@@ -102,6 +102,7 @@ const addColumnSqlize = ({
102
102
name,
103
103
type,
104
104
default_value,
105
+ default_value_format = 'literal' ,
105
106
is_identity = false ,
106
107
is_nullable = true ,
107
108
is_primary_key = false ,
@@ -113,6 +114,7 @@ const addColumnSqlize = ({
113
114
name : string
114
115
type : string
115
116
default_value ?: any
117
+ default_value_format ?: 'expression' | 'literal'
116
118
is_identity ?: boolean
117
119
is_nullable ?: boolean
118
120
is_primary_key ?: boolean
@@ -122,10 +124,10 @@ const addColumnSqlize = ({
122
124
let defaultValueSql : string
123
125
if ( default_value === undefined ) {
124
126
defaultValueSql = ''
125
- } else if ( typeof default_value === 'string' ) {
126
- defaultValueSql = `DEFAULT ${ literal ( default_value ) } `
127
- } else {
127
+ } else if ( default_value_format === 'expression' ) {
128
128
defaultValueSql = `DEFAULT ${ default_value } `
129
+ } else {
130
+ defaultValueSql = `DEFAULT ${ literal ( default_value ) } `
129
131
}
130
132
const isIdentitySql = is_identity ? 'GENERATED BY DEFAULT AS IDENTITY' : ''
131
133
const isNullableSql = is_nullable ? 'NULL' : 'NOT NULL'
@@ -167,6 +169,7 @@ const alterColumnSqlize = ({
167
169
type,
168
170
drop_default = false ,
169
171
default_value,
172
+ default_value_format = 'literal' ,
170
173
is_nullable,
171
174
comment,
172
175
} : {
@@ -177,6 +180,7 @@ const alterColumnSqlize = ({
177
180
type ?: string
178
181
drop_default ?: boolean
179
182
default_value ?: any
183
+ default_value_format ?: 'expression' | 'literal'
180
184
is_nullable ?: boolean
181
185
comment ?: string
182
186
} ) => {
@@ -206,8 +210,10 @@ const alterColumnSqlize = ({
206
210
oldName
207
211
)
208
212
} else if ( default_value !== undefined ) {
213
+ let defaultValue =
214
+ default_value_format === 'expression' ? default_value : literal ( default_value )
209
215
defaultValueSql = format (
210
- `ALTER TABLE %I.%I ALTER COLUMN %I SET DEFAULT ${ default_value } ;` ,
216
+ `ALTER TABLE %I.%I ALTER COLUMN %I SET DEFAULT ${ defaultValue } ;` ,
211
217
schema ,
212
218
table ,
213
219
oldName
0 commit comments