diff --git a/src/operation-node/alter-table-node.ts b/src/operation-node/alter-table-node.ts index b7b2ddb98..fdb090eef 100644 --- a/src/operation-node/alter-table-node.ts +++ b/src/operation-node/alter-table-node.ts @@ -40,10 +40,10 @@ export const AlterTableNode = freeze({ return node.kind === 'AlterTableNode' }, - create(table: string): AlterTableNode { + create(table: TableNode): AlterTableNode { return freeze({ kind: 'AlterTableNode', - table: TableNode.create(table), + table, }) }, diff --git a/src/schema/schema.ts b/src/schema/schema.ts index b33d508a1..e5ddaafcc 100644 --- a/src/schema/schema.ts +++ b/src/schema/schema.ts @@ -210,7 +210,7 @@ export class SchemaModule { return new AlterTableBuilder({ queryId: createQueryId(), executor: this.#executor, - node: AlterTableNode.create(table), + node: AlterTableNode.create(parseTable(table)), }) } diff --git a/test/node/src/schema.test.ts b/test/node/src/schema.test.ts index a42882cc6..3d3586173 100644 --- a/test/node/src/schema.test.ts +++ b/test/node/src/schema.test.ts @@ -2446,6 +2446,35 @@ for (const dialect of DIALECTS) { }) } + if (dialect !== 'sqlite') { + describe('parse schema name', () => { + it('should parse the schema from table name', async () => { + await ctx.db.schema.createSchema('pets').ifNotExists().execute() + await ctx.db.schema.createTable('pets.name').addColumn('id', 'serial').execute(); + + const builder = ctx.db.schema.alterTable('pets.name').addColumn('nickname', 'text') + + testSql(builder, dialect, { + postgres: { + sql: `alter table "pets"."name" add column "nickname" text`, + parameters: [], + }, + mysql: { + sql: "alter table `pets`.`name` add column `nickname` text", + parameters: [], + }, + sqlite: NOT_SUPPORTED, + }) + + await builder.execute() + }) + + async function cleanup() { + await ctx.db.schema.dropSchema('pets').cascade().ifExists().execute() + } + }) + } + it('should alter a table calling query builder functions', async () => { const builder = ctx.db.schema .alterTable('test')