@supabase/pg-delta 1.0.0-alpha.1 → 1.0.0-alpha.3
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.
- package/dist/core/catalog.model.d.ts +2 -2
- package/dist/core/catalog.model.js +29 -29
- package/dist/core/context.d.ts +3 -3
- package/dist/core/context.js +7 -10
- package/dist/core/depend.d.ts +2 -2
- package/dist/core/depend.js +8 -7
- package/dist/core/integrations/supabase.js +2 -0
- package/dist/core/objects/aggregate/aggregate.model.d.ts +2 -2
- package/dist/core/objects/aggregate/aggregate.model.js +7 -9
- package/dist/core/objects/collation/collation.model.d.ts +2 -2
- package/dist/core/objects/collation/collation.model.js +29 -28
- package/dist/core/objects/domain/domain.model.d.ts +2 -2
- package/dist/core/objects/domain/domain.model.js +8 -10
- package/dist/core/objects/event-trigger/event-trigger.model.d.ts +2 -2
- package/dist/core/objects/event-trigger/event-trigger.model.js +7 -9
- package/dist/core/objects/extension/extension.model.d.ts +2 -2
- package/dist/core/objects/extension/extension.model.js +8 -10
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.d.ts +2 -2
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.js +20 -22
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.d.ts +2 -2
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.js +20 -22
- package/dist/core/objects/foreign-data-wrapper/server/server.model.d.ts +2 -2
- package/dist/core/objects/foreign-data-wrapper/server/server.model.js +20 -22
- package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.d.ts +2 -2
- package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.js +20 -22
- package/dist/core/objects/index/index.model.d.ts +4 -4
- package/dist/core/objects/index/index.model.js +9 -11
- package/dist/core/objects/language/language.model.js +5 -7
- package/dist/core/objects/materialized-view/materialized-view.model.d.ts +2 -2
- package/dist/core/objects/materialized-view/materialized-view.model.js +8 -10
- package/dist/core/objects/procedure/procedure.model.d.ts +2 -2
- package/dist/core/objects/procedure/procedure.model.js +8 -10
- package/dist/core/objects/publication/publication.model.d.ts +2 -2
- package/dist/core/objects/publication/publication.model.js +7 -9
- package/dist/core/objects/rls-policy/rls-policy.model.d.ts +2 -2
- package/dist/core/objects/rls-policy/rls-policy.model.js +8 -10
- package/dist/core/objects/role/role.model.d.ts +2 -2
- package/dist/core/objects/role/role.model.js +28 -28
- package/dist/core/objects/rule/rule.model.d.ts +2 -2
- package/dist/core/objects/rule/rule.model.js +7 -9
- package/dist/core/objects/schema/schema.model.d.ts +2 -2
- package/dist/core/objects/schema/schema.model.js +8 -10
- package/dist/core/objects/sequence/sequence.model.d.ts +2 -2
- package/dist/core/objects/sequence/sequence.model.js +8 -10
- package/dist/core/objects/subscription/subscription.model.d.ts +2 -2
- package/dist/core/objects/subscription/subscription.model.js +25 -20
- package/dist/core/objects/table/table.model.d.ts +2 -2
- package/dist/core/objects/table/table.model.js +8 -10
- package/dist/core/objects/trigger/trigger.model.d.ts +2 -2
- package/dist/core/objects/trigger/trigger.model.js +8 -10
- package/dist/core/objects/type/composite-type/composite-type.model.d.ts +2 -2
- package/dist/core/objects/type/composite-type/composite-type.model.js +8 -10
- package/dist/core/objects/type/enum/enum.model.d.ts +2 -2
- package/dist/core/objects/type/enum/enum.model.js +22 -24
- package/dist/core/objects/type/range/range.model.d.ts +2 -2
- package/dist/core/objects/type/range/range.model.js +7 -9
- package/dist/core/objects/view/view.model.d.ts +2 -2
- package/dist/core/objects/view/view.model.js +8 -10
- package/dist/core/plan/apply.d.ts +2 -2
- package/dist/core/plan/apply.js +50 -16
- package/dist/core/plan/create.d.ts +2 -2
- package/dist/core/plan/create.js +84 -38
- package/dist/core/postgres-config.d.ts +18 -3
- package/dist/core/postgres-config.js +105 -41
- package/package.json +4 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
import { type PgDepend } from "./depend.ts";
|
|
3
3
|
import { type Aggregate } from "./objects/aggregate/aggregate.model.ts";
|
|
4
4
|
import type { TableLikeObject } from "./objects/base.model.ts";
|
|
@@ -89,5 +89,5 @@ export declare class Catalog {
|
|
|
89
89
|
readonly currentUser: CatalogProps["currentUser"];
|
|
90
90
|
constructor(props: CatalogProps);
|
|
91
91
|
}
|
|
92
|
-
export declare function extractCatalog(
|
|
92
|
+
export declare function extractCatalog(pool: Pool): Promise<Catalog>;
|
|
93
93
|
export {};
|
|
@@ -88,36 +88,36 @@ export class Catalog {
|
|
|
88
88
|
this.currentUser = props.currentUser;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
export async function extractCatalog(
|
|
91
|
+
export async function extractCatalog(pool) {
|
|
92
92
|
const [aggregates, collations, compositeTypes, domains, enums, extensions, indexes, materializedViews, subscriptions, publications, procedures, rlsPolicies, roles, schemas, sequences, tables, triggers, eventTriggers, rules, ranges, views, foreignDataWrappers, servers, userMappings, foreignTables, depends, version, currentUser,] = await Promise.all([
|
|
93
|
-
extractAggregates(
|
|
94
|
-
extractCollations(
|
|
95
|
-
extractCompositeTypes(
|
|
96
|
-
extractDomains(
|
|
97
|
-
extractEnums(
|
|
98
|
-
extractExtensions(
|
|
99
|
-
extractIndexes(
|
|
100
|
-
extractMaterializedViews(
|
|
101
|
-
extractSubscriptions(
|
|
102
|
-
extractPublications(
|
|
103
|
-
extractProcedures(
|
|
104
|
-
extractRlsPolicies(
|
|
105
|
-
extractRoles(
|
|
106
|
-
extractSchemas(
|
|
107
|
-
extractSequences(
|
|
108
|
-
extractTables(
|
|
109
|
-
extractTriggers(
|
|
110
|
-
extractEventTriggers(
|
|
111
|
-
extractRules(
|
|
112
|
-
extractRanges(
|
|
113
|
-
extractViews(
|
|
114
|
-
extractForeignDataWrappers(
|
|
115
|
-
extractServers(
|
|
116
|
-
extractUserMappings(
|
|
117
|
-
extractForeignTables(
|
|
118
|
-
extractDepends(
|
|
119
|
-
extractVersion(
|
|
120
|
-
extractCurrentUser(
|
|
93
|
+
extractAggregates(pool).then(listToRecord),
|
|
94
|
+
extractCollations(pool).then(listToRecord),
|
|
95
|
+
extractCompositeTypes(pool).then(listToRecord),
|
|
96
|
+
extractDomains(pool).then(listToRecord),
|
|
97
|
+
extractEnums(pool).then(listToRecord),
|
|
98
|
+
extractExtensions(pool).then(listToRecord),
|
|
99
|
+
extractIndexes(pool).then(listToRecord),
|
|
100
|
+
extractMaterializedViews(pool).then(listToRecord),
|
|
101
|
+
extractSubscriptions(pool).then(listToRecord),
|
|
102
|
+
extractPublications(pool).then(listToRecord),
|
|
103
|
+
extractProcedures(pool).then(listToRecord),
|
|
104
|
+
extractRlsPolicies(pool).then(listToRecord),
|
|
105
|
+
extractRoles(pool).then(listToRecord),
|
|
106
|
+
extractSchemas(pool).then(listToRecord),
|
|
107
|
+
extractSequences(pool).then(listToRecord),
|
|
108
|
+
extractTables(pool).then(listToRecord),
|
|
109
|
+
extractTriggers(pool).then(listToRecord),
|
|
110
|
+
extractEventTriggers(pool).then(listToRecord),
|
|
111
|
+
extractRules(pool).then(listToRecord),
|
|
112
|
+
extractRanges(pool).then(listToRecord),
|
|
113
|
+
extractViews(pool).then(listToRecord),
|
|
114
|
+
extractForeignDataWrappers(pool).then(listToRecord),
|
|
115
|
+
extractServers(pool).then(listToRecord),
|
|
116
|
+
extractUserMappings(pool).then(listToRecord),
|
|
117
|
+
extractForeignTables(pool).then(listToRecord),
|
|
118
|
+
extractDepends(pool),
|
|
119
|
+
extractVersion(pool),
|
|
120
|
+
extractCurrentUser(pool),
|
|
121
121
|
]);
|
|
122
122
|
const indexableObjects = {
|
|
123
123
|
...tables,
|
package/dist/core/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
import type { Catalog } from "./catalog.model.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Context for diff operations, containing both source and target catalogs.
|
|
@@ -7,5 +7,5 @@ export interface DiffContext {
|
|
|
7
7
|
mainCatalog: Catalog;
|
|
8
8
|
branchCatalog: Catalog;
|
|
9
9
|
}
|
|
10
|
-
export declare function extractVersion(
|
|
11
|
-
export declare function extractCurrentUser(
|
|
10
|
+
export declare function extractVersion(pool: Pool): Promise<number>;
|
|
11
|
+
export declare function extractCurrentUser(pool: Pool): Promise<string>;
|
package/dist/core/context.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
select current_setting('server_version_num')::int as version;
|
|
4
|
-
|
|
5
|
-
return version;
|
|
1
|
+
import { sql } from "@ts-safeql/sql-tag";
|
|
2
|
+
export async function extractVersion(pool) {
|
|
3
|
+
const { rows } = await pool.query(sql `select current_setting('server_version_num')::int as version`);
|
|
4
|
+
return rows[0].version;
|
|
6
5
|
}
|
|
7
|
-
export async function extractCurrentUser(
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
`;
|
|
11
|
-
return current_user;
|
|
6
|
+
export async function extractCurrentUser(pool) {
|
|
7
|
+
const { rows } = await pool.query(sql `select quote_ident(current_user) as current_user`);
|
|
8
|
+
return rows[0].current_user;
|
|
12
9
|
}
|
package/dist/core/depend.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
/**
|
|
3
3
|
* Dependency type as defined in PostgreSQL's pg_depend.deptype.
|
|
4
4
|
* n: normal
|
|
@@ -27,5 +27,5 @@ export interface PgDepend {
|
|
|
27
27
|
* @param params - Object containing arrays of OIDs for filtering (user_oids, user_namespace_oids, etc.)
|
|
28
28
|
* @returns Array of dependency objects with class names.
|
|
29
29
|
*/
|
|
30
|
-
export declare function extractDepends(
|
|
30
|
+
export declare function extractDepends(pool: Pool): Promise<PgDepend[]>;
|
|
31
31
|
export {};
|
package/dist/core/depend.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sql } from "@ts-safeql/sql-tag";
|
|
1
2
|
/**
|
|
2
3
|
* Extract dependencies for privileges and memberships so that GRANT/REVOKE
|
|
3
4
|
* operations are properly ordered with respect to their target objects/roles.
|
|
@@ -13,8 +14,8 @@
|
|
|
13
14
|
* - membership:<role>-><member> -> role:<role>
|
|
14
15
|
* - membership:<role>-><member> -> role:<member>
|
|
15
16
|
*/
|
|
16
|
-
async function extractPrivilegeAndMembershipDepends(
|
|
17
|
-
const rows = await sql `
|
|
17
|
+
async function extractPrivilegeAndMembershipDepends(pool) {
|
|
18
|
+
const { rows } = await pool.query(sql `
|
|
18
19
|
with
|
|
19
20
|
-- OBJECT PRIVILEGES (relations)
|
|
20
21
|
extension_rel_oids as (
|
|
@@ -468,7 +469,7 @@ where dependent_stable_id <> referenced_stable_id
|
|
|
468
469
|
and NOT (
|
|
469
470
|
COALESCE(dep_schema, '') LIKE ANY (ARRAY['pg\\_%','information\\_schema'])
|
|
470
471
|
)
|
|
471
|
-
|
|
472
|
+
`);
|
|
472
473
|
return rows;
|
|
473
474
|
}
|
|
474
475
|
/**
|
|
@@ -477,8 +478,8 @@ where dependent_stable_id <> referenced_stable_id
|
|
|
477
478
|
* @param params - Object containing arrays of OIDs for filtering (user_oids, user_namespace_oids, etc.)
|
|
478
479
|
* @returns Array of dependency objects with class names.
|
|
479
480
|
*/
|
|
480
|
-
export async function extractDepends(
|
|
481
|
-
const dependsRows = await sql `
|
|
481
|
+
export async function extractDepends(pool) {
|
|
482
|
+
const { rows: dependsRows } = await pool.query(sql `
|
|
482
483
|
WITH ids AS (
|
|
483
484
|
-- only the objects that actually show up in dependencies (both sides)
|
|
484
485
|
SELECT DISTINCT classid, objid, objsubid FROM pg_depend WHERE deptype IN ('n','a')
|
|
@@ -1823,9 +1824,9 @@ export async function extractDepends(sql) {
|
|
|
1823
1824
|
COALESCE(dep_schema, '') LIKE ANY (ARRAY['pg\\_%','information\\_schema'])
|
|
1824
1825
|
)
|
|
1825
1826
|
ORDER BY dependent_stable_id, referenced_stable_id;
|
|
1826
|
-
|
|
1827
|
+
`);
|
|
1827
1828
|
// Extract privilege and membership dependencies
|
|
1828
|
-
const privilegeDepends = await extractPrivilegeAndMembershipDepends(
|
|
1829
|
+
const privilegeDepends = await extractPrivilegeAndMembershipDepends(pool);
|
|
1829
1830
|
// Combine all dependency sources and remove duplicates
|
|
1830
1831
|
const allDepends = new Set([...dependsRows, ...privilegeDepends]);
|
|
1831
1832
|
return Array.from(allDepends).sort((a, b) => a.dependent_stable_id.localeCompare(b.dependent_stable_id) ||
|
|
@@ -35,6 +35,7 @@ const SUPABASE_SYSTEM_ROLES = [
|
|
|
35
35
|
"anon",
|
|
36
36
|
"authenticated",
|
|
37
37
|
"authenticator",
|
|
38
|
+
"cli_login_postgres",
|
|
38
39
|
"dashboard_user",
|
|
39
40
|
"pgbouncer",
|
|
40
41
|
"pgsodium_keyholder",
|
|
@@ -50,6 +51,7 @@ const SUPABASE_SYSTEM_ROLES = [
|
|
|
50
51
|
"supabase_realtime_admin",
|
|
51
52
|
"supabase_replication_admin",
|
|
52
53
|
"supabase_storage_admin",
|
|
54
|
+
"supabase_superuser",
|
|
53
55
|
];
|
|
54
56
|
export const supabase = {
|
|
55
57
|
filter: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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";
|
|
@@ -170,5 +170,5 @@ export declare class Aggregate extends BasePgModel {
|
|
|
170
170
|
}[];
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
-
export declare function extractAggregates(
|
|
173
|
+
export declare function extractAggregates(pool: Pool): Promise<Aggregate[]>;
|
|
174
174
|
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";
|
|
@@ -208,10 +209,8 @@ export class Aggregate extends BasePgModel {
|
|
|
208
209
|
};
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
|
-
export async function extractAggregates(
|
|
212
|
-
|
|
213
|
-
await sql `set search_path = ''`;
|
|
214
|
-
const aggregateRows = await sql `
|
|
212
|
+
export async function extractAggregates(pool) {
|
|
213
|
+
const { rows: aggregateRows } = await pool.query(sql `
|
|
215
214
|
with extension_oids as (
|
|
216
215
|
select
|
|
217
216
|
objid
|
|
@@ -289,9 +288,8 @@ where
|
|
|
289
288
|
and not p.pronamespace::regnamespace::text like any(array['pg\\_%', 'information\\_schema'])
|
|
290
289
|
and e.objid is null
|
|
291
290
|
order by
|
|
292
|
-
1, 2, 3
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
});
|
|
291
|
+
1, 2, 3
|
|
292
|
+
`);
|
|
293
|
+
const validatedRows = aggregateRows.map((row) => aggregatePropsSchema.parse(row));
|
|
294
|
+
return validatedRows.map((row) => new Aggregate(row));
|
|
297
295
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel } from "../base.model.ts";
|
|
4
4
|
/**
|
|
@@ -63,5 +63,5 @@ export declare class Collation extends BasePgModel {
|
|
|
63
63
|
comment: string | null;
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
export declare function extractCollations(
|
|
66
|
+
export declare function extractCollations(pool: Pool): Promise<Collation[]>;
|
|
67
67
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sql } from "@ts-safeql/sql-tag";
|
|
1
2
|
import z from "zod";
|
|
2
3
|
import { extractVersion } from "../../context.js";
|
|
3
4
|
import { BasePgModel } from "../base.model.js";
|
|
@@ -88,15 +89,13 @@ export class Collation extends BasePgModel {
|
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
export async function extractCollations(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (isPostgres17OrGreater) {
|
|
99
|
-
collations = await sql `
|
|
92
|
+
export async function extractCollations(pool) {
|
|
93
|
+
const version = await extractVersion(pool);
|
|
94
|
+
const isPostgres17OrGreater = version >= 170000;
|
|
95
|
+
const isPostgres16OrGreater = version >= 160000;
|
|
96
|
+
let collationRows;
|
|
97
|
+
if (isPostgres17OrGreater) {
|
|
98
|
+
const result = await pool.query(sql `
|
|
100
99
|
with extension_oids as (
|
|
101
100
|
select
|
|
102
101
|
objid
|
|
@@ -125,12 +124,13 @@ export async function extractCollations(sql) {
|
|
|
125
124
|
where not c.collnamespace::regnamespace::text like any(array['pg\\_%', 'information\\_schema'])
|
|
126
125
|
and e.objid is null
|
|
127
126
|
order by
|
|
128
|
-
1, 2
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
1, 2
|
|
128
|
+
`);
|
|
129
|
+
collationRows = result.rows;
|
|
130
|
+
}
|
|
131
|
+
else if (isPostgres16OrGreater) {
|
|
132
|
+
// On postgres 16 there colllocale column was named colliculocale
|
|
133
|
+
const result = await pool.query(sql `
|
|
134
134
|
with extension_oids as (
|
|
135
135
|
select
|
|
136
136
|
objid
|
|
@@ -161,12 +161,13 @@ export async function extractCollations(sql) {
|
|
|
161
161
|
and e.objid is null
|
|
162
162
|
-- </EXCLUDE_INTERNAL>
|
|
163
163
|
order by
|
|
164
|
-
1, 2
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
1, 2
|
|
165
|
+
`);
|
|
166
|
+
collationRows = result.rows;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// On postgres 15 icu_rules does not exist
|
|
170
|
+
const result = await pool.query(sql `
|
|
170
171
|
with extension_oids as (
|
|
171
172
|
select
|
|
172
173
|
objid
|
|
@@ -197,11 +198,11 @@ export async function extractCollations(sql) {
|
|
|
197
198
|
and e.objid is null
|
|
198
199
|
-- </EXCLUDE_INTERNAL>
|
|
199
200
|
order by
|
|
200
|
-
1, 2
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
1, 2
|
|
202
|
+
`);
|
|
203
|
+
collationRows = result.rows;
|
|
204
|
+
}
|
|
205
|
+
// Validate and parse each row using the Zod schema
|
|
206
|
+
const validatedRows = collationRows.map((row) => collationPropsSchema.parse(row));
|
|
207
|
+
return validatedRows.map((row) => new Collation(row));
|
|
207
208
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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";
|
|
@@ -99,5 +99,5 @@ export declare class Domain extends BasePgModel {
|
|
|
99
99
|
* @param sql - The SQL client.
|
|
100
100
|
* @returns A list of domains.
|
|
101
101
|
*/
|
|
102
|
-
export declare function extractDomains(
|
|
102
|
+
export declare function extractDomains(pool: Pool): Promise<Domain[]>;
|
|
103
103
|
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";
|
|
@@ -98,10 +99,8 @@ export class Domain extends BasePgModel {
|
|
|
98
99
|
* @param sql - The SQL client.
|
|
99
100
|
* @returns A list of domains.
|
|
100
101
|
*/
|
|
101
|
-
export async function extractDomains(
|
|
102
|
-
|
|
103
|
-
await sql `set search_path = ''`;
|
|
104
|
-
const domainRows = await sql `
|
|
102
|
+
export async function extractDomains(pool) {
|
|
103
|
+
const { rows: domainRows } = await pool.query(sql `
|
|
105
104
|
with extension_oids as (
|
|
106
105
|
select
|
|
107
106
|
objid
|
|
@@ -163,10 +162,9 @@ export async function extractDomains(sql) {
|
|
|
163
162
|
and e.objid is null
|
|
164
163
|
and t.typtype = 'd'
|
|
165
164
|
order by
|
|
166
|
-
1, 2
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
165
|
+
1, 2
|
|
166
|
+
`);
|
|
167
|
+
// Validate and parse each row using the Zod schema
|
|
168
|
+
const validatedRows = domainRows.map((row) => domainPropsSchema.parse(row));
|
|
169
|
+
return validatedRows.map((row) => new Domain(row));
|
|
172
170
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel } from "../base.model.ts";
|
|
4
4
|
declare const eventTriggerPropsSchema: z.ZodObject<{
|
|
@@ -41,5 +41,5 @@ export declare class EventTrigger extends BasePgModel {
|
|
|
41
41
|
comment: string | null;
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
export declare function extractEventTriggers(
|
|
44
|
+
export declare function extractEventTriggers(pool: Pool): Promise<EventTrigger[]>;
|
|
45
45
|
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 EventTriggerEnabledSchema = z.enum([
|
|
@@ -58,10 +59,8 @@ export class EventTrigger extends BasePgModel {
|
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
export async function extractEventTriggers(
|
|
62
|
-
|
|
63
|
-
await sql `set search_path = ''`;
|
|
64
|
-
const rows = await sql `
|
|
62
|
+
export async function extractEventTriggers(pool) {
|
|
63
|
+
const { rows } = await pool.query(sql `
|
|
65
64
|
with extension_oids as (
|
|
66
65
|
select objid
|
|
67
66
|
from pg_depend d
|
|
@@ -81,9 +80,8 @@ from pg_catalog.pg_event_trigger et
|
|
|
81
80
|
join pg_catalog.pg_proc p on p.oid = et.evtfoid
|
|
82
81
|
left join extension_oids e on e.objid = et.oid
|
|
83
82
|
where e.objid is null
|
|
84
|
-
order by 1
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
83
|
+
order by 1
|
|
84
|
+
`);
|
|
85
|
+
const validatedRows = rows.map((row) => eventTriggerPropsSchema.parse(row));
|
|
86
|
+
return validatedRows.map((row) => new EventTrigger(row));
|
|
89
87
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel } from "../base.model.ts";
|
|
4
4
|
/**
|
|
@@ -48,5 +48,5 @@ export declare class Extension extends BasePgModel {
|
|
|
48
48
|
comment: string | null;
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
export declare function extractExtensions(
|
|
51
|
+
export declare function extractExtensions(pool: Pool): Promise<Extension[]>;
|
|
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
|
/**
|
|
@@ -65,10 +66,8 @@ export class Extension extends BasePgModel {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
// TODO: fetch extension dependencies so we can determine when to use CASCADE on creation
|
|
68
|
-
export async function extractExtensions(
|
|
69
|
-
|
|
70
|
-
await sql `set search_path = ''`;
|
|
71
|
-
const extensionRows = await sql `
|
|
69
|
+
export async function extractExtensions(pool) {
|
|
70
|
+
const { rows: extensionRows } = await pool.query(sql `
|
|
72
71
|
with extension_rows as (
|
|
73
72
|
select
|
|
74
73
|
e.oid,
|
|
@@ -259,10 +258,9 @@ export async function extractExtensions(sql) {
|
|
|
259
258
|
) as members
|
|
260
259
|
from extension_rows er
|
|
261
260
|
order by
|
|
262
|
-
er.name
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
});
|
|
261
|
+
er.name
|
|
262
|
+
`);
|
|
263
|
+
// Validate and parse each row using the Zod schema
|
|
264
|
+
const validatedRows = extensionRows.map((row) => extensionPropsSchema.parse(row));
|
|
265
|
+
return validatedRows.map((row) => new Extension(row));
|
|
268
266
|
}
|
package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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";
|
|
@@ -55,5 +55,5 @@ export declare class ForeignDataWrapper extends BasePgModel {
|
|
|
55
55
|
}[];
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
export declare function extractForeignDataWrappers(
|
|
58
|
+
export declare function extractForeignDataWrappers(pool: Pool): Promise<ForeignDataWrapper[]>;
|
|
59
59
|
export {};
|
package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.js
CHANGED
|
@@ -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";
|
|
@@ -59,10 +60,8 @@ export class ForeignDataWrapper extends BasePgModel {
|
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
export async function extractForeignDataWrappers(
|
|
63
|
-
|
|
64
|
-
await sql `set search_path = ''`;
|
|
65
|
-
const fdwRows = await sql `
|
|
63
|
+
export async function extractForeignDataWrappers(pool) {
|
|
64
|
+
const { rows: fdwRows } = await pool.query(sql `
|
|
66
65
|
with extension_oids as (
|
|
67
66
|
select objid
|
|
68
67
|
from pg_depend d
|
|
@@ -104,25 +103,24 @@ export async function extractForeignDataWrappers(sql) {
|
|
|
104
103
|
not fdw.fdwname like any(array['pg\\_%'])
|
|
105
104
|
and e.objid is null
|
|
106
105
|
order by
|
|
107
|
-
fdw.fdwname
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
106
|
+
fdw.fdwname
|
|
107
|
+
`);
|
|
108
|
+
// Validate and parse each row using the Zod schema
|
|
109
|
+
const validatedRows = fdwRows.map((row) => {
|
|
110
|
+
const parsed = foreignDataWrapperPropsSchema.parse(row);
|
|
111
|
+
// Parse options from PostgreSQL format ['key=value'] to ['key', 'value']
|
|
112
|
+
if (parsed.options && parsed.options.length > 0) {
|
|
113
|
+
const parsedOptions = [];
|
|
114
|
+
for (const opt of parsed.options) {
|
|
115
|
+
const eqIndex = opt.indexOf("=");
|
|
116
|
+
if (eqIndex > 0) {
|
|
117
|
+
parsedOptions.push(opt.substring(0, eqIndex));
|
|
118
|
+
parsedOptions.push(opt.substring(eqIndex + 1));
|
|
121
119
|
}
|
|
122
|
-
parsed.options = parsedOptions.length > 0 ? parsedOptions : null;
|
|
123
120
|
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
return
|
|
121
|
+
parsed.options = parsedOptions.length > 0 ? parsedOptions : null;
|
|
122
|
+
}
|
|
123
|
+
return parsed;
|
|
127
124
|
});
|
|
125
|
+
return validatedRows.map((row) => new ForeignDataWrapper(row));
|
|
128
126
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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";
|
|
@@ -113,5 +113,5 @@ export declare class ForeignTable extends BasePgModel implements TableLikeObject
|
|
|
113
113
|
};
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
export declare function extractForeignTables(
|
|
116
|
+
export declare function extractForeignTables(pool: Pool): Promise<ForeignTable[]>;
|
|
117
117
|
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";
|
|
@@ -82,10 +83,8 @@ export class ForeignTable extends BasePgModel {
|
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
|
-
export async function extractForeignTables(
|
|
86
|
-
|
|
87
|
-
await sql `set search_path = ''`;
|
|
88
|
-
const tableRows = await sql `
|
|
86
|
+
export async function extractForeignTables(pool) {
|
|
87
|
+
const { rows: tableRows } = await pool.query(sql `
|
|
89
88
|
with extension_oids as (
|
|
90
89
|
select objid
|
|
91
90
|
from pg_depend d
|
|
@@ -191,25 +190,24 @@ export async function extractForeignTables(sql) {
|
|
|
191
190
|
group by
|
|
192
191
|
ft.oid, ft.schema, ft.name, ft.owner, ft.server, ft.options
|
|
193
192
|
order by
|
|
194
|
-
ft.schema, ft.name
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
193
|
+
ft.schema, ft.name
|
|
194
|
+
`);
|
|
195
|
+
// Validate and parse each row using the Zod schema
|
|
196
|
+
const validatedRows = tableRows.map((row) => {
|
|
197
|
+
const parsed = foreignTablePropsSchema.parse(row);
|
|
198
|
+
// Parse options from PostgreSQL format ['key=value'] to ['key', 'value']
|
|
199
|
+
if (parsed.options && parsed.options.length > 0) {
|
|
200
|
+
const parsedOptions = [];
|
|
201
|
+
for (const opt of parsed.options) {
|
|
202
|
+
const eqIndex = opt.indexOf("=");
|
|
203
|
+
if (eqIndex > 0) {
|
|
204
|
+
parsedOptions.push(opt.substring(0, eqIndex));
|
|
205
|
+
parsedOptions.push(opt.substring(eqIndex + 1));
|
|
208
206
|
}
|
|
209
|
-
parsed.options = parsedOptions.length > 0 ? parsedOptions : null;
|
|
210
207
|
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
return
|
|
208
|
+
parsed.options = parsedOptions.length > 0 ? parsedOptions : null;
|
|
209
|
+
}
|
|
210
|
+
return parsed;
|
|
214
211
|
});
|
|
212
|
+
return validatedRows.map((row) => new ForeignTable(row));
|
|
215
213
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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";
|
|
@@ -58,5 +58,5 @@ export declare class Server extends BasePgModel {
|
|
|
58
58
|
}[];
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
export declare function extractServers(
|
|
61
|
+
export declare function extractServers(pool: Pool): Promise<Server[]>;
|
|
62
62
|
export {};
|