@@ -24,6 +24,7 @@ import {
2424 pgPolicy ,
2525 pgRole ,
2626 pgSchema ,
27+ pgSequence ,
2728 pgTable ,
2829 pgView ,
2930 real ,
@@ -33,6 +34,7 @@ import {
3334 text ,
3435 time ,
3536 timestamp ,
37+ unique ,
3638 uuid ,
3739 varchar ,
3840} from 'drizzle-orm/pg-core' ;
@@ -1072,6 +1074,48 @@ test('introspect partitioned tables', async () => {
10721074 ] ) ;
10731075} ) ;
10741076
1077+ test ( 'default sequence nextval' , async ( ) => {
1078+ const seqOrgCode = pgSequence ( 'seq_org_code' , {
1079+ startWith : '1000' ,
1080+ increment : '1' ,
1081+ minValue : '1' ,
1082+ maxValue : '9223372036854775807' ,
1083+ cache : '1' ,
1084+ cycle : false ,
1085+ } ) ;
1086+
1087+ const organizations = pgTable ( 'organizations' , {
1088+ code : bigint ( { mode : 'number' } ) . default ( sql `nextval('seq_org_code'::regclass)` ) . notNull ( ) ,
1089+ } ) ;
1090+
1091+ const { sqlStatements } = await diffIntrospect ( db , { seqOrgCode, organizations } , 'default_sequence_nextval' ) ;
1092+
1093+ expect ( sqlStatements ) . toStrictEqual ( [ ] ) ;
1094+ } ) ;
1095+
1096+ test ( 'policy' , async ( ) => {
1097+ const organizationsInCore = pgTable ( 'organizations' , {
1098+ domain : text ( ) ,
1099+ } , ( table ) => [
1100+ unique ( 'organizations_domain_key' ) . on ( table . domain ) ,
1101+ ] ) ;
1102+
1103+ const policy = pgPolicy ( 'new_policy' , {
1104+ as : 'restrictive' ,
1105+ to : 'postgres' ,
1106+ withCheck : sql `1 = 1` ,
1107+ for : 'all' ,
1108+ } ) . link ( organizationsInCore ) ;
1109+
1110+ const { sqlStatements } = await diffIntrospect (
1111+ db ,
1112+ { organizationsInCore, policy } ,
1113+ 'policy' ,
1114+ ) ;
1115+
1116+ expect ( sqlStatements ) . toStrictEqual ( [ ] ) ;
1117+ } ) ;
1118+
10751119// test('introspect foreign tables', async () => {
10761120// await db.query('CREATE EXTENSION postgres_fdw;');
10771121// await db.query("CREATE SERVER film_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foo', dbname 'foodb', port '5432');");
0 commit comments