@supabase/pg-delta 1.0.0-alpha.0 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/cli/utils/integrations.d.ts +4 -3
  2. package/dist/cli/utils/integrations.js +25 -16
  3. package/dist/core/catalog.model.d.ts +2 -2
  4. package/dist/core/catalog.model.js +29 -29
  5. package/dist/core/context.d.ts +3 -3
  6. package/dist/core/context.js +7 -10
  7. package/dist/core/depend.d.ts +2 -2
  8. package/dist/core/depend.js +8 -7
  9. package/dist/core/fingerprint.d.ts +0 -8
  10. package/dist/core/fingerprint.js +2 -2
  11. package/dist/core/integrations/filter/dsl.d.ts +1 -1
  12. package/dist/core/integrations/filter/filter.types.d.ts +2 -0
  13. package/dist/core/integrations/filter/filter.types.js +1 -0
  14. package/dist/core/integrations/integration.types.d.ts +2 -1
  15. package/dist/core/integrations/serialize/dsl.d.ts +1 -1
  16. package/dist/core/integrations/serialize/serialize.types.d.ts +2 -0
  17. package/dist/core/integrations/serialize/serialize.types.js +1 -0
  18. package/dist/core/integrations/supabase.d.ts +10 -0
  19. package/dist/core/integrations/supabase.js +114 -0
  20. package/dist/core/objects/aggregate/aggregate.model.d.ts +10 -10
  21. package/dist/core/objects/aggregate/aggregate.model.js +7 -9
  22. package/dist/core/objects/collation/collation.model.d.ts +2 -2
  23. package/dist/core/objects/collation/collation.model.js +29 -28
  24. package/dist/core/objects/domain/domain.model.d.ts +2 -2
  25. package/dist/core/objects/domain/domain.model.js +8 -10
  26. package/dist/core/objects/event-trigger/event-trigger.model.d.ts +2 -2
  27. package/dist/core/objects/event-trigger/event-trigger.model.js +7 -9
  28. package/dist/core/objects/extension/extension.model.d.ts +2 -2
  29. package/dist/core/objects/extension/extension.model.js +8 -10
  30. package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.d.ts +2 -2
  31. package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.js +20 -22
  32. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.d.ts +2 -2
  33. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.js +20 -22
  34. package/dist/core/objects/foreign-data-wrapper/server/server.model.d.ts +2 -2
  35. package/dist/core/objects/foreign-data-wrapper/server/server.model.js +20 -22
  36. package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.d.ts +2 -2
  37. package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.js +20 -22
  38. package/dist/core/objects/index/index.model.d.ts +4 -4
  39. package/dist/core/objects/index/index.model.js +9 -11
  40. package/dist/core/objects/language/language.model.js +5 -7
  41. package/dist/core/objects/materialized-view/materialized-view.model.d.ts +5 -5
  42. package/dist/core/objects/materialized-view/materialized-view.model.js +8 -10
  43. package/dist/core/objects/procedure/procedure.model.d.ts +11 -11
  44. package/dist/core/objects/procedure/procedure.model.js +8 -10
  45. package/dist/core/objects/publication/publication.model.d.ts +2 -2
  46. package/dist/core/objects/publication/publication.model.js +7 -9
  47. package/dist/core/objects/rls-policy/rls-policy.model.d.ts +4 -4
  48. package/dist/core/objects/rls-policy/rls-policy.model.js +8 -10
  49. package/dist/core/objects/role/role.model.d.ts +5 -5
  50. package/dist/core/objects/role/role.model.js +28 -28
  51. package/dist/core/objects/rule/rule.model.d.ts +3 -3
  52. package/dist/core/objects/rule/rule.model.js +7 -9
  53. package/dist/core/objects/schema/schema.model.d.ts +2 -2
  54. package/dist/core/objects/schema/schema.model.js +8 -10
  55. package/dist/core/objects/sequence/sequence.model.d.ts +2 -2
  56. package/dist/core/objects/sequence/sequence.model.js +8 -10
  57. package/dist/core/objects/subscription/subscription.model.d.ts +2 -2
  58. package/dist/core/objects/subscription/subscription.model.js +25 -20
  59. package/dist/core/objects/table/table.model.d.ts +24 -24
  60. package/dist/core/objects/table/table.model.js +8 -10
  61. package/dist/core/objects/trigger/trigger.model.d.ts +2 -2
  62. package/dist/core/objects/trigger/trigger.model.js +8 -10
  63. package/dist/core/objects/type/composite-type/composite-type.model.d.ts +5 -5
  64. package/dist/core/objects/type/composite-type/composite-type.model.js +8 -10
  65. package/dist/core/objects/type/enum/enum.model.d.ts +2 -2
  66. package/dist/core/objects/type/enum/enum.model.js +22 -24
  67. package/dist/core/objects/type/range/range.model.d.ts +2 -2
  68. package/dist/core/objects/type/range/range.model.js +7 -9
  69. package/dist/core/objects/view/view.model.d.ts +5 -5
  70. package/dist/core/objects/view/view.model.js +8 -10
  71. package/dist/core/plan/apply.d.ts +2 -2
  72. package/dist/core/plan/apply.js +50 -16
  73. package/dist/core/plan/create.d.ts +2 -2
  74. package/dist/core/plan/create.js +84 -38
  75. package/dist/core/plan/index.d.ts +1 -2
  76. package/dist/core/plan/index.js +0 -1
  77. package/dist/core/plan/types.d.ts +4 -15
  78. package/dist/core/postgres-config.d.ts +18 -3
  79. package/dist/core/postgres-config.js +105 -41
  80. package/dist/index.d.ts +9 -1
  81. package/dist/index.js +8 -1
  82. package/package.json +8 -3
  83. package/dist/core/index.d.ts +0 -15
  84. package/dist/core/index.js +0 -14
  85. package/dist/core/main.d.ts +0 -5
  86. package/dist/core/main.js +0 -44
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel, type TableLikeObject } from "../base.model.ts";
4
4
  import { type PrivilegeProps } from "../base.privilege-diff.ts";
