diff --git a/src/operation-node/alter-column-node.ts b/src/operation-node/alter-column-node.ts index 3f75f68c1..cb251e557 100644 --- a/src/operation-node/alter-column-node.ts +++ b/src/operation-node/alter-column-node.ts @@ -42,53 +42,4 @@ export const AlterColumnNode = freeze({ ...props, }) }, - - // Because AlterColumnNode is aggregation for multiple "ALTER COLUMN" expressions - // We can unwind any instance into multiple instances of single expression - unwind(node: AlterColumnNode): AlterColumnNode[] { - const operations: AlterColumnNode[] = [] - - if (node.dataType) { - operations.push({ - column: node.column, - kind: node.kind, - dataType: node.dataType, - dataTypeExpression: node.dataTypeExpression, - }) - } - - if (node.dropDefault) { - operations.push({ - column: node.column, - kind: node.kind, - dropDefault: node.dropDefault, - }) - } - - if (node.dropNotNull) { - operations.push({ - column: node.column, - kind: node.kind, - dropNotNull: node.dropNotNull, - }) - } - - if (node.setDefault) { - operations.push({ - column: node.column, - kind: node.kind, - setDefault: node.setDefault, - }) - } - - if (node.setNotNull) { - operations.push({ - column: node.column, - kind: node.kind, - setNotNull: node.setNotNull, - }) - } - - return operations - } }) diff --git a/src/query-compiler/default-query-compiler.ts b/src/query-compiler/default-query-compiler.ts index f6f99806a..69b42b215 100644 --- a/src/query-compiler/default-query-compiler.ts +++ b/src/query-compiler/default-query-compiler.ts @@ -990,46 +990,36 @@ export class DefaultQueryCompiler } protected override visitAlterColumn(node: AlterColumnNode): void { - const operations = AlterColumnNode.unwind(node); - - if (operations.length === 0) { - return - } else if (operations.length > 1) { - return this.compileList(operations) - } else { - const operation = operations[0] + this.append('alter column ') + this.visitNode(node.column) + this.append(' ') - this.append('alter column ') - this.visitNode(node.column) - this.append(' ') + if (node.dataType) { + this.append('type ') + this.visitNode(node.dataType) - if (operation.dataType) { - this.append('type ') - this.visitNode(operation.dataType) - - if (operation.dataTypeExpression) { - this.append('using ') - this.visitNode(operation.dataTypeExpression) - } - } - - if (operation.setDefault) { - this.append('set default ') - this.visitNode(operation.setDefault) - } - - if (operation.dropDefault) { - this.append('drop default') - } - - if (operation.setNotNull) { - this.append('set not null') - } - - if (operation.dropNotNull) { - this.append('drop not null') + if (node.dataTypeExpression) { + this.append('using ') + this.visitNode(node.dataTypeExpression) } } + + if (node.setDefault) { + this.append('set default ') + this.visitNode(node.setDefault) + } + + if (node.dropDefault) { + this.append('drop default') + } + + if (node.setNotNull) { + this.append('set not null') + } + + if (node.dropNotNull) { + this.append('drop not null') + } } protected override visitModifyColumn(node: ModifyColumnNode): void { diff --git a/test/node/src/schema.test.ts b/test/node/src/schema.test.ts index 774e4ddcd..12545b2cc 100644 --- a/test/node/src/schema.test.ts +++ b/test/node/src/schema.test.ts @@ -2023,39 +2023,6 @@ for (const dialect of DIALECTS) { await builder.execute() }) - - // Checking MySQL for that operation doesn't make sense, because it supports - // only setDefault and dropDefault in ALTER COLUMN, and probably nobody will use this combination - it('should set multiple attributes', async () => { - const builder = ctx.db.schema - .alterTable('test') - .alterColumn('varchar_col', (ac) => - ac - .setDefault('foo') - .setDataType('varchar') - .setNotNull() - .dropDefault() - .dropNotNull() - ) - - testSql(builder, dialect, { - postgres: { - sql: [ - `alter table "test" `, - `alter column "varchar_col" type varchar`, - `, alter column "varchar_col" drop default`, - `, alter column "varchar_col" drop not null`, - `, alter column "varchar_col" set default 'foo'`, - `, alter column "varchar_col" set not null`, - ].join(''), - parameters: [], - }, - mysql: NOT_SUPPORTED, - sqlite: NOT_SUPPORTED, - }) - - await builder.execute() - }) } it('should alter multiple columns', async () => {