Skip to content

Commit

Permalink
Merge branch 'master' into fix-alter-column-multiple-operations
Browse files Browse the repository at this point in the history
  • Loading branch information
soanvig authored May 12, 2023
2 parents 300a384 + f670ffa commit 3050b10
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/operation-node/alter-column-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type AlterColumnNodeProps = Omit<AlterColumnNode, 'kind' | 'column'>
export interface AlterColumnNode extends OperationNode {
readonly kind: 'AlterColumnNode'
readonly column: ColumnNode
readonly dataType?: DataTypeNode
readonly dataType?: OperationNode
readonly dataTypeExpression?: RawNode
readonly setDefault?: OperationNode
readonly dropDefault?: true
Expand Down
12 changes: 6 additions & 6 deletions src/schema/alter-column-builder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AlterColumnNode } from '../operation-node/alter-column-node.js'
import {
ColumnDataType,
DataTypeNode,
} from '../operation-node/data-type-node.js'
import { OperationNodeSource } from '../operation-node/operation-node-source.js'
import {
DataTypeExpression,
parseDataTypeExpression,
} from '../parser/data-type-parser.js'
import {
DefaultValueExpression,
parseDefaultValueExpression,
Expand All @@ -16,10 +16,10 @@ export class AlterColumnBuilder {
this.alterColumnNode = alterColumnNode
}

setDataType(dataType: ColumnDataType): AlteredColumnBuilder {
setDataType(dataType: DataTypeExpression): AlteredColumnBuilder {
return new AlteredColumnBuilder(
AlterColumnNode.cloneWith(this.alterColumnNode, {
dataType: DataTypeNode.create(dataType),
dataType: parseDataTypeExpression(dataType),
})
)
}
Expand Down
22 changes: 21 additions & 1 deletion test/node/src/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ for (const dialect of DIALECTS) {

await builder.execute()
})

if (dialect !== 'mysql') {
it('should create a partial index', async () => {
const builder = ctx.db.schema
Expand Down Expand Up @@ -1959,6 +1959,26 @@ for (const dialect of DIALECTS) {
await builder.execute()
})

it('should set column data type from expression', async () => {
const builder = ctx.db.schema
.alterTable('test')
.alterColumn('varchar_col', (ac) => ac.setDataType(sql`text`))

testSql(builder, dialect, {
postgres: {
sql: 'alter table "test" alter column "varchar_col" type text',
parameters: [],
},
sqlite: {
sql: 'alter table "test" alter column "varchar_col" type text',
parameters: [],
},
mysql: NOT_SUPPORTED,
})

await builder.execute()
})

it('should add not null constraint for column', async () => {
const builder = ctx.db.schema
.alterTable('test')
Expand Down

0 comments on commit 3050b10

Please sign in to comment.