@@ -14,10 +14,10 @@ declare const materializedViewPropsSchema: z.ZodObject<{
14
14
  has_subclasses: z.ZodBoolean;
15
15
  is_populated: z.ZodBoolean;
16
16
  replica_identity: z.ZodEnum<{
17
+ f: "f";
17
18
  n: "n";
18
19
  i: "i";
19
20
  d: "d";
20
- f: "f";
21
21
  }>;
22
22
  is_partition: z.ZodBoolean;
23
23
  options: z.ZodNullable<z.ZodArray<z.ZodString>>;
@@ -85,7 +85,7 @@ export declare class MaterializedView extends BasePgModel implements TableLikeOb
85
85
  has_triggers: boolean;
86
86
  has_subclasses: boolean;
87
87
  is_populated: boolean;
88
- replica_identity: "n" | "i" | "d" | "f";
88
+ replica_identity: "f" | "n" | "i" | "d";
89
89
  is_partition: boolean;
90
90
  options: string[] | null;
91
91
  partition_bound: string | null;
@@ -133,7 +133,7 @@ export declare class MaterializedView extends BasePgModel implements TableLikeOb
133
133
  has_triggers: boolean;
134
134
  has_subclasses: boolean;
135
135
  is_populated: boolean;
136
- replica_identity: "n" | "i" | "d" | "f";
136
+ replica_identity: "f" | "n" | "i" | "d";
137
137
  is_partition: boolean;
138
138
  options: string[] | null;
139
139
  partition_bound: string | null;
@@ -148,5 +148,5 @@ export declare class MaterializedView extends BasePgModel implements TableLikeOb
148
148
  };
149
149
  };
150
150
  }
