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 {
8989 is_primary_key = false ,
9090 is_unique = false ,
9191 comment,
92+ constraint,
9293 } : {
9394 table_id : number
9495 name : string
@@ -101,6 +102,7 @@ export default class PostgresMetaColumns {
101102 is_primary_key ?: boolean
102103 is_unique ?: boolean
103104 comment ?: string
105+ constraint ?: string
104106 } ) : Promise < PostgresMetaResult < PostgresColumn > > {
105107 const { data, error } = await this . metaTables . retrieve ( { id : table_id } )
106108 if ( error ) {
@@ -120,6 +122,10 @@ export default class PostgresMetaColumns {
120122 const isNullableClause = is_nullable ? 'NULL' : 'NOT NULL'
121123 const isPrimaryKeyClause = is_primary_key ? 'PRIMARY KEY' : ''
122124 const isUniqueClause = is_unique ? 'UNIQUE' : ''
125+ const constraintSql =
126+ constraint === undefined
127+ ? ''
128+ : constraint
123129 const commentSql =
124130 comment === undefined
125131 ? ''
@@ -132,7 +138,8 @@ BEGIN;
132138 ${ isIdentityClause }
133139 ${ isNullableClause }
134140 ${ isPrimaryKeyClause }
135- ${ isUniqueClause } ;
141+ ${ isUniqueClause }
142+ ${ constraintSql } ;
136143 ${ commentSql } ;
137144COMMIT;`
138145 {
Original file line number Diff line number Diff line change @@ -414,6 +414,21 @@ describe('/tables', async () => {
414414 await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
415415 await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
416416 } )
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+ } )
417432 it ( 'PATCH /columns' , async ( ) => {
418433 const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'foo bar' } )
419434 await axios . post ( `${ URL } /columns` , {
You can’t perform that action at this time.
0 commit comments