File tree 2 files changed +48
-1
lines changed
2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -419,6 +419,12 @@ COMMIT;`
419
419
}
420
420
}
421
421
422
+ // TODO: make this more robust - use type_id or type_schema + type_name instead
423
+ // of just type.
422
424
const typeIdent = ( type : string ) => {
423
- return type . endsWith ( '[]' ) ? `${ ident ( type . slice ( 0 , - 2 ) ) } []` : ident ( type )
425
+ return type . endsWith ( '[]' )
426
+ ? `${ ident ( type . slice ( 0 , - 2 ) ) } []`
427
+ : type . includes ( '.' )
428
+ ? type
429
+ : ident ( type )
424
430
}
Original file line number Diff line number Diff line change @@ -947,3 +947,44 @@ test('dropping column checks', async () => {
947
947
948
948
await pgMeta . query ( `drop table t` )
949
949
} )
950
+
951
+ test ( 'column with fully-qualified type' , async ( ) => {
952
+ await pgMeta . query ( `create table public.t(); create schema s; create type s.my_type as enum ();` )
953
+
954
+ const table = await pgMeta . tables . retrieve ( {
955
+ schema : 'public' ,
956
+ name : 't' ,
957
+ } )
958
+ const column = await pgMeta . columns . create ( {
959
+ table_id : table . data ! . id ,
960
+ name : 'c' ,
961
+ type : 's.my_type' ,
962
+ } )
963
+ expect ( column ) . toMatchInlineSnapshot ( `
964
+ {
965
+ "data": {
966
+ "check": null,
967
+ "comment": null,
968
+ "data_type": "USER-DEFINED",
969
+ "default_value": null,
970
+ "enums": [],
971
+ "format": "my_type",
972
+ "id": "16619.1",
973
+ "identity_generation": null,
974
+ "is_generated": false,
975
+ "is_identity": false,
976
+ "is_nullable": true,
977
+ "is_unique": false,
978
+ "is_updatable": true,
979
+ "name": "c",
980
+ "ordinal_position": 1,
981
+ "schema": "public",
982
+ "table": "t",
983
+ "table_id": 16619,
984
+ },
985
+ "error": null,
986
+ }
987
+ ` )
988
+
989
+ await pgMeta . query ( `drop table public.t; drop schema s cascade;` )
990
+ } )
You can’t perform that action at this time.
0 commit comments