Skip to content

Commit

Permalink
Merge pull request #4023 from Karibash/bugfix/unsigned-column
Browse files Browse the repository at this point in the history
bugfix: Fix a bug that caused incorrect syntax output when introspect in unsigned columns
  • Loading branch information
AndriiSherman authored Jan 29, 2025
2 parents d9f609a + cdbf1e9 commit 991e8b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
16 changes: 4 additions & 12 deletions drizzle-kit/src/introspect-mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ const column = (
if (lowered.startsWith('int')) {
const isUnsigned = lowered.startsWith('int unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
let out = `${casing(name)}: int(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out = `${casing(name)}: int(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand All @@ -419,9 +417,7 @@ const column = (
const isUnsigned = lowered.startsWith('tinyint unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
// let out = `${name.camelCase()}: tinyint("${name}")`;
let out: string = `${casing(name)}: tinyint(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out: string = `${casing(name)}: tinyint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand All @@ -432,9 +428,7 @@ const column = (
if (lowered.startsWith('smallint')) {
const isUnsigned = lowered.startsWith('smallint unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
let out = `${casing(name)}: smallint(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out = `${casing(name)}: smallint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += defaultValue
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand All @@ -445,9 +439,7 @@ const column = (
if (lowered.startsWith('mediumint')) {
const isUnsigned = lowered.startsWith('mediumint unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
let out = `${casing(name)}: mediumint(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out = `${casing(name)}: mediumint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += defaultValue
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand Down
17 changes: 4 additions & 13 deletions drizzle-kit/src/introspect-singlestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,7 @@ const column = (
if (lowered.startsWith('int')) {
const isUnsigned = lowered.includes('unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
let out = `${casing(name)}: int(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out = `${casing(name)}: int(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand All @@ -393,10 +391,7 @@ const column = (
if (lowered.startsWith('tinyint')) {
const isUnsigned = lowered.includes('unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
// let out = `${name.camelCase()}: tinyint("${name}")`;
let out: string = `${casing(name)}: tinyint(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out: string = `${casing(name)}: tinyint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand All @@ -407,9 +402,7 @@ const column = (
if (lowered.startsWith('smallint')) {
const isUnsigned = lowered.includes('unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
let out = `${casing(name)}: smallint(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out = `${casing(name)}: smallint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += defaultValue
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand All @@ -420,9 +413,7 @@ const column = (
if (lowered.startsWith('mediumint')) {
const isUnsigned = lowered.includes('unsigned');
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
let out = `${casing(name)}: mediumint(${columnName}${
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
})`;
let out = `${casing(name)}: mediumint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
out += autoincrement ? `.autoincrement()` : '';
out += defaultValue
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
Expand Down

0 comments on commit 991e8b4

Please sign in to comment.