Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pgpm/cli/src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default async (
});

const dbsResult = await selectedDb.query(`
SELECT id, name FROM collections_public.database;
SELECT id, name FROM metaschema_public.database;
`);

const { database_ids: selectedDatabaseName } = await prompter.prompt({} as any, [
Expand Down Expand Up @@ -112,7 +112,7 @@ export default async (
]);

const schemasResult = await selectedDb.query(
`SELECT * FROM collections_public.schema WHERE database_id = $1`,
`SELECT * FROM metaschema_public.schema WHERE database_id = $1`,
[dbInfo.database_ids[0]]
);

Expand Down
64 changes: 32 additions & 32 deletions pgpm/core/src/export/export-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface TableConfig {

const config: Record<string, TableConfig> = {
database: {
schema: 'collections_public',
schema: 'metaschema_public',
table: 'database',
fields: {
id: 'uuid',
Expand All @@ -22,15 +22,15 @@ const config: Record<string, TableConfig> = {
}
},
database_extension: {
schema: 'collections_public',
schema: 'metaschema_public',
table: 'database_extension',
fields: {
name: 'text',
database_id: 'uuid'
}
},
schema: {
schema: 'collections_public',
schema: 'metaschema_public',
table: 'schema',
fields: {
id: 'uuid',
Expand All @@ -41,7 +41,7 @@ const config: Record<string, TableConfig> = {
}
},
table: {
schema: 'collections_public',
schema: 'metaschema_public',
table: 'table',
fields: {
id: 'uuid',
Expand All @@ -52,7 +52,7 @@ const config: Record<string, TableConfig> = {
}
},
field: {
schema: 'collections_public',
schema: 'metaschema_public',
table: 'field',
fields: {
id: 'uuid',
Expand All @@ -64,7 +64,7 @@ const config: Record<string, TableConfig> = {
}
},
domains: {
schema: 'meta_public',
schema: 'services_public',
table: 'domains',
fields: {
id: 'uuid',
Expand All @@ -76,7 +76,7 @@ const config: Record<string, TableConfig> = {
}
},
sites: {
schema: 'meta_public',
schema: 'services_public',
table: 'sites',
fields: {
id: 'uuid',
Expand All @@ -91,7 +91,7 @@ const config: Record<string, TableConfig> = {
}
},
apis: {
schema: 'meta_public',
schema: 'services_public',
table: 'apis',
fields: {
id: 'uuid',
Expand All @@ -104,7 +104,7 @@ const config: Record<string, TableConfig> = {
}
},
apps: {
schema: 'meta_public',
schema: 'services_public',
table: 'apps',
fields: {
id: 'uuid',
Expand All @@ -119,7 +119,7 @@ const config: Record<string, TableConfig> = {
}
},
site_modules: {
schema: 'meta_public',
schema: 'services_public',
table: 'site_modules',
fields: {
id: 'uuid',
Expand All @@ -130,7 +130,7 @@ const config: Record<string, TableConfig> = {
}
},
site_themes: {
schema: 'meta_public',
schema: 'services_public',
table: 'site_themes',
fields: {
id: 'uuid',
Expand All @@ -140,7 +140,7 @@ const config: Record<string, TableConfig> = {
}
},
api_modules: {
schema: 'meta_public',
schema: 'services_public',
table: 'api_modules',
fields: {
id: 'uuid',
Expand All @@ -151,7 +151,7 @@ const config: Record<string, TableConfig> = {
}
},
api_extensions: {
schema: 'meta_public',
schema: 'services_public',
table: 'api_extensions',
fields: {
id: 'uuid',
Expand All @@ -161,7 +161,7 @@ const config: Record<string, TableConfig> = {
}
},
api_schemata: {
schema: 'meta_public',
schema: 'services_public',
table: 'api_schemata',
fields: {
id: 'uuid',
Expand All @@ -171,7 +171,7 @@ const config: Record<string, TableConfig> = {
}
},
rls_module: {
schema: 'meta_public',
schema: 'services_public',
table: 'rls_module',
fields: {
id: 'uuid',
Expand All @@ -188,7 +188,7 @@ const config: Record<string, TableConfig> = {
}
},
user_auth_module: {
schema: 'meta_public',
schema: 'services_public',
table: 'user_auth_module',
fields: {
id: 'uuid',
Expand Down Expand Up @@ -243,22 +243,22 @@ export const exportMeta = async ({ opts, dbname, database_id }: ExportMetaParams
}
};

await queryAndParse('database', `SELECT * FROM collections_public.database WHERE id = $1`);
await queryAndParse('schema', `SELECT * FROM collections_public.schema WHERE database_id = $1`);
await queryAndParse('table', `SELECT * FROM collections_public.table WHERE database_id = $1`);
await queryAndParse('field', `SELECT * FROM collections_public.field WHERE database_id = $1`);
await queryAndParse('domains', `SELECT * FROM meta_public.domains WHERE database_id = $1`);
await queryAndParse('apis', `SELECT * FROM meta_public.apis WHERE database_id = $1`);
await queryAndParse('sites', `SELECT * FROM meta_public.sites WHERE database_id = $1`);
await queryAndParse('api_modules', `SELECT * FROM meta_public.api_modules WHERE database_id = $1`);
await queryAndParse('site_modules', `SELECT * FROM meta_public.site_modules WHERE database_id = $1`);
await queryAndParse('site_themes', `SELECT * FROM meta_public.site_themes WHERE database_id = $1`);
await queryAndParse('apps', `SELECT * FROM meta_public.apps WHERE database_id = $1`);
await queryAndParse('database_extension', `SELECT * FROM collections_public.database_extension WHERE database_id = $1`);
await queryAndParse('api_extensions', `SELECT * FROM meta_public.api_extensions WHERE database_id = $1`);
await queryAndParse('api_schemata', `SELECT * FROM meta_public.api_schemata WHERE database_id = $1`);
await queryAndParse('rls_module', `SELECT * FROM meta_public.rls_module WHERE database_id = $1`);
await queryAndParse('user_auth_module', `SELECT * FROM meta_public.user_auth_module WHERE database_id = $1`);
await queryAndParse('database', `SELECT * FROM metaschema_public.database WHERE id = $1`);
await queryAndParse('schema', `SELECT * FROM metaschema_public.schema WHERE database_id = $1`);
await queryAndParse('table', `SELECT * FROM metaschema_public.table WHERE database_id = $1`);
await queryAndParse('field', `SELECT * FROM metaschema_public.field WHERE database_id = $1`);
await queryAndParse('domains', `SELECT * FROM services_public.domains WHERE database_id = $1`);
await queryAndParse('apis', `SELECT * FROM services_public.apis WHERE database_id = $1`);
await queryAndParse('sites', `SELECT * FROM services_public.sites WHERE database_id = $1`);
await queryAndParse('api_modules', `SELECT * FROM services_public.api_modules WHERE database_id = $1`);
await queryAndParse('site_modules', `SELECT * FROM services_public.site_modules WHERE database_id = $1`);
await queryAndParse('site_themes', `SELECT * FROM services_public.site_themes WHERE database_id = $1`);
await queryAndParse('apps', `SELECT * FROM services_public.apps WHERE database_id = $1`);
await queryAndParse('database_extension', `SELECT * FROM metaschema_public.database_extension WHERE database_id = $1`);
await queryAndParse('api_extensions', `SELECT * FROM services_public.api_extensions WHERE database_id = $1`);
await queryAndParse('api_schemata', `SELECT * FROM services_public.api_schemata WHERE database_id = $1`);
await queryAndParse('rls_module', `SELECT * FROM services_public.rls_module WHERE database_id = $1`);
await queryAndParse('user_auth_module', `SELECT * FROM services_public.user_auth_module WHERE database_id = $1`);

return Object.entries(sql).reduce((m, [_, v]) => m + '\n\n' + v, '');
};
12 changes: 6 additions & 6 deletions pgpm/core/src/export/export-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ const exportMigrationsToDisk = async ({
});

const db = await pgPool.query(
`select * from collections_public.database where id=$1`,
`select * from metaschema_public.database where id=$1`,
[databaseId]
);

const schemas = await pgPool.query(
`select * from collections_public.schema where database_id=$1`,
`select * from metaschema_public.schema where database_id=$1`,
[databaseId]
);

Expand Down Expand Up @@ -315,7 +315,7 @@ const exportMigrationsToDisk = async ({
deps: [],
deploy: 'migrate/meta',
content: `SET session_replication_role TO replica;
-- using replica in case we are deploying triggers to collections_public
-- using replica in case we are deploying triggers to metaschema_public

-- unaccent, postgis affected and require grants
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public to public;
Expand All @@ -334,12 +334,12 @@ ${meta}

-- TODO: Research needed - These UPDATE statements may be a security leak.
-- They appear to rebind exported metadata to the target database after import,
-- but exposing dbname in meta_public tables could leak internal database names.
-- but exposing dbname in services_public tables could leak internal database names.
-- Consider removing entirely or gating behind an explicit flag.
-- UPDATE meta_public.apis
-- UPDATE services_public.apis
-- SET dbname = current_database() WHERE TRUE;

-- UPDATE meta_public.sites
-- UPDATE services_public.sites
-- SET dbname = current_database() WHERE TRUE;

SET session_replication_role TO DEFAULT;
Expand Down
2 changes: 1 addition & 1 deletion postgres/pg-ast/src/asts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file was automatically generated by pg-proto-parser@1.30.2.
* This file was automatically generated by pg-proto-parser@1.30.4.
* DO NOT MODIFY IT BY HAND. Instead, modify the source proto file,
* and run the pg-proto-parser generate command to regenerate this file.
*/
Expand Down
2 changes: 1 addition & 1 deletion postgres/pg-ast/src/wrapped.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file was automatically generated by pg-proto-parser@1.30.2.
* This file was automatically generated by pg-proto-parser@1.30.4.
* DO NOT MODIFY IT BY HAND. Instead, modify the source proto file,
* and run the pg-proto-parser generate command to regenerate this file.
*/
Expand Down
Loading