@pgpmjs/core 4.7.0 → 4.7.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.
|
@@ -2,7 +2,7 @@ import { Parser } from 'csv-to-pg';
|
|
|
2
2
|
import { getPgPool } from 'pg-cache';
|
|
3
3
|
const config = {
|
|
4
4
|
database: {
|
|
5
|
-
schema: '
|
|
5
|
+
schema: 'metaschema_public',
|
|
6
6
|
table: 'database',
|
|
7
7
|
fields: {
|
|
8
8
|
id: 'uuid',
|
|
@@ -12,7 +12,7 @@ const config = {
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
database_extension: {
|
|
15
|
-
schema: '
|
|
15
|
+
schema: 'metaschema_public',
|
|
16
16
|
table: 'database_extension',
|
|
17
17
|
fields: {
|
|
18
18
|
name: 'text',
|
|
@@ -20,7 +20,7 @@ const config = {
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
schema: {
|
|
23
|
-
schema: '
|
|
23
|
+
schema: 'metaschema_public',
|
|
24
24
|
table: 'schema',
|
|
25
25
|
fields: {
|
|
26
26
|
id: 'uuid',
|
|
@@ -31,7 +31,7 @@ const config = {
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
table: {
|
|
34
|
-
schema: '
|
|
34
|
+
schema: 'metaschema_public',
|
|
35
35
|
table: 'table',
|
|
36
36
|
fields: {
|
|
37
37
|
id: 'uuid',
|
|
@@ -42,7 +42,7 @@ const config = {
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
field: {
|
|
45
|
-
schema: '
|
|
45
|
+
schema: 'metaschema_public',
|
|
46
46
|
table: 'field',
|
|
47
47
|
fields: {
|
|
48
48
|
id: 'uuid',
|
|
@@ -54,7 +54,7 @@ const config = {
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
domains: {
|
|
57
|
-
schema: '
|
|
57
|
+
schema: 'services_public',
|
|
58
58
|
table: 'domains',
|
|
59
59
|
fields: {
|
|
60
60
|
id: 'uuid',
|
|
@@ -66,7 +66,7 @@ const config = {
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
sites: {
|
|
69
|
-
schema: '
|
|
69
|
+
schema: 'services_public',
|
|
70
70
|
table: 'sites',
|
|
71
71
|
fields: {
|
|
72
72
|
id: 'uuid',
|
|
@@ -81,7 +81,7 @@ const config = {
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
apis: {
|
|
84
|
-
schema: '
|
|
84
|
+
schema: 'services_public',
|
|
85
85
|
table: 'apis',
|
|
86
86
|
fields: {
|
|
87
87
|
id: 'uuid',
|
|
@@ -94,7 +94,7 @@ const config = {
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
apps: {
|
|
97
|
-
schema: '
|
|
97
|
+
schema: 'services_public',
|
|
98
98
|
table: 'apps',
|
|
99
99
|
fields: {
|
|
100
100
|
id: 'uuid',
|
|
@@ -109,7 +109,7 @@ const config = {
|
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
site_modules: {
|
|
112
|
-
schema: '
|
|
112
|
+
schema: 'services_public',
|
|
113
113
|
table: 'site_modules',
|
|
114
114
|
fields: {
|
|
115
115
|
id: 'uuid',
|
|
@@ -120,7 +120,7 @@ const config = {
|
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
122
|
site_themes: {
|
|
123
|
-
schema: '
|
|
123
|
+
schema: 'services_public',
|
|
124
124
|
table: 'site_themes',
|
|
125
125
|
fields: {
|
|
126
126
|
id: 'uuid',
|
|
@@ -130,7 +130,7 @@ const config = {
|
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
132
|
api_modules: {
|
|
133
|
-
schema: '
|
|
133
|
+
schema: 'services_public',
|
|
134
134
|
table: 'api_modules',
|
|
135
135
|
fields: {
|
|
136
136
|
id: 'uuid',
|
|
@@ -141,7 +141,7 @@ const config = {
|
|
|
141
141
|
}
|
|
142
142
|
},
|
|
143
143
|
api_extensions: {
|
|
144
|
-
schema: '
|
|
144
|
+
schema: 'services_public',
|
|
145
145
|
table: 'api_extensions',
|
|
146
146
|
fields: {
|
|
147
147
|
id: 'uuid',
|
|
@@ -151,7 +151,7 @@ const config = {
|
|
|
151
151
|
}
|
|
152
152
|
},
|
|
153
153
|
api_schemata: {
|
|
154
|
-
schema: '
|
|
154
|
+
schema: 'services_public',
|
|
155
155
|
table: 'api_schemata',
|
|
156
156
|
fields: {
|
|
157
157
|
id: 'uuid',
|
|
@@ -161,7 +161,7 @@ const config = {
|
|
|
161
161
|
}
|
|
162
162
|
},
|
|
163
163
|
rls_module: {
|
|
164
|
-
schema: '
|
|
164
|
+
schema: 'metaschema_modules_public',
|
|
165
165
|
table: 'rls_module',
|
|
166
166
|
fields: {
|
|
167
167
|
id: 'uuid',
|
|
@@ -178,7 +178,7 @@ const config = {
|
|
|
178
178
|
}
|
|
179
179
|
},
|
|
180
180
|
user_auth_module: {
|
|
181
|
-
schema: '
|
|
181
|
+
schema: 'metaschema_modules_public',
|
|
182
182
|
table: 'user_auth_module',
|
|
183
183
|
fields: {
|
|
184
184
|
id: 'uuid',
|
|
@@ -224,21 +224,21 @@ export const exportMeta = async ({ opts, dbname, database_id }) => {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
};
|
|
227
|
-
await queryAndParse('database', `SELECT * FROM
|
|
228
|
-
await queryAndParse('schema', `SELECT * FROM
|
|
229
|
-
await queryAndParse('table', `SELECT * FROM
|
|
230
|
-
await queryAndParse('field', `SELECT * FROM
|
|
231
|
-
await queryAndParse('domains', `SELECT * FROM
|
|
232
|
-
await queryAndParse('apis', `SELECT * FROM
|
|
233
|
-
await queryAndParse('sites', `SELECT * FROM
|
|
234
|
-
await queryAndParse('api_modules', `SELECT * FROM
|
|
235
|
-
await queryAndParse('site_modules', `SELECT * FROM
|
|
236
|
-
await queryAndParse('site_themes', `SELECT * FROM
|
|
237
|
-
await queryAndParse('apps', `SELECT * FROM
|
|
238
|
-
await queryAndParse('database_extension', `SELECT * FROM
|
|
239
|
-
await queryAndParse('api_extensions', `SELECT * FROM
|
|
240
|
-
await queryAndParse('api_schemata', `SELECT * FROM
|
|
241
|
-
await queryAndParse('rls_module', `SELECT * FROM
|
|
242
|
-
await queryAndParse('user_auth_module', `SELECT * FROM
|
|
227
|
+
await queryAndParse('database', `SELECT * FROM metaschema_public.database WHERE id = $1`);
|
|
228
|
+
await queryAndParse('schema', `SELECT * FROM metaschema_public.schema WHERE database_id = $1`);
|
|
229
|
+
await queryAndParse('table', `SELECT * FROM metaschema_public.table WHERE database_id = $1`);
|
|
230
|
+
await queryAndParse('field', `SELECT * FROM metaschema_public.field WHERE database_id = $1`);
|
|
231
|
+
await queryAndParse('domains', `SELECT * FROM services_public.domains WHERE database_id = $1`);
|
|
232
|
+
await queryAndParse('apis', `SELECT * FROM services_public.apis WHERE database_id = $1`);
|
|
233
|
+
await queryAndParse('sites', `SELECT * FROM services_public.sites WHERE database_id = $1`);
|
|
234
|
+
await queryAndParse('api_modules', `SELECT * FROM services_public.api_modules WHERE database_id = $1`);
|
|
235
|
+
await queryAndParse('site_modules', `SELECT * FROM services_public.site_modules WHERE database_id = $1`);
|
|
236
|
+
await queryAndParse('site_themes', `SELECT * FROM services_public.site_themes WHERE database_id = $1`);
|
|
237
|
+
await queryAndParse('apps', `SELECT * FROM services_public.apps WHERE database_id = $1`);
|
|
238
|
+
await queryAndParse('database_extension', `SELECT * FROM metaschema_public.database_extension WHERE database_id = $1`);
|
|
239
|
+
await queryAndParse('api_extensions', `SELECT * FROM services_public.api_extensions WHERE database_id = $1`);
|
|
240
|
+
await queryAndParse('api_schemata', `SELECT * FROM services_public.api_schemata WHERE database_id = $1`);
|
|
241
|
+
await queryAndParse('rls_module', `SELECT * FROM metaschema_modules_public.rls_module WHERE database_id = $1`);
|
|
242
|
+
await queryAndParse('user_auth_module', `SELECT * FROM metaschema_modules_public.user_auth_module WHERE database_id = $1`);
|
|
243
243
|
return Object.entries(sql).reduce((m, [_, v]) => m + '\n\n' + v, '');
|
|
244
244
|
};
|
|
@@ -100,8 +100,8 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
100
100
|
...options.pg,
|
|
101
101
|
database
|
|
102
102
|
});
|
|
103
|
-
const db = await pgPool.query(`select * from
|
|
104
|
-
const schemas = await pgPool.query(`select * from
|
|
103
|
+
const db = await pgPool.query(`select * from metaschema_public.database where id=$1`, [databaseId]);
|
|
104
|
+
const schemas = await pgPool.query(`select * from metaschema_public.schema where database_id=$1`, [databaseId]);
|
|
105
105
|
if (!db?.rows?.length) {
|
|
106
106
|
console.log('NO DATABASES.');
|
|
107
107
|
return;
|
|
@@ -180,7 +180,7 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
180
180
|
deps: [],
|
|
181
181
|
deploy: 'migrate/meta',
|
|
182
182
|
content: `SET session_replication_role TO replica;
|
|
183
|
-
-- using replica in case we are deploying triggers to
|
|
183
|
+
-- using replica in case we are deploying triggers to metaschema_public
|
|
184
184
|
|
|
185
185
|
-- unaccent, postgis affected and require grants
|
|
186
186
|
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public to public;
|
|
@@ -199,12 +199,12 @@ ${meta}
|
|
|
199
199
|
|
|
200
200
|
-- TODO: Research needed - These UPDATE statements may be a security leak.
|
|
201
201
|
-- They appear to rebind exported metadata to the target database after import,
|
|
202
|
-
-- but exposing dbname in
|
|
202
|
+
-- but exposing dbname in services_public tables could leak internal database names.
|
|
203
203
|
-- Consider removing entirely or gating behind an explicit flag.
|
|
204
|
-
-- UPDATE
|
|
204
|
+
-- UPDATE services_public.apis
|
|
205
205
|
-- SET dbname = current_database() WHERE TRUE;
|
|
206
206
|
|
|
207
|
-
-- UPDATE
|
|
207
|
+
-- UPDATE services_public.sites
|
|
208
208
|
-- SET dbname = current_database() WHERE TRUE;
|
|
209
209
|
|
|
210
210
|
SET session_replication_role TO DEFAULT;
|
|
@@ -53,17 +53,6 @@ CREATE PROCEDURE pgpm_migrate.deploy(
|
|
|
53
53
|
LANGUAGE plpgsql AS $$
|
|
54
54
|
DECLARE
|
|
55
55
|
v_change_id TEXT;
|
|
56
|
-
-- Error diagnostic variables
|
|
57
|
-
v_sqlstate TEXT;
|
|
58
|
-
v_message TEXT;
|
|
59
|
-
v_detail TEXT;
|
|
60
|
-
v_hint TEXT;
|
|
61
|
-
v_context TEXT;
|
|
62
|
-
v_schema_name TEXT;
|
|
63
|
-
v_table_name TEXT;
|
|
64
|
-
v_column_name TEXT;
|
|
65
|
-
v_constraint_name TEXT;
|
|
66
|
-
v_datatype_name TEXT;
|
|
67
56
|
BEGIN
|
|
68
57
|
-- Ensure package exists
|
|
69
58
|
CALL pgpm_migrate.register_package(p_package);
|
|
@@ -108,30 +97,8 @@ BEGIN
|
|
|
108
97
|
BEGIN
|
|
109
98
|
EXECUTE p_deploy_sql;
|
|
110
99
|
EXCEPTION WHEN OTHERS THEN
|
|
111
|
-
--
|
|
112
|
-
|
|
113
|
-
v_sqlstate = RETURNED_SQLSTATE,
|
|
114
|
-
v_message = MESSAGE_TEXT,
|
|
115
|
-
v_detail = PG_EXCEPTION_DETAIL,
|
|
116
|
-
v_hint = PG_EXCEPTION_HINT,
|
|
117
|
-
v_context = PG_EXCEPTION_CONTEXT,
|
|
118
|
-
v_schema_name = SCHEMA_NAME,
|
|
119
|
-
v_table_name = TABLE_NAME,
|
|
120
|
-
v_column_name = COLUMN_NAME,
|
|
121
|
-
v_constraint_name = CONSTRAINT_NAME,
|
|
122
|
-
v_datatype_name = PG_DATATYPE_NAME;
|
|
123
|
-
|
|
124
|
-
-- Re-raise with all captured diagnostics preserved
|
|
125
|
-
RAISE EXCEPTION USING
|
|
126
|
-
ERRCODE = v_sqlstate,
|
|
127
|
-
MESSAGE = v_message,
|
|
128
|
-
DETAIL = v_detail,
|
|
129
|
-
HINT = v_hint,
|
|
130
|
-
SCHEMA = v_schema_name,
|
|
131
|
-
TABLE = v_table_name,
|
|
132
|
-
COLUMN = v_column_name,
|
|
133
|
-
CONSTRAINT = v_constraint_name,
|
|
134
|
-
DATATYPE = v_datatype_name;
|
|
100
|
+
-- Re-raise the original exception to preserve full context including SQL statement
|
|
101
|
+
RAISE;
|
|
135
102
|
END;
|
|
136
103
|
END IF;
|
|
137
104
|
|
|
@@ -158,18 +125,6 @@ CREATE PROCEDURE pgpm_migrate.revert(
|
|
|
158
125
|
p_revert_sql TEXT
|
|
159
126
|
)
|
|
160
127
|
LANGUAGE plpgsql AS $$
|
|
161
|
-
DECLARE
|
|
162
|
-
-- Error diagnostic variables
|
|
163
|
-
v_sqlstate TEXT;
|
|
164
|
-
v_message TEXT;
|
|
165
|
-
v_detail TEXT;
|
|
166
|
-
v_hint TEXT;
|
|
167
|
-
v_context TEXT;
|
|
168
|
-
v_schema_name TEXT;
|
|
169
|
-
v_table_name TEXT;
|
|
170
|
-
v_column_name TEXT;
|
|
171
|
-
v_constraint_name TEXT;
|
|
172
|
-
v_datatype_name TEXT;
|
|
173
128
|
BEGIN
|
|
174
129
|
-- Check if deployed
|
|
175
130
|
IF NOT pgpm_migrate.is_deployed(p_package, p_change_name) THEN
|
|
@@ -211,34 +166,12 @@ BEGIN
|
|
|
211
166
|
END;
|
|
212
167
|
END IF;
|
|
213
168
|
|
|
214
|
-
-- Execute revert
|
|
169
|
+
-- Execute revert
|
|
215
170
|
BEGIN
|
|
216
171
|
EXECUTE p_revert_sql;
|
|
217
172
|
EXCEPTION WHEN OTHERS THEN
|
|
218
|
-
--
|
|
219
|
-
|
|
220
|
-
v_sqlstate = RETURNED_SQLSTATE,
|
|
221
|
-
v_message = MESSAGE_TEXT,
|
|
222
|
-
v_detail = PG_EXCEPTION_DETAIL,
|
|
223
|
-
v_hint = PG_EXCEPTION_HINT,
|
|
224
|
-
v_context = PG_EXCEPTION_CONTEXT,
|
|
225
|
-
v_schema_name = SCHEMA_NAME,
|
|
226
|
-
v_table_name = TABLE_NAME,
|
|
227
|
-
v_column_name = COLUMN_NAME,
|
|
228
|
-
v_constraint_name = CONSTRAINT_NAME,
|
|
229
|
-
v_datatype_name = PG_DATATYPE_NAME;
|
|
230
|
-
|
|
231
|
-
-- Re-raise with all captured diagnostics preserved
|
|
232
|
-
RAISE EXCEPTION USING
|
|
233
|
-
ERRCODE = v_sqlstate,
|
|
234
|
-
MESSAGE = v_message,
|
|
235
|
-
DETAIL = v_detail,
|
|
236
|
-
HINT = v_hint,
|
|
237
|
-
SCHEMA = v_schema_name,
|
|
238
|
-
TABLE = v_table_name,
|
|
239
|
-
COLUMN = v_column_name,
|
|
240
|
-
CONSTRAINT = v_constraint_name,
|
|
241
|
-
DATATYPE = v_datatype_name;
|
|
173
|
+
-- Re-raise the original exception to preserve full context including SQL statement
|
|
174
|
+
RAISE;
|
|
242
175
|
END;
|
|
243
176
|
|
|
244
177
|
-- Remove from deployed
|
package/export/export-meta.js
CHANGED
|
@@ -5,7 +5,7 @@ const csv_to_pg_1 = require("csv-to-pg");
|
|
|
5
5
|
const pg_cache_1 = require("pg-cache");
|
|
6
6
|
const config = {
|
|
7
7
|
database: {
|
|
8
|
-
schema: '
|
|
8
|
+
schema: 'metaschema_public',
|
|
9
9
|
table: 'database',
|
|
10
10
|
fields: {
|
|
11
11
|
id: 'uuid',
|
|
@@ -15,7 +15,7 @@ const config = {
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
database_extension: {
|
|
18
|
-
schema: '
|
|
18
|
+
schema: 'metaschema_public',
|
|
19
19
|
table: 'database_extension',
|
|
20
20
|
fields: {
|
|
21
21
|
name: 'text',
|
|
@@ -23,7 +23,7 @@ const config = {
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
schema: {
|
|
26
|
-
schema: '
|
|
26
|
+
schema: 'metaschema_public',
|
|
27
27
|
table: 'schema',
|
|
28
28
|
fields: {
|
|
29
29
|
id: 'uuid',
|
|
@@ -34,7 +34,7 @@ const config = {
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
table: {
|
|
37
|
-
schema: '
|
|
37
|
+
schema: 'metaschema_public',
|
|
38
38
|
table: 'table',
|
|
39
39
|
fields: {
|
|
40
40
|
id: 'uuid',
|
|
@@ -45,7 +45,7 @@ const config = {
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
field: {
|
|
48
|
-
schema: '
|
|
48
|
+
schema: 'metaschema_public',
|
|
49
49
|
table: 'field',
|
|
50
50
|
fields: {
|
|
51
51
|
id: 'uuid',
|
|
@@ -57,7 +57,7 @@ const config = {
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
domains: {
|
|
60
|
-
schema: '
|
|
60
|
+
schema: 'services_public',
|
|
61
61
|
table: 'domains',
|
|
62
62
|
fields: {
|
|
63
63
|
id: 'uuid',
|
|
@@ -69,7 +69,7 @@ const config = {
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
sites: {
|
|
72
|
-
schema: '
|
|
72
|
+
schema: 'services_public',
|
|
73
73
|
table: 'sites',
|
|
74
74
|
fields: {
|
|
75
75
|
id: 'uuid',
|
|
@@ -84,7 +84,7 @@ const config = {
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
apis: {
|
|
87
|
-
schema: '
|
|
87
|
+
schema: 'services_public',
|
|
88
88
|
table: 'apis',
|
|
89
89
|
fields: {
|
|
90
90
|
id: 'uuid',
|
|
@@ -97,7 +97,7 @@ const config = {
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
apps: {
|
|
100
|
-
schema: '
|
|
100
|
+
schema: 'services_public',
|
|
101
101
|
table: 'apps',
|
|
102
102
|
fields: {
|
|
103
103
|
id: 'uuid',
|
|
@@ -112,7 +112,7 @@ const config = {
|
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
114
|
site_modules: {
|
|
115
|
-
schema: '
|
|
115
|
+
schema: 'services_public',
|
|
116
116
|
table: 'site_modules',
|
|
117
117
|
fields: {
|
|
118
118
|
id: 'uuid',
|
|
@@ -123,7 +123,7 @@ const config = {
|
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
site_themes: {
|
|
126
|
-
schema: '
|
|
126
|
+
schema: 'services_public',
|
|
127
127
|
table: 'site_themes',
|
|
128
128
|
fields: {
|
|
129
129
|
id: 'uuid',
|
|
@@ -133,7 +133,7 @@ const config = {
|
|
|
133
133
|
}
|
|
134
134
|
},
|
|
135
135
|
api_modules: {
|
|
136
|
-
schema: '
|
|
136
|
+
schema: 'services_public',
|
|
137
137
|
table: 'api_modules',
|
|
138
138
|
fields: {
|
|
139
139
|
id: 'uuid',
|
|
@@ -144,7 +144,7 @@ const config = {
|
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
146
|
api_extensions: {
|
|
147
|
-
schema: '
|
|
147
|
+
schema: 'services_public',
|
|
148
148
|
table: 'api_extensions',
|
|
149
149
|
fields: {
|
|
150
150
|
id: 'uuid',
|
|
@@ -154,7 +154,7 @@ const config = {
|
|
|
154
154
|
}
|
|
155
155
|
},
|
|
156
156
|
api_schemata: {
|
|
157
|
-
schema: '
|
|
157
|
+
schema: 'services_public',
|
|
158
158
|
table: 'api_schemata',
|
|
159
159
|
fields: {
|
|
160
160
|
id: 'uuid',
|
|
@@ -164,7 +164,7 @@ const config = {
|
|
|
164
164
|
}
|
|
165
165
|
},
|
|
166
166
|
rls_module: {
|
|
167
|
-
schema: '
|
|
167
|
+
schema: 'metaschema_modules_public',
|
|
168
168
|
table: 'rls_module',
|
|
169
169
|
fields: {
|
|
170
170
|
id: 'uuid',
|
|
@@ -181,7 +181,7 @@ const config = {
|
|
|
181
181
|
}
|
|
182
182
|
},
|
|
183
183
|
user_auth_module: {
|
|
184
|
-
schema: '
|
|
184
|
+
schema: 'metaschema_modules_public',
|
|
185
185
|
table: 'user_auth_module',
|
|
186
186
|
fields: {
|
|
187
187
|
id: 'uuid',
|
|
@@ -227,22 +227,22 @@ const exportMeta = async ({ opts, dbname, database_id }) => {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
};
|
|
230
|
-
await queryAndParse('database', `SELECT * FROM
|
|
231
|
-
await queryAndParse('schema', `SELECT * FROM
|
|
232
|
-
await queryAndParse('table', `SELECT * FROM
|
|
233
|
-
await queryAndParse('field', `SELECT * FROM
|
|
234
|
-
await queryAndParse('domains', `SELECT * FROM
|
|
235
|
-
await queryAndParse('apis', `SELECT * FROM
|
|
236
|
-
await queryAndParse('sites', `SELECT * FROM
|
|
237
|
-
await queryAndParse('api_modules', `SELECT * FROM
|
|
238
|
-
await queryAndParse('site_modules', `SELECT * FROM
|
|
239
|
-
await queryAndParse('site_themes', `SELECT * FROM
|
|
240
|
-
await queryAndParse('apps', `SELECT * FROM
|
|
241
|
-
await queryAndParse('database_extension', `SELECT * FROM
|
|
242
|
-
await queryAndParse('api_extensions', `SELECT * FROM
|
|
243
|
-
await queryAndParse('api_schemata', `SELECT * FROM
|
|
244
|
-
await queryAndParse('rls_module', `SELECT * FROM
|
|
245
|
-
await queryAndParse('user_auth_module', `SELECT * FROM
|
|
230
|
+
await queryAndParse('database', `SELECT * FROM metaschema_public.database WHERE id = $1`);
|
|
231
|
+
await queryAndParse('schema', `SELECT * FROM metaschema_public.schema WHERE database_id = $1`);
|
|
232
|
+
await queryAndParse('table', `SELECT * FROM metaschema_public.table WHERE database_id = $1`);
|
|
233
|
+
await queryAndParse('field', `SELECT * FROM metaschema_public.field WHERE database_id = $1`);
|
|
234
|
+
await queryAndParse('domains', `SELECT * FROM services_public.domains WHERE database_id = $1`);
|
|
235
|
+
await queryAndParse('apis', `SELECT * FROM services_public.apis WHERE database_id = $1`);
|
|
236
|
+
await queryAndParse('sites', `SELECT * FROM services_public.sites WHERE database_id = $1`);
|
|
237
|
+
await queryAndParse('api_modules', `SELECT * FROM services_public.api_modules WHERE database_id = $1`);
|
|
238
|
+
await queryAndParse('site_modules', `SELECT * FROM services_public.site_modules WHERE database_id = $1`);
|
|
239
|
+
await queryAndParse('site_themes', `SELECT * FROM services_public.site_themes WHERE database_id = $1`);
|
|
240
|
+
await queryAndParse('apps', `SELECT * FROM services_public.apps WHERE database_id = $1`);
|
|
241
|
+
await queryAndParse('database_extension', `SELECT * FROM metaschema_public.database_extension WHERE database_id = $1`);
|
|
242
|
+
await queryAndParse('api_extensions', `SELECT * FROM services_public.api_extensions WHERE database_id = $1`);
|
|
243
|
+
await queryAndParse('api_schemata', `SELECT * FROM services_public.api_schemata WHERE database_id = $1`);
|
|
244
|
+
await queryAndParse('rls_module', `SELECT * FROM metaschema_modules_public.rls_module WHERE database_id = $1`);
|
|
245
|
+
await queryAndParse('user_auth_module', `SELECT * FROM metaschema_modules_public.user_auth_module WHERE database_id = $1`);
|
|
246
246
|
return Object.entries(sql).reduce((m, [_, v]) => m + '\n\n' + v, '');
|
|
247
247
|
};
|
|
248
248
|
exports.exportMeta = exportMeta;
|
|
@@ -106,8 +106,8 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
106
106
|
...options.pg,
|
|
107
107
|
database
|
|
108
108
|
});
|
|
109
|
-
const db = await pgPool.query(`select * from
|
|
110
|
-
const schemas = await pgPool.query(`select * from
|
|
109
|
+
const db = await pgPool.query(`select * from metaschema_public.database where id=$1`, [databaseId]);
|
|
110
|
+
const schemas = await pgPool.query(`select * from metaschema_public.schema where database_id=$1`, [databaseId]);
|
|
111
111
|
if (!db?.rows?.length) {
|
|
112
112
|
console.log('NO DATABASES.');
|
|
113
113
|
return;
|
|
@@ -186,7 +186,7 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
186
186
|
deps: [],
|
|
187
187
|
deploy: 'migrate/meta',
|
|
188
188
|
content: `SET session_replication_role TO replica;
|
|
189
|
-
-- using replica in case we are deploying triggers to
|
|
189
|
+
-- using replica in case we are deploying triggers to metaschema_public
|
|
190
190
|
|
|
191
191
|
-- unaccent, postgis affected and require grants
|
|
192
192
|
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public to public;
|
|
@@ -205,12 +205,12 @@ ${meta}
|
|
|
205
205
|
|
|
206
206
|
-- TODO: Research needed - These UPDATE statements may be a security leak.
|
|
207
207
|
-- They appear to rebind exported metadata to the target database after import,
|
|
208
|
-
-- but exposing dbname in
|
|
208
|
+
-- but exposing dbname in services_public tables could leak internal database names.
|
|
209
209
|
-- Consider removing entirely or gating behind an explicit flag.
|
|
210
|
-
-- UPDATE
|
|
210
|
+
-- UPDATE services_public.apis
|
|
211
211
|
-- SET dbname = current_database() WHERE TRUE;
|
|
212
212
|
|
|
213
|
-
-- UPDATE
|
|
213
|
+
-- UPDATE services_public.sites
|
|
214
214
|
-- SET dbname = current_database() WHERE TRUE;
|
|
215
215
|
|
|
216
216
|
SET session_replication_role TO DEFAULT;
|
|
@@ -53,17 +53,6 @@ CREATE PROCEDURE pgpm_migrate.deploy(
|
|
|
53
53
|
LANGUAGE plpgsql AS $$
|
|
54
54
|
DECLARE
|
|
55
55
|
v_change_id TEXT;
|
|
56
|
-
-- Error diagnostic variables
|
|
57
|
-
v_sqlstate TEXT;
|
|
58
|
-
v_message TEXT;
|
|
59
|
-
v_detail TEXT;
|
|
60
|
-
v_hint TEXT;
|
|
61
|
-
v_context TEXT;
|
|
62
|
-
v_schema_name TEXT;
|
|
63
|
-
v_table_name TEXT;
|
|
64
|
-
v_column_name TEXT;
|
|
65
|
-
v_constraint_name TEXT;
|
|
66
|
-
v_datatype_name TEXT;
|
|
67
56
|
BEGIN
|
|
68
57
|
-- Ensure package exists
|
|
69
58
|
CALL pgpm_migrate.register_package(p_package);
|
|
@@ -108,30 +97,8 @@ BEGIN
|
|
|
108
97
|
BEGIN
|
|
109
98
|
EXECUTE p_deploy_sql;
|
|
110
99
|
EXCEPTION WHEN OTHERS THEN
|
|
111
|
-
--
|
|
112
|
-
|
|
113
|
-
v_sqlstate = RETURNED_SQLSTATE,
|
|
114
|
-
v_message = MESSAGE_TEXT,
|
|
115
|
-
v_detail = PG_EXCEPTION_DETAIL,
|
|
116
|
-
v_hint = PG_EXCEPTION_HINT,
|
|
117
|
-
v_context = PG_EXCEPTION_CONTEXT,
|
|
118
|
-
v_schema_name = SCHEMA_NAME,
|
|
119
|
-
v_table_name = TABLE_NAME,
|
|
120
|
-
v_column_name = COLUMN_NAME,
|
|
121
|
-
v_constraint_name = CONSTRAINT_NAME,
|
|
122
|
-
v_datatype_name = PG_DATATYPE_NAME;
|
|
123
|
-
|
|
124
|
-
-- Re-raise with all captured diagnostics preserved
|
|
125
|
-
RAISE EXCEPTION USING
|
|
126
|
-
ERRCODE = v_sqlstate,
|
|
127
|
-
MESSAGE = v_message,
|
|
128
|
-
DETAIL = v_detail,
|
|
129
|
-
HINT = v_hint,
|
|
130
|
-
SCHEMA = v_schema_name,
|
|
131
|
-
TABLE = v_table_name,
|
|
132
|
-
COLUMN = v_column_name,
|
|
133
|
-
CONSTRAINT = v_constraint_name,
|
|
134
|
-
DATATYPE = v_datatype_name;
|
|
100
|
+
-- Re-raise the original exception to preserve full context including SQL statement
|
|
101
|
+
RAISE;
|
|
135
102
|
END;
|
|
136
103
|
END IF;
|
|
137
104
|
|
|
@@ -158,18 +125,6 @@ CREATE PROCEDURE pgpm_migrate.revert(
|
|
|
158
125
|
p_revert_sql TEXT
|
|
159
126
|
)
|
|
160
127
|
LANGUAGE plpgsql AS $$
|
|
161
|
-
DECLARE
|
|
162
|
-
-- Error diagnostic variables
|
|
163
|
-
v_sqlstate TEXT;
|
|
164
|
-
v_message TEXT;
|
|
165
|
-
v_detail TEXT;
|
|
166
|
-
v_hint TEXT;
|
|
167
|
-
v_context TEXT;
|
|
168
|
-
v_schema_name TEXT;
|
|
169
|
-
v_table_name TEXT;
|
|
170
|
-
v_column_name TEXT;
|
|
171
|
-
v_constraint_name TEXT;
|
|
172
|
-
v_datatype_name TEXT;
|
|
173
128
|
BEGIN
|
|
174
129
|
-- Check if deployed
|
|
175
130
|
IF NOT pgpm_migrate.is_deployed(p_package, p_change_name) THEN
|
|
@@ -211,34 +166,12 @@ BEGIN
|
|
|
211
166
|
END;
|
|
212
167
|
END IF;
|
|
213
168
|
|
|
214
|
-
-- Execute revert
|
|
169
|
+
-- Execute revert
|
|
215
170
|
BEGIN
|
|
216
171
|
EXECUTE p_revert_sql;
|
|
217
172
|
EXCEPTION WHEN OTHERS THEN
|
|
218
|
-
--
|
|
219
|
-
|
|
220
|
-
v_sqlstate = RETURNED_SQLSTATE,
|
|
221
|
-
v_message = MESSAGE_TEXT,
|
|
222
|
-
v_detail = PG_EXCEPTION_DETAIL,
|
|
223
|
-
v_hint = PG_EXCEPTION_HINT,
|
|
224
|
-
v_context = PG_EXCEPTION_CONTEXT,
|
|
225
|
-
v_schema_name = SCHEMA_NAME,
|
|
226
|
-
v_table_name = TABLE_NAME,
|
|
227
|
-
v_column_name = COLUMN_NAME,
|
|
228
|
-
v_constraint_name = CONSTRAINT_NAME,
|
|
229
|
-
v_datatype_name = PG_DATATYPE_NAME;
|
|
230
|
-
|
|
231
|
-
-- Re-raise with all captured diagnostics preserved
|
|
232
|
-
RAISE EXCEPTION USING
|
|
233
|
-
ERRCODE = v_sqlstate,
|
|
234
|
-
MESSAGE = v_message,
|
|
235
|
-
DETAIL = v_detail,
|
|
236
|
-
HINT = v_hint,
|
|
237
|
-
SCHEMA = v_schema_name,
|
|
238
|
-
TABLE = v_table_name,
|
|
239
|
-
COLUMN = v_column_name,
|
|
240
|
-
CONSTRAINT = v_constraint_name,
|
|
241
|
-
DATATYPE = v_datatype_name;
|
|
173
|
+
-- Re-raise the original exception to preserve full context including SQL statement
|
|
174
|
+
RAISE;
|
|
242
175
|
END;
|
|
243
176
|
|
|
244
177
|
-- Remove from deployed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.2",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM Package and Migration Tools",
|
|
6
6
|
"main": "index.js",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"pgsql-parser": "^17.9.9",
|
|
65
65
|
"yanse": "^0.1.11"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "5eca40587d2b8e2362a2308bc3fa8c1eecf131da"
|
|
68
68
|
}
|