@@ -102,6 +102,7 @@ const addColumnSqlize = ({
102102 name,
103103 type,
104104 default_value,
105+ default_value_format = 'literal' ,
105106 is_identity = false ,
106107 is_nullable = true ,
107108 is_primary_key = false ,
@@ -113,6 +114,7 @@ const addColumnSqlize = ({
113114 name : string
114115 type : string
115116 default_value ?: any
117+ default_value_format ?: 'expression' | 'literal'
116118 is_identity ?: boolean
117119 is_nullable ?: boolean
118120 is_primary_key ?: boolean
@@ -122,10 +124,10 @@ const addColumnSqlize = ({
122124 let defaultValueSql : string
123125 if ( default_value === undefined ) {
124126 defaultValueSql = ''
125- } else if ( typeof default_value === 'string' ) {
126- defaultValueSql = `DEFAULT ${ literal ( default_value ) } `
127- } else {
127+ } else if ( default_value_format === 'expression' ) {
128128 defaultValueSql = `DEFAULT ${ default_value } `
129+ } else {
130+ defaultValueSql = `DEFAULT ${ literal ( default_value ) } `
129131 }
130132 const isIdentitySql = is_identity ? 'GENERATED BY DEFAULT AS IDENTITY' : ''
131133 const isNullableSql = is_nullable ? 'NULL' : 'NOT NULL'
@@ -167,6 +169,7 @@ const alterColumnSqlize = ({
167169 type,
168170 drop_default = false ,
169171 default_value,
172+ default_value_format = 'literal' ,
170173 is_nullable,
171174 comment,
172175} : {
@@ -177,6 +180,7 @@ const alterColumnSqlize = ({
177180 type ?: string
178181 drop_default ?: boolean
179182 default_value ?: any
183+ default_value_format ?: 'expression' | 'literal'
180184 is_nullable ?: boolean
181185 comment ?: string
182186} ) => {
@@ -206,8 +210,10 @@ const alterColumnSqlize = ({
206210 oldName
207211 )
208212 } else if ( default_value !== undefined ) {
213+ let defaultValue =
214+ default_value_format === 'expression' ? default_value : literal ( default_value )
209215 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 } ;` ,
211217 schema ,
212218 table ,
213219 oldName
0 commit comments