151
- export declare function extractMaterializedViews(sql: Sql): Promise<MaterializedView[]>;
151
+ export declare function extractMaterializedViews(pool: Pool): Promise<MaterializedView[]>;
152
152
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel, columnPropsSchema, } from "../base.model.js";
3
4
  import { privilegePropsSchema, } from "../base.privilege-diff.js";
@@ -113,10 +114,8 @@ export class MaterializedView extends BasePgModel {
113
114
  };
114
115
  }
115
116
  }
116
- export async function extractMaterializedViews(sql) {
117
- return sql.begin(async (sql) => {
118
- await sql `set search_path = ''`;
119
- const mvRows = await sql `
117
+ export async function extractMaterializedViews(pool) {
118
+ const { rows: mvRows } = await pool.query(sql `
120
119
  with extension_oids as (
121
120
  select
122
121
  objid
@@ -219,10 +218,9 @@ where not c.relnamespace::regnamespace::text like any(array['pg\\_%', 'informati
219
218
  group by
220
219
  c.oid, c.relnamespace, c.relname, pg_get_viewdef(c.oid), c.relrowsecurity, c.relforcerowsecurity, c.relhasindex, c.relhasrules, c.relhastriggers, c.relhassubclass, c.relispopulated, c.relreplident, c.relispartition, c.reloptions, pg_get_expr(c.relpartbound, c.oid), c.relowner
221
220
  order by
222
- c.relnamespace::regnamespace, c.relname;
223
- `;
224
- // Validate and parse each row using the Zod schema
225
- const validatedRows = mvRows.map((row) => materializedViewPropsSchema.parse(row));
226
- return validatedRows.map((row) => new MaterializedView(row));
227
- });
221
+ c.relnamespace::regnamespace, c.relname
222
+ `);
223
+ // Validate and parse each row using the Zod schema
224
+ const validatedRows = mvRows.map((row) => materializedViewPropsSchema.parse(row));
225
+ return validatedRows.map((row) => new MaterializedView(row));
228
226
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  import { type PrivilegeProps } from "../base.privilege-diff.ts";
@@ -6,24 +6,24 @@ declare const procedurePropsSchema: z.ZodObject<{
6
6
  schema: z.ZodString;
7
7
  name: z.ZodString;
8
8
  kind: z.ZodEnum<{
9
- a: "a";
9
+ f: "f";
10
10
  w: "w";
11
+ a: "a";
11
12
  p: "p";
12
- f: "f";
13
13
  }>;
14
14
  return_type: z.ZodString;
15
15
  return_type_schema: z.ZodString;
16
16
  language: z.ZodString;
17
17
  security_definer: z.ZodBoolean;
18
18
  volatility: z.ZodEnum<{
19
- i: "i";
20
19
  s: "s";
20
+ i: "i";
21
21
  v: "v";
22
22
  }>;
23
23
  parallel_safety: z.ZodEnum<{
24
+ r: "r";
24
25
  u: "u";
25
26
  s: "s";
26
- r: "r";
27
27
  }>;
28
28
  execution_cost: z.ZodNumber;
29
29
  result_rows: z.ZodNumber;
@@ -36,8 +36,8 @@ declare const procedurePropsSchema: z.ZodObject<{
36
36
  argument_types: z.ZodNullable<z.ZodArray<z.ZodString>>;
37
37
  all_argument_types: z.ZodNullable<z.ZodArray<z.ZodString>>;
38
38
  argument_modes: z.ZodNullable<z.ZodArray<z.ZodEnum<{
39
- i: "i";
40
39
  o: "o";
40
+ i: "i";
41
41
  b: "b";
42
42
  v: "v";
43
43
  t: "t";
@@ -96,13 +96,13 @@ export declare class Procedure extends BasePgModel {
96
96
  name: string;
97
97
  };
98
98
  get dataFields(): {
99
- kind: "a" | "w" | "p" | "f";
99
+ kind: "f" | "w" | "a" | "p";
100
100
  return_type: string;
101
101
  return_type_schema: string;
102
102
  language: string;
103
103
  security_definer: boolean;
104
- volatility: "i" | "s" | "v";
105
- parallel_safety: "u" | "s" | "r";
104
+ volatility: "s" | "i" | "v";
105
+ parallel_safety: "r" | "u" | "s";
106
106
  is_strict: boolean;
107
107
  leakproof: boolean;
108
108
  returns_set: boolean;
@@ -111,7 +111,7 @@ export declare class Procedure extends BasePgModel {
111
111
  argument_names: string[] | null;
112
112
  argument_types: string[] | null;
113
113
  all_argument_types: string[] | null;
114
- argument_modes: ("i" | "o" | "b" | "v" | "t")[] | null;
114
+ argument_modes: ("o" | "i" | "b" | "v" | "t")[] | null;
115
115
  argument_defaults: string | null;
116
116
  source_code: string | null;
117
117
  binary_path: string | null;
@@ -128,5 +128,5 @@ export declare class Procedure extends BasePgModel {
128
128
  }[];
129
129
  };
130
130
  }
131
- export declare function extractProcedures(sql: Sql): Promise<Procedure[]>;
131
+ export declare function extractProcedures(pool: Pool): Promise<Procedure[]>;
132
132
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel } from "../base.model.js";
3
4
  import { privilegePropsSchema, } from "../base.privilege-diff.js";
@@ -162,10 +163,8 @@ export class Procedure extends BasePgModel {
162
163
  };
163
164
  }
164
165
  }
165
- export async function extractProcedures(sql) {
166
- return sql.begin(async (sql) => {
167
- await sql `set search_path = ''`;
168
- const procedureRows = await sql `
166
+ export async function extractProcedures(pool) {
167
+ const { rows: procedureRows } = await pool.query(sql `
169
168
  with extension_oids as (
170
169
  select
171
170
  objid
@@ -235,10 +234,9 @@ from
235
234
  and e.objid is null
236
235
  and l.lanname not in ('c', 'internal')
237
236
  order by
238
- 1, 2;
239
- `;
240
- // Validate and parse each row using the Zod schema
241
- const validatedRows = procedureRows.map((row) => procedurePropsSchema.parse(row));
242
- return validatedRows.map((row) => new Procedure(row));
243
- });
237
+ 1, 2
238
+ `);
239
+ // Validate and parse each row using the Zod schema
240
+ const validatedRows = procedureRows.map((row) => procedurePropsSchema.parse(row));
241
+ return validatedRows.map((row) => new Procedure(row));
244
242
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  declare const publicationTablePropsSchema: z.ZodObject<{
@@ -92,5 +92,5 @@ export declare class Publication extends BasePgModel {
92
92
  /**
93
93
  * Extract all logical replication publications from the database.
94
94
  */
95
- export declare function extractPublications(sql: Sql): Promise<Publication[]>;
95
+ export declare function extractPublications(pool: Pool): Promise<Publication[]>;
96
96
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel } from "../base.model.js";
3
4
  const publicationTablePropsSchema = z.object({
@@ -104,10 +105,8 @@ export class Publication extends BasePgModel {
104
105
  /**
105
106
  * Extract all logical replication publications from the database.
106
107
  */
107
- export async function extractPublications(sql) {
108
- return sql.begin(async (tx) => {
109
- await tx `set search_path = ''`;
110
- const rows = await tx `
108
+ export async function extractPublications(pool) {
109
+ const { rows } = await pool.query(sql `
111
110
  with extension_oids as (
112
111
  select objid
113
112
  from pg_depend d
@@ -178,9 +177,8 @@ export async function extractPublications(sql) {
178
177
  from pg_publication p
179
178
  left join extension_oids e on e.objid = p.oid
180
179
  where e.objid is null
181
- order by 1;
182
- `;
183
- const validated = rows.map((row) => publicationPropsSchema.parse(row));
184
- return validated.map((row) => new Publication(row));
185
- });
180
+ order by 1
181
+ `);
182
+ const validated = rows.map((row) => publicationPropsSchema.parse(row));
183
+ return validated.map((row) => new Publication(row));
186
184
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  declare const rlsPolicyPropsSchema: z.ZodObject<{
@@ -6,9 +6,9 @@ declare const rlsPolicyPropsSchema: z.ZodObject<{
6
6
  name: z.ZodString;
7
7
  table_name: z.ZodString;
8
8
  command: z.ZodEnum<{
9
- a: "a";
10
9
  r: "r";
11
10
  w: "w";
11
+ a: "a";
12
12
  d: "d";
13
13
  "*": "*";
14
14
  }>;
@@ -39,7 +39,7 @@ export declare class RlsPolicy extends BasePgModel {
39
39
  name: string;
40
40
  };
41
41
  get dataFields(): {
42
- command: "a" | "r" | "w" | "d" | "*";
42
+ command: "r" | "w" | "a" | "d" | "*";
43
43
  permissive: boolean;
44
44
  roles: string[];
45
45
  using_expression: string | null;
@@ -48,5 +48,5 @@ export declare class RlsPolicy extends BasePgModel {
48
48
  comment: string | null;
49
49
  };
50
50
  }
51
- export declare function extractRlsPolicies(sql: Sql): Promise<RlsPolicy[]>;
51
+ export declare function extractRlsPolicies(pool: Pool): Promise<RlsPolicy[]>;
52
52
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel } from "../base.model.js";
3
4
  const RlsPolicyCommandSchema = z.enum([
@@ -67,10 +68,8 @@ export class RlsPolicy extends BasePgModel {
67
68
  };
68
69
  }
69
70
  }
70
- export async function extractRlsPolicies(sql) {
71
- return sql.begin(async (sql) => {
72
- await sql `set search_path = ''`;
73
- const policyRows = await sql `
71
+ export async function extractRlsPolicies(pool) {
72
+ const { rows: policyRows } = await pool.query(sql `
74
73
  with extension_policy_oids as (
75
74
  select
76
75
  objid
@@ -118,10 +117,9 @@ from
118
117
  and e_policy.objid is null
119
118
  and e_table.objid is null
120
119
  order by
121
- 1, 2;
122
- `;
123
- // Validate and parse each row using the Zod schema
124
- const validatedRows = policyRows.map((row) => rlsPolicyPropsSchema.parse(row));
125
- return validatedRows.map((row) => new RlsPolicy(row));
126
- });
120
+ 1, 2
121
+ `);
122
+ // Validate and parse each row using the Zod schema
123
+ const validatedRows = policyRows.map((row) => rlsPolicyPropsSchema.parse(row));
124
+ return validatedRows.map((row) => new RlsPolicy(row));
127
125
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  declare const rolePropsSchema: z.ZodObject<{
@@ -23,11 +23,11 @@ declare const rolePropsSchema: z.ZodObject<{
23
23
  default_privileges: z.ZodArray<z.ZodObject<{
24
24
  in_schema: z.ZodNullable<z.ZodString>;
25
25
  objtype: z.ZodEnum<{
26
- n: "n";
27
26
  r: "r";
28
- f: "f";
29
27
  S: "S";
28
+ f: "f";
30
29
  T: "T";
30
+ n: "n";
31
31
  }>;
32
32
  grantee: z.ZodString;
33
33
  privileges: z.ZodArray<z.ZodObject<{
@@ -80,10 +80,10 @@ export declare class Role extends BasePgModel {
80
80
  grantable: boolean;
81
81
  }[];
82
82
  in_schema: string | null;
83
- objtype: "n" | "r" | "f" | "S" | "T";
83
+ objtype: "r" | "S" | "f" | "T" | "n";
84
84
  grantee: string;
85
85
  }[];
86
86
  };
87
87
  }
88
- export declare function extractRoles(sql: Sql): Promise<Role[]>;
88
+ export declare function extractRoles(pool: Pool): Promise<Role[]>;
89
89
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel } from "../base.model.js";
3
4
  const membershipInfoSchema = z.object({
@@ -104,11 +105,9 @@ export class Role extends BasePgModel {
104
105
  };
105
106
  }
106
107
  }
107
- export async function extractRoles(sql) {
108
- return sql.begin(async (sql) => {
109
- await sql `set search_path = ''`;
110
- // Check PostgreSQL version capabilities for membership options
111
- const [capabilities] = await sql `
108
+ export async function extractRoles(pool) {
109
+ // Check PostgreSQL version capabilities for membership options
110
+ const { rows: capabilitiesRows } = await pool.query(sql `
112
111
  select
113
112
  exists (
114
113
  select 1
@@ -122,23 +121,25 @@ export async function extractRoles(sql) {
122
121
  where attrelid = 'pg_auth_members'::regclass
123
122
  and attname = 'set_option'
124
123
  ) as has_set
125
- `;
126
- const roleRows = capabilities?.has_inherit && capabilities?.has_set
127
- ? await sql `
124
+ `);
125
+ const capabilities = capabilitiesRows[0];
126
+ let roleRows;
127
+ if (capabilities?.has_inherit && capabilities?.has_set) {
128
+ const result = await pool.query(sql `
128
129
  WITH role_memberships AS (
129
- SELECT
130
+ SELECT
130
131
  r.rolname AS role_name,
131
132
  json_agg(
132
133
  json_build_object(
133
134
  'member', m.rolname,
134
135
  'grantor', g.rolname,
135
136
  'admin_option', am.admin_option,
136
- 'inherit_option', am.inherit_option, -- PG16+
137
- 'set_option', am.set_option -- PG16+
137
+ 'inherit_option', am.inherit_option,
138
+ 'set_option', am.set_option
138
139
  )
139
140
  ) FILTER (WHERE m.rolname IS NOT NULL) AS members
140
141
  FROM pg_catalog.pg_roles r
141
- LEFT JOIN pg_auth_members am ON am.roleid = r.oid -- roles that are members of this role
142
+ LEFT JOIN pg_auth_members am ON am.roleid = r.oid
142
143
  LEFT JOIN pg_roles m ON m.oid = am.member
143
144
  LEFT JOIN pg_roles g ON g.oid = am.grantor
144
145
  GROUP BY r.rolname
@@ -201,9 +202,7 @@ export async function extractRoles(sql) {
201
202
  FROM pg_catalog.pg_roles r
202
203
  LEFT JOIN role_memberships rm ON rm.role_name = r.rolname
203
204
  WHERE
204
- -- 1) drop built-in/internal roles (anything starting with pg_)
205
205
  r.rolname !~ '^pg_'
206
- -- 2) drop roles directly tracked as extension members in pg_shdepend (if any)
207
206
  AND NOT EXISTS (
208
207
  SELECT 1
209
208
  FROM pg_catalog.pg_shdepend d
@@ -212,24 +211,26 @@ export async function extractRoles(sql) {
212
211
  AND d.refclassid = 'pg_extension'::regclass
213
212
  AND d.deptype IN ('e','x')
214
213
  )
215
- ORDER BY 1;
216
- `
217
- : await sql `
214
+ ORDER BY 1
215
+ `);
216
+ roleRows = result.rows;
217
+ }
218
+ else {
219
+ const result = await pool.query(sql `
218
220
  WITH role_memberships AS (
219
- SELECT
221
+ SELECT
220
222
  r.rolname AS role_name,
221
223
  json_agg(
222
224
  json_build_object(
223
225
  'member', m.rolname,
224
226
  'grantor', g.rolname,
225
227
  'admin_option', am.admin_option,
226
- -- PG15: these columns don't exist; emit them as nulls
227
228
  'inherit_option', NULL,
228
229
  'set_option', NULL
229
230
  )
230
231
  ) FILTER (WHERE m.rolname IS NOT NULL) AS members
231
232
  FROM pg_catalog.pg_roles r
232
- LEFT JOIN pg_auth_members am ON am.roleid = r.oid -- roles that are members of this role
233
+ LEFT JOIN pg_auth_members am ON am.roleid = r.oid
233
234
  LEFT JOIN pg_roles m ON m.oid = am.member
234
235
  LEFT JOIN pg_roles g ON g.oid = am.grantor
235
236
  GROUP BY r.rolname
@@ -292,9 +293,7 @@ export async function extractRoles(sql) {
292
293
  FROM pg_catalog.pg_roles r
293
294
  LEFT JOIN role_memberships rm ON rm.role_name = r.rolname
294
295
  WHERE
295
- -- drop built-in/internal roles
296
296
  r.rolname !~ '^pg_'
297
- -- drop roles directly tracked as extension members in pg_shdepend (if any)
298
297
  AND NOT EXISTS (
299
298
  SELECT 1
300
299
  FROM pg_catalog.pg_shdepend d
@@ -303,10 +302,11 @@ export async function extractRoles(sql) {
303
302
  AND d.refclassid = 'pg_extension'::regclass
304
303
  AND d.deptype IN ('e','x')
305
304
  )
306
- ORDER BY 1;
307
- `;
308
- // Validate and parse each row using the Zod schema
309
- const validatedRows = roleRows.map((row) => rolePropsSchema.parse(row));
310
- return validatedRows.map((row) => new Role(row));
311
- });
305
+ ORDER BY 1
306
+ `);
307
+ roleRows = result.rows;
308
+ }
309
+ // Validate and parse each row using the Zod schema
310
+ const validatedRows = roleRows.map((row) => rolePropsSchema.parse(row));
311
+ return validatedRows.map((row) => new Role(row));
312
312
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  declare const RuleEnabledStateSchema: z.ZodEnum<{
@@ -13,10 +13,10 @@ declare const rulePropsSchema: z.ZodObject<{
13
13
  table_name: z.ZodString;
14
14
  relation_kind: z.ZodEnum<{
15
15
  r: "r";
16
+ f: "f";
16
17
  v: "v";
17
18
  m: "m";
18
19
  p: "p";
19
- f: "f";
20
20
  }>;
21
21
  event: z.ZodEnum<{
22
22
  DELETE: "DELETE";
@@ -68,5 +68,5 @@ export declare class Rule extends BasePgModel {
68
68
  };
69
69
  get relationStableId(): string;
70
70
  }
71
- export declare function extractRules(sql: Sql): Promise<Rule[]>;
71
+ export declare function extractRules(pool: Pool): Promise<Rule[]>;
72
72
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel } from "../base.model.js";
3
4
  import { stableId } from "../utils.js";
@@ -81,10 +82,8 @@ export class Rule extends BasePgModel {
81
82
  }
82
83
  }
83
84
  }
84
- export async function extractRules(sql) {
85
- return sql.begin(async (sql) => {
86
- await sql `set search_path = ''`;
87
- const ruleRows = await sql `
85
+ export async function extractRules(pool) {
86
+ const { rows: ruleRows } = await pool.query(sql `
88
87
  WITH extension_rule_oids AS (
89
88
  SELECT
90
89
  objid
@@ -148,9 +147,8 @@ export async function extractRules(sql) {
148
147
  AND e_rel.objid IS NULL
149
148
  AND r.rulename <> '_RETURN'
150
149
  ORDER BY
151
- 1, 3, 2;
152
- `;
153
- const validatedRows = ruleRows.map((row) => rulePropsSchema.parse(row));
154
- return validatedRows.map((row) => new Rule(row));
155
- });
150
+ 1, 3, 2
151
+ `);
152
+ const validatedRows = ruleRows.map((row) => rulePropsSchema.parse(row));
153
+ return validatedRows.map((row) => new Rule(row));
156
154
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  import { type PrivilegeProps } from "../base.privilege-diff.ts";
@@ -43,5 +43,5 @@ export declare class Schema extends BasePgModel {
43
43
  }[];
44
44
  };
45
45
  }
46
- export declare function extractSchemas(sql: Sql): Promise<Schema[]>;
46
+ export declare function extractSchemas(pool: Pool): Promise<Schema[]>;
47
47
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel } from "../base.model.js";
3
4
  import { privilegePropsSchema, } from "../base.privilege-diff.js";
@@ -44,10 +45,8 @@ export class Schema extends BasePgModel {
44
45
  };
45
46
  }
46
47
  }
47
- export async function extractSchemas(sql) {
48
- return sql.begin(async (sql) => {
49
- await sql `set search_path = ''`;
50
- const schemaRows = await sql `
48
+ export async function extractSchemas(pool) {
49
+ const { rows: schemaRows } = await pool.query(sql `
51
50
  with extension_oids as (
52
51
  select
53
52
  objid
@@ -82,10 +81,9 @@ export async function extractSchemas(sql) {
82
81
  and e.objid is null
83
82
  -- </EXCLUDE_INTERNAL>
84
83
  order by
85
- 1;
86
- `;
87
- // Validate and parse each row using the Zod schema
88
- const validatedRows = schemaRows.map((row) => schemaPropsSchema.parse(row));
89
- return validatedRows.map((row) => new Schema(row));
90
- });
84
+ 1
85
+ `);
86
+ // Validate and parse each row using the Zod schema
87
+ const validatedRows = schemaRows.map((row) => schemaPropsSchema.parse(row));
88
+ return validatedRows.map((row) => new Schema(row));
91
89
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  import { type PrivilegeProps } from "../base.privilege-diff.ts";
@@ -72,5 +72,5 @@ export declare class Sequence extends BasePgModel {
72
72
  owner: string;
73
73
  };
74
74
  }
75
- export declare function extractSequences(sql: Sql): Promise<Sequence[]>;
75
+ export declare function extractSequences(pool: Pool): Promise<Sequence[]>;
76
76
  export {};
@@ -1,3 +1,4 @@
1
+ import { sql } from "@ts-safeql/sql-tag";
1
2
  import z from "zod";
2
3
  import { BasePgModel } from "../base.model.js";
3
4
  import { privilegePropsSchema, } from "../base.privilege-diff.js";
@@ -85,10 +86,8 @@ export class Sequence extends BasePgModel {
85
86
  };
86
87
  }
87
88
  }
88
- export async function extractSequences(sql) {
89
- return sql.begin(async (sql) => {
90
- await sql `set search_path = ''`;
91
- const sequenceRows = await sql `
89
+ export async function extractSequences(pool) {
90
+ const { rows: sequenceRows } = await pool.query(sql `
92
91
  with extension_sequence_oids as (
93
92
  select
94
93
  objid
@@ -160,10 +159,9 @@ from
160
159
  and di.deptype = 'i'
161
160
  )
162
161
  order by
163
- 1, 2;
164
- `;
165
- // Validate and parse each row using the Zod schema
166
- const validatedRows = sequenceRows.map((row) => sequencePropsSchema.parse(row));
167
- return validatedRows.map((row) => new Sequence(row));
168
- });
162
+ 1, 2
163
+ `);
164
+ // Validate and parse each row using the Zod schema
165
+ const validatedRows = sequenceRows.map((row) => sequencePropsSchema.parse(row));
166
+ return validatedRows.map((row) => new Sequence(row));
169
167
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
1
+ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  declare const subscriptionPropsSchema: z.ZodObject<{
@@ -76,5 +76,5 @@ export declare class Subscription extends BasePgModel {
76
76
  origin: "any" | "none";
77
77
  };
78
78
  }
79
- export declare function extractSubscriptions(sql: Sql): Promise<Subscription[]>;
79
+ export declare function extractSubscriptions(pool: Pool): Promise<Subscription[]>;
80
80
  export {};