File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ export default class PostgresMetaColumns {
89
89
is_primary_key = false ,
90
90
is_unique = false ,
91
91
comment,
92
+ constraint,
92
93
} : {
93
94
table_id : number
94
95
name : string
@@ -101,6 +102,7 @@ export default class PostgresMetaColumns {
101
102
is_primary_key ?: boolean
102
103
is_unique ?: boolean
103
104
comment ?: string
105
+ constraint ?: string
104
106
} ) : Promise < PostgresMetaResult < PostgresColumn > > {
105
107
const { data, error } = await this . metaTables . retrieve ( { id : table_id } )
106
108
if ( error ) {
@@ -120,6 +122,10 @@ export default class PostgresMetaColumns {
120
122
const isNullableClause = is_nullable ? 'NULL' : 'NOT NULL'
121
123
const isPrimaryKeyClause = is_primary_key ? 'PRIMARY KEY' : ''
122
124
const isUniqueClause = is_unique ? 'UNIQUE' : ''
125
+ const constraintSql =
126
+ constraint === undefined
127
+ ? ''
128
+ : constraint
123
129
const commentSql =
124
130
comment === undefined
125
131
? ''
@@ -132,7 +138,8 @@ BEGIN;
132
138
${ isIdentityClause }
133
139
${ isNullableClause }
134
140
${ isPrimaryKeyClause }
135
- ${ isUniqueClause } ;
141
+ ${ isUniqueClause }
142
+ ${ constraintSql } ;
136
143
${ commentSql } ;
137
144
COMMIT;`
138
145
{
Original file line number Diff line number Diff line change @@ -414,6 +414,21 @@ describe('/tables', async () => {
414
414
await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
415
415
await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
416
416
} )
417
+ it ( 'POST /columns with constraint definition' , async ( ) => {
418
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'a' } )
419
+ const { error } = await axios . post ( `${ URL } /columns` , {
420
+ table_id : newTable . id ,
421
+ name : 'description' ,
422
+ type : 'text' ,
423
+ constraint : "CHECK (description <> '')" ,
424
+ } )
425
+
426
+ // TODO: some way to check constraints?
427
+ assert . equal ( error , undefined )
428
+
429
+ await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
430
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
431
+ } )
417
432
it ( 'PATCH /columns' , async ( ) => {
418
433
const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'foo bar' } )
419
434
await axios . post ( `${ URL } /columns` , {
You can’t perform that action at this time.
0 commit comments