@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
@@ -3,9 +3,10 @@
3
3
  */
4
4
  import type { IntegrationDSL } from "../../core/integrations/integration-dsl.ts";
5
5
  /**
6
- * Load an integration DSL from a JSON file.
7
- * If the path ends with .json, treats it as a file path directly.
8
- * Otherwise, tries to load from core/integrations/ first, then falls back to treating as a file path.
6
+ * Load an integration DSL from a file or core integration.
7
+ * If the path ends with .json, treats it as a JSON file path directly.
8
+ * Otherwise, tries to load from core integrations (TypeScript) first,
9
+ * then falls back to treating as a JSON file path.
9
10
  *
10
11
  * @param nameOrPath - Integration name (e.g., "supabase") or file path (e.g., "./my-integration.json")
11
12
  * @returns The loaded IntegrationDSL
@@ -1,35 +1,44 @@
1
1
  /**
2
2
  * Utilities for loading integrations from files.
3
3
  */
4
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
5
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
6
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
7
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
8
+ });
9
+ }
10
+ return path;
11
+ };
4
12
  import { readFile } from "node:fs/promises";
5
- import { dirname, join } from "node:path";
6
- import { fileURLToPath } from "node:url";
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
13
  /**
10
- * Load an integration DSL from a JSON file.
11
- * If the path ends with .json, treats it as a file path directly.
12
- * Otherwise, tries to load from core/integrations/ first, then falls back to treating as a file path.
14
+ * Load an integration DSL from a file or core integration.
15
+ * If the path ends with .json, treats it as a JSON file path directly.
16
+ * Otherwise, tries to load from core integrations (TypeScript) first,
17
+ * then falls back to treating as a JSON file path.
13
18
  *
14
19
  * @param nameOrPath - Integration name (e.g., "supabase") or file path (e.g., "./my-integration.json")
15
20
  * @returns The loaded IntegrationDSL
16
21
  */
17
22
  export async function loadIntegrationDSL(nameOrPath) {
18
- // If path ends with .json, treat it as a file path directly
23
+ // If path ends with .json, treat it as a JSON file path directly
19
24
  if (nameOrPath.endsWith(".json")) {
20
25
  const content = await readFile(nameOrPath, "utf-8");
21
26
  return JSON.parse(content);
22
27
  }
23
- // Try loading from core/integrations/ first
24
- // __dirname is src/cli/utils, so we go up to src/ then into core/integrations
25
- const coreIntegrationsPath = join(__dirname, "../../core/integrations", `${nameOrPath}.json`);
28
+ // Try loading from core integrations (TypeScript) first
26
29
  try {
27
- const content = await readFile(coreIntegrationsPath, "utf-8");
28
- return JSON.parse(content);
30
+ const module = await import(__rewriteRelativeImportExtension(`../../core/integrations/${nameOrPath}.ts`));
31
+ // Core integrations export using the integration name directly (e.g., "supabase")
32
+ const integrationName = nameOrPath;
33
+ if (integrationName in module) {
34
+ return module[integrationName];
35
+ }
36
+ // If no matching export, fall through to JSON file loading
29
37
  }
30
38
  catch {
31
- // Fallback to treating as file path
32
- const content = await readFile(nameOrPath, "utf-8");
33
- return JSON.parse(content);
39
+ // Module not found or not a core integration, fall through to JSON file loading
34
40
  }
41
+ // Fallback to treating as JSON file path
42
+ const content = await readFile(nameOrPath, "utf-8");
43
+ return JSON.parse(content);
35
44
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
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(sql: Sql): Promise<Catalog>;
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(sql) {
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(sql).then(listToRecord),
94
- extractCollations(sql).then(listToRecord),
95
- extractCompositeTypes(sql).then(listToRecord),
96
- extractDomains(sql).then(listToRecord),
97
- extractEnums(sql).then(listToRecord),
98
- extractExtensions(sql).then(listToRecord),
99
- extractIndexes(sql).then(listToRecord),
100
- extractMaterializedViews(sql).then(listToRecord),
101
- extractSubscriptions(sql).then(listToRecord),
102
- extractPublications(sql).then(listToRecord),
103
- extractProcedures(sql).then(listToRecord),
104
- extractRlsPolicies(sql).then(listToRecord),
105
- extractRoles(sql).then(listToRecord),
106
- extractSchemas(sql).then(listToRecord),
107
- extractSequences(sql).then(listToRecord),
108
- extractTables(sql).then(listToRecord),
109
- extractTriggers(sql).then(listToRecord),
110
- extractEventTriggers(sql).then(listToRecord),
111
- extractRules(sql).then(listToRecord),
112
- extractRanges(sql).then(listToRecord),
113
- extractViews(sql).then(listToRecord),
114
- extractForeignDataWrappers(sql).then(listToRecord),
115
- extractServers(sql).then(listToRecord),
116
- extractUserMappings(sql).then(listToRecord),
117
- extractForeignTables(sql).then(listToRecord),
118
- extractDepends(sql),
119
- extractVersion(sql),
120
- extractCurrentUser(sql),
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,
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
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(sql: Sql): Promise<number>;
11
- export declare function extractCurrentUser(sql: Sql): Promise<string>;
10
+ export declare function extractVersion(pool: Pool): Promise<number>;
11
+ export declare function extractCurrentUser(pool: Pool): Promise<string>;
@@ -1,12 +1,9 @@
1
- export async function extractVersion(sql) {
2
- const [{ version }] = await sql `
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(sql) {
8
- const [{ current_user }] = await sql `
9
- select quote_ident(current_user) as current_user;
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
  }
@@ -1,4 +1,4 @@
1
- import type { Sql } from "postgres";
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(sql: Sql): Promise<PgDepend[]>;
30
+ export declare function extractDepends(pool: Pool): Promise<PgDepend[]>;
31
31
  export {};
@@ -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(sql) {
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(sql) {
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(sql);
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) ||
@@ -13,11 +13,3 @@ export declare function buildPlanScopeFingerprint(catalog: Catalog, changes: Cha
13
13
  * Compute a fingerprint from a catalog and a set of stableIds.
14
14
  */
15
15
  export declare function hashStableIds(catalog: Catalog, stableIds: string[]): string;
16
- /**
17
- * Hash a string to hex SHA256.
18
- */
19
- export declare function sha256(input: string): string;
20
- /**
21
- * Collect the union of stableIds referenced by all changes.
22
- */
23
- export declare function collectStableIds(changes: Change[]): string[];
@@ -31,13 +31,13 @@ export function hashStableIds(catalog, stableIds) {
31
31
  /**
32
32
  * Hash a string to hex SHA256.
33
33
  */
34
- export function sha256(input) {
34
+ function sha256(input) {
35
35
  return crypto.createHash("sha256").update(input).digest("hex");
36
36
  }
37
37
  /**
38
38
  * Collect the union of stableIds referenced by all changes.
39
39
  */
40
- export function collectStableIds(changes) {
40
+ function collectStableIds(changes) {
41
41
  const ids = new Set();
42
42
  for (const change of changes) {
43
43
  for (const id of getChangeStableIds(change)) {
@@ -2,7 +2,7 @@
2
2
  * Filter DSL - A serializable domain-specific language for change filtering.
3
3
  */
4
4
  import type { Change } from "../../change.types.ts";
5
- import type { ChangeFilter } from "../../main.ts";
5
+ import type { ChangeFilter } from "./filter.types.ts";
6
6
  /**
7
7
  * Core properties that all changes have.
8
8
  */
@@ -0,0 +1,2 @@
1
+ import type { Change } from "../../change.types.ts";
2
+ export type ChangeFilter = (change: Change) => boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
- import type { ChangeFilter, ChangeSerializer } from "../main.ts";
1
+ import type { ChangeFilter } from "./filter/filter.types.ts";
2
+ import type { ChangeSerializer } from "./serialize/serialize.types.ts";
2
3
  export type Integration = {
3
4
  filter?: ChangeFilter;
4
5
  serialize?: ChangeSerializer;
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * Reuses the filter pattern matching logic to determine when to apply serialization options.
5
5
  */
6
- import type { ChangeSerializer } from "../../main.ts";
7
6
  import { type FilterPattern } from "../filter/dsl.ts";
7
+ import type { ChangeSerializer } from "./serialize.types.ts";
8
8
  /**
9
9
  * Serialization options that can be passed to change.serialize().
10
10
  */
@@ -0,0 +1,2 @@
1
+ import type { Change } from "../../change.types.ts";
2
+ export type ChangeSerializer = (change: Change) => string | undefined;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Supabase integration - filtering and serialization rules for Supabase databases.
3
+ *
4
+ * This integration:
5
+ * - Filters out Supabase system schemas and roles
6
+ * - Includes user schemas and extensions
7
+ * - Skips authorization for schema creates owned by Supabase system roles
8
+ */
9
+ import type { IntegrationDSL } from "./integration-dsl.ts";
10
+ export declare const supabase: IntegrationDSL;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Supabase integration - filtering and serialization rules for Supabase databases.
3
+ *
4
+ * This integration:
5
+ * - Filters out Supabase system schemas and roles
6
+ * - Includes user schemas and extensions
7
+ * - Skips authorization for schema creates owned by Supabase system roles
8
+ */
9
+ // Supabase system schemas that should be excluded
10
+ const SUPABASE_SYSTEM_SCHEMAS = [
11
+ "_analytics",
12
+ "_realtime",
13
+ "_supavisor",
14
+ "auth",
15
+ "cron",
16
+ "extensions",
17
+ "graphql",
18
+ "graphql_public",
19
+ "information_schema",
20
+ "net",
21
+ "pgbouncer",
22
+ "pgmq",
23
+ "pgmq_public",
24
+ "pgsodium",
25
+ "pgsodium_masks",
26
+ "pgtle",
27
+ "realtime",
28
+ "storage",
29
+ "supabase_functions",
30
+ "supabase_migrations",
31
+ "vault",
32
+ ];
33
+ // Supabase system roles that should be excluded
34
+ const SUPABASE_SYSTEM_ROLES = [
35
+ "anon",
36
+ "authenticated",
37
+ "authenticator",
38
+ "dashboard_user",
39
+ "pgbouncer",
40
+ "pgsodium_keyholder",
41
+ "pgsodium_keyiduser",
42
+ "pgsodium_keymaker",
43
+ "pgtle_admin",
44
+ "service_role",
45
+ "supabase_admin",
46
+ "supabase_auth_admin",
47
+ "supabase_etl_admin",
48
+ "supabase_functions_admin",
49
+ "supabase_read_only_user",
50
+ "supabase_realtime_admin",
51
+ "supabase_replication_admin",
52
+ "supabase_storage_admin",
53
+ ];
54
+ export const supabase = {
55
+ filter: {
56
+ or: [
57
+ {
58
+ and: [
59
+ {
60
+ type: "schema",
61
+ operation: "create",
62
+ scope: "object",
63
+ },
64
+ {
65
+ not: {
66
+ schema: [...SUPABASE_SYSTEM_SCHEMAS],
67
+ },
68
+ },
69
+ ],
70
+ },
71
+ {
72
+ type: "extension",
73
+ operation: "create",
74
+ scope: "object",
75
+ },
76
+ {
77
+ not: {
78
+ or: [
79
+ {
80
+ schema: [...SUPABASE_SYSTEM_SCHEMAS],
81
+ },
82
+ {
83
+ owner: [...SUPABASE_SYSTEM_ROLES],
84
+ },
85
+ {
86
+ and: [
87
+ {
88
+ type: "role",
89
+ scope: "membership",
90
+ },
91
+ {
92
+ member: [...SUPABASE_SYSTEM_ROLES],
93
+ },
94
+ ],
95
+ },
96
+ ],
97
+ },
98
+ },
99
+ ],
100
+ },
101
+ serialize: [
102
+ {
103
+ when: {
104
+ type: "schema",
105
+ operation: "create",
106
+ scope: "object",
107
+ owner: [...SUPABASE_SYSTEM_ROLES],
108
+ },
109
+ options: {
110
+ skipAuthorization: true,
111
+ },
112
+ },
113
+ ],
114
+ };
@@ -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";
@@ -16,9 +16,9 @@ declare const aggregatePropsSchema: z.ZodObject<{
16
16
  return_type: z.ZodString;
17
17
  return_type_schema: z.ZodNullable<z.ZodString>;
18
18
  parallel_safety: z.ZodEnum<{
19
+ r: "r";
19
20
  u: "u";
20
21
  s: "s";
21
- r: "r";
22
22
  }>;
23
23
  is_strict: z.ZodBoolean;
24
24
  transition_function: z.ZodString;
@@ -28,8 +28,8 @@ declare const aggregatePropsSchema: z.ZodObject<{
28
28
  final_function: z.ZodNullable<z.ZodString>;
29
29
  final_function_extra_args: z.ZodBoolean;
30
30
  final_function_modify: z.ZodNullable<z.ZodEnum<{
31
- s: "s";
32
31
  r: "r";
32
+ s: "s";
33
33
  w: "w";
34
34
  }>>;
35
35
  combine_function: z.ZodNullable<z.ZodString>;
@@ -44,8 +44,8 @@ declare const aggregatePropsSchema: z.ZodObject<{
44
44
  moving_final_function: z.ZodNullable<z.ZodString>;
45
45
  moving_final_function_extra_args: z.ZodBoolean;
46
46
  moving_final_function_modify: z.ZodNullable<z.ZodEnum<{
47
- s: "s";
48
47
  r: "r";
48
+ s: "s";
49
49
  w: "w";
50
50
  }>>;
51
51
  moving_initial_condition: z.ZodNullable<z.ZodString>;
@@ -56,8 +56,8 @@ declare const aggregatePropsSchema: z.ZodObject<{
56
56
  argument_types: z.ZodNullable<z.ZodArray<z.ZodString>>;
57
57
  all_argument_types: z.ZodNullable<z.ZodArray<z.ZodString>>;
58
58
  argument_modes: z.ZodNullable<z.ZodArray<z.ZodEnum<{
59
- i: "i";
60
59
  o: "o";
60
+ i: "i";
61
61
  b: "b";
62
62
  v: "v";
63
63
  t: "t";
@@ -129,7 +129,7 @@ export declare class Aggregate extends BasePgModel {
129
129
  num_direct_args: number;
130
130
  return_type: string;
131
131
  return_type_schema: string | null;
132
- parallel_safety: "u" | "s" | "r";
132
+ parallel_safety: "r" | "u" | "s";
133
133
  is_strict: boolean;
134
134
  transition_function: string;
135
135
  state_data_type: string;
@@ -137,7 +137,7 @@ export declare class Aggregate extends BasePgModel {
137
137
  state_data_space: number;
138
138
  final_function: string | null;
139
139
  final_function_extra_args: boolean;
140
- final_function_modify: "s" | "r" | "w" | null;
140
+ final_function_modify: "r" | "s" | "w" | null;
141
141
  combine_function: string | null;
142
142
  serial_function: string | null;
143
143
  deserial_function: string | null;
@@ -149,7 +149,7 @@ export declare class Aggregate extends BasePgModel {
149
149
  moving_state_data_space: number | null;
150
150
  moving_final_function: string | null;
151
151
  moving_final_function_extra_args: boolean;
152
- moving_final_function_modify: "s" | "r" | "w" | null;
152
+ moving_final_function_modify: "r" | "s" | "w" | null;
153
153
  moving_initial_condition: string | null;
154
154
  sort_operator: string | null;
155
155
  argument_count: number;
@@ -157,7 +157,7 @@ export declare class Aggregate extends BasePgModel {
157
157
  argument_names: string[] | null;
158
158
  argument_types: string[] | null;
159
159
  all_argument_types: string[] | null;
160
- argument_modes: ("i" | "o" | "b" | "v" | "t")[] | null;
160
+ argument_modes: ("o" | "i" | "b" | "v" | "t")[] | null;
161
161
  argument_defaults: string | null;
162
162
  identity_arguments: string;
163
163
  owner: string;
@@ -170,5 +170,5 @@ export declare class Aggregate extends BasePgModel {
170
170
  }[];
171
171
  };
172
172
  }
173
- export declare function extractAggregates(sql: Sql): Promise<Aggregate[]>;
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(sql) {
212
- return sql.begin(async (sql) => {
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
- const validatedRows = aggregateRows.map((row) => aggregatePropsSchema.parse(row));
295
- return validatedRows.map((row) => new Aggregate(row));
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 { 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
  /**
@@ -63,5 +63,5 @@ export declare class Collation extends BasePgModel {
63
63
  comment: string | null;
64
64
  };
65
65
  }
66
- export declare function extractCollations(sql: Sql): Promise<Collation[]>;
66
+ export declare function extractCollations(pool: Pool): Promise<Collation[]>;
67
67
  export {};