Skip to content

Commit

Permalink
Merge branch 'master' into case
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas authored May 13, 2023
2 parents f7a4a1b + bf5613f commit 6ccbbd3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/operation-node/alter-table-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
},

Expand Down
2 changes: 1 addition & 1 deletion src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class SchemaModule {
return new AlterTableBuilder({
queryId: createQueryId(),
executor: this.#executor,
node: AlterTableNode.create(table),
node: AlterTableNode.create(parseTable(table)),
})
}

Expand Down
35 changes: 35 additions & 0 deletions test/node/src/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2466,6 +2466,41 @@ for (const dialect of DIALECTS) {
})
}

if (dialect !== 'sqlite') {
describe('parse schema name', () => {
beforeEach(cleanup)
afterEach(cleanup)

it('should parse the schema from table name', async () => {
await ctx.db.schema.createSchema('test_schema').ifNotExists().execute()
await ctx.db.schema.createTable('test_schema.test').addColumn('id', 'serial').execute();

const builder = ctx.db.schema
.alterTable('test_schema.test')
.addColumn('second_column', 'text')

testSql(builder, dialect, {
postgres: {
sql: `alter table "test_schema"."test" add column "second_column" text`,
parameters: [],
},
mysql: {
sql: "alter table `test_schema`.`test` add column `second_column` text",
parameters: [],
},
sqlite: NOT_SUPPORTED,
})

await builder.execute()
})

async function cleanup() {
await ctx.db.schema.dropTable('test_schema.test').ifExists().execute()
await ctx.db.schema.dropSchema('test_schema').ifExists().execute()
}
})
}

it('should alter a table calling query builder functions', async () => {
const builder = ctx.db.schema
.alterTable('test')
Expand Down

0 comments on commit 6ccbbd3

Please sign in to comment.