File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ const addColumnSqlize = ({
146
146
147
147
return format (
148
148
`
149
- ALTER TABLE %I.%I ADD COLUMN %I %I
149
+ ALTER TABLE %I.%I ADD COLUMN %I ${ type }
150
150
${ defaultValueSql }
151
151
${ isIdentitySql }
152
152
${ isNullableSql }
@@ -155,8 +155,7 @@ ALTER TABLE %I.%I ADD COLUMN %I %I
155
155
${ commentSql } `,
156
156
schema ,
157
157
table ,
158
- name ,
159
- type
158
+ name
160
159
)
161
160
}
162
161
const getColumnSqlize = ( tableId : number , name : string ) => {
@@ -198,13 +197,11 @@ const alterColumnSqlize = (
198
197
type === undefined
199
198
? ''
200
199
: format (
201
- ' ALTER TABLE %I.%I ALTER COLUMN %I SET DATA TYPE %I USING %I::%I;' ,
200
+ ` ALTER TABLE %I.%I ALTER COLUMN %I SET DATA TYPE ${ type } USING %I::${ type } ;` ,
202
201
old . schema ,
203
202
old . table ,
204
203
old . name ,
205
- type ,
206
- old . name ,
207
- type
204
+ old . name
208
205
)
209
206
let defaultValueSql : string
210
207
if ( drop_default ) {
Original file line number Diff line number Diff line change @@ -323,6 +323,24 @@ describe('/tables', async () => {
323
323
await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
324
324
await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
325
325
} )
326
+ it ( 'POST /columns array type' , async ( ) => {
327
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'a' } )
328
+ await axios . post ( `${ URL } /columns` , {
329
+ table_id : newTable . id ,
330
+ name : 'b' ,
331
+ type : 'int2[]' ,
332
+ } )
333
+
334
+ const { data : columns } = await axios . get ( `${ URL } /columns` )
335
+ const newColumn = columns . find (
336
+ ( column ) =>
337
+ column . id === `${ newTable . id } .1` && column . name === 'b' && column . format === '_int2'
338
+ )
339
+ assert . equal ( newColumn . name , 'b' )
340
+
341
+ await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
342
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
343
+ } )
326
344
it ( '/columns default_value with expressions' , async ( ) => {
327
345
const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'a' } )
328
346
const { data : newColumn } = await axios . post ( `${ URL } /columns` , {
You can’t perform that action at this time.
0 commit comments