@contember/engine-system-api 2.1.0-alpha.3 → 2.1.0-alpha.30
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/development/src/migrations/2025-03-14-110000-fix-missing-index.cjs +3 -0
- package/dist/development/src/migrations/2025-03-14-110000-fix-missing-index.cjs.map +1 -1
- package/dist/development/src/migrations/2025-03-14-110000-fix-missing-index.js +3 -0
- package/dist/development/src/migrations/2025-03-14-110000-fix-missing-index.js.map +1 -1
- package/dist/development/src/model/migrations/ProjectMigrator.cjs +15 -5
- package/dist/development/src/model/migrations/ProjectMigrator.cjs.map +1 -1
- package/dist/development/src/model/migrations/ProjectMigrator.js +15 -5
- package/dist/development/src/model/migrations/ProjectMigrator.js.map +1 -1
- package/dist/development/src/model/migrations/SchemaProvider.cjs +1 -4
- package/dist/development/src/model/migrations/SchemaProvider.cjs.map +1 -1
- package/dist/development/src/model/migrations/SchemaProvider.js +1 -4
- package/dist/development/src/model/migrations/SchemaProvider.js.map +1 -1
- package/dist/production/src/migrations/2025-03-14-110000-fix-missing-index.cjs +3 -0
- package/dist/production/src/migrations/2025-03-14-110000-fix-missing-index.cjs.map +1 -1
- package/dist/production/src/migrations/2025-03-14-110000-fix-missing-index.js +3 -0
- package/dist/production/src/migrations/2025-03-14-110000-fix-missing-index.js.map +1 -1
- package/dist/production/src/model/migrations/ProjectMigrator.cjs +15 -5
- package/dist/production/src/model/migrations/ProjectMigrator.cjs.map +1 -1
- package/dist/production/src/model/migrations/ProjectMigrator.js +15 -5
- package/dist/production/src/model/migrations/ProjectMigrator.js.map +1 -1
- package/dist/production/src/model/migrations/SchemaProvider.cjs +1 -4
- package/dist/production/src/model/migrations/SchemaProvider.cjs.map +1 -1
- package/dist/production/src/model/migrations/SchemaProvider.js +1 -4
- package/dist/production/src/model/migrations/SchemaProvider.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/migrations/2025-03-14-110000-fix-missing-index.d.ts.map +1 -1
- package/dist/types/model/migrations/ProjectMigrator.d.ts +1 -0
- package/dist/types/model/migrations/ProjectMigrator.d.ts.map +1 -1
- package/dist/types/model/migrations/SchemaProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/graphql.codegen.yml +1 -1
- package/package.json +12 -12
- package/src/migrations/2025-03-14-110000-fix-missing-index.ts +3 -0
- package/src/model/migrations/ProjectMigrator.ts +21 -5
- package/src/model/migrations/SchemaProvider.ts +4 -5
package/graphql.codegen.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-system-api",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.30",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -23,21 +23,21 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@contember/authorization": "2.1.0-alpha.
|
|
27
|
-
"@contember/database": "2.1.0-alpha.
|
|
28
|
-
"@contember/database-migrations": "2.1.0-alpha.
|
|
29
|
-
"@contember/dic": "2.1.0-alpha.
|
|
30
|
-
"@contember/graphql-utils": "2.1.0-alpha.
|
|
31
|
-
"@contember/logger": "2.1.0-alpha.
|
|
32
|
-
"@contember/queryable": "2.1.0-alpha.
|
|
33
|
-
"@contember/schema": "2.1.0-alpha.
|
|
34
|
-
"@contember/schema-migrations": "2.1.0-alpha.
|
|
35
|
-
"@contember/schema-utils": "2.1.0-alpha.
|
|
26
|
+
"@contember/authorization": "2.1.0-alpha.30",
|
|
27
|
+
"@contember/database": "2.1.0-alpha.30",
|
|
28
|
+
"@contember/database-migrations": "2.1.0-alpha.30",
|
|
29
|
+
"@contember/dic": "2.1.0-alpha.30",
|
|
30
|
+
"@contember/graphql-utils": "2.1.0-alpha.30",
|
|
31
|
+
"@contember/logger": "2.1.0-alpha.30",
|
|
32
|
+
"@contember/queryable": "2.1.0-alpha.30",
|
|
33
|
+
"@contember/schema": "2.1.0-alpha.30",
|
|
34
|
+
"@contember/schema-migrations": "2.1.0-alpha.30",
|
|
35
|
+
"@contember/schema-utils": "2.1.0-alpha.30",
|
|
36
36
|
"@graphql-tools/utils": "^10.5.5",
|
|
37
37
|
"graphql-tag": "^2.12.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@contember/schema-definition": "2.1.0-alpha.
|
|
40
|
+
"@contember/schema-definition": "2.1.0-alpha.30",
|
|
41
41
|
"@types/node": "^20.17.22",
|
|
42
42
|
"graphql": "^16.9.0",
|
|
43
43
|
"pg": "^8.12.0"
|
|
@@ -14,6 +14,9 @@ export default async function (builder: MigrationBuilder, args: MigrationArgs<Sy
|
|
|
14
14
|
if (entity.indexes.length === 0) {
|
|
15
15
|
continue
|
|
16
16
|
}
|
|
17
|
+
if (entity.view) {
|
|
18
|
+
continue
|
|
19
|
+
}
|
|
17
20
|
|
|
18
21
|
for (const stage of stages) {
|
|
19
22
|
const databaseMetadata = metadataByStage[stage.schema] ??= await args.databaseMetadataResolver(args.connection, stage.schema)
|
|
@@ -15,6 +15,11 @@ import { SchemaProvider } from './SchemaProvider'
|
|
|
15
15
|
import { SaveSchemaCommand } from '../commands/schema/SaveSchemaCommand'
|
|
16
16
|
import { ImplementationException } from '../../utils'
|
|
17
17
|
|
|
18
|
+
type MigrationVariables = {
|
|
19
|
+
system_schema: string
|
|
20
|
+
project_slug: string
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
export class ProjectMigrator {
|
|
19
24
|
constructor(
|
|
20
25
|
private readonly migrationDescriber: MigrationDescriber,
|
|
@@ -64,7 +69,7 @@ export class ProjectMigrator {
|
|
|
64
69
|
modification,
|
|
65
70
|
formatVersion,
|
|
66
71
|
migration.version,
|
|
67
|
-
|
|
72
|
+
project,
|
|
68
73
|
metadataStore,
|
|
69
74
|
)
|
|
70
75
|
}
|
|
@@ -200,6 +205,13 @@ export class ProjectMigrator {
|
|
|
200
205
|
return toExecute
|
|
201
206
|
}
|
|
202
207
|
|
|
208
|
+
private sqlPreprocessor(text: string, variables: MigrationVariables): string {
|
|
209
|
+
return Object.entries(variables).reduce(
|
|
210
|
+
(content, [key, value]) => content.replace(new RegExp(`\\{\\{${key}\\}\\}`, 'g'), value),
|
|
211
|
+
text,
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
203
215
|
private async applyModification(
|
|
204
216
|
db: Client,
|
|
205
217
|
stages: Stage[],
|
|
@@ -207,7 +219,7 @@ export class ProjectMigrator {
|
|
|
207
219
|
modification: Migration.Modification,
|
|
208
220
|
formatVersion: number,
|
|
209
221
|
migrationVersion: string,
|
|
210
|
-
systemSchema: string,
|
|
222
|
+
project: { slug: string; systemSchema: string },
|
|
211
223
|
metadataStore: SchemaDatabaseMetadataResolverStore,
|
|
212
224
|
): Promise<[Schema]> {
|
|
213
225
|
const {
|
|
@@ -217,17 +229,21 @@ export class ProjectMigrator {
|
|
|
217
229
|
for (const stage of stages) {
|
|
218
230
|
const databaseMetadata = await metadataStore.getMetadata(stage.schema)
|
|
219
231
|
const sql = getSql({
|
|
220
|
-
systemSchema,
|
|
232
|
+
systemSchema: project.systemSchema,
|
|
221
233
|
databaseMetadata,
|
|
222
234
|
invalidateDatabaseMetadata: () => metadataStore.invalidate(stage.schema),
|
|
223
235
|
})
|
|
224
|
-
|
|
236
|
+
const processedSql = this.sqlPreprocessor(sql, {
|
|
237
|
+
project_slug: project.slug,
|
|
238
|
+
system_schema: project.systemSchema,
|
|
239
|
+
})
|
|
240
|
+
await this.executeOnStage(db, stage, processedSql, migrationVersion)
|
|
225
241
|
}
|
|
226
242
|
return [newSchema]
|
|
227
243
|
}
|
|
228
244
|
|
|
229
245
|
private async executeOnStage(db: Client, stage: Stage, sql: string, migrationVersion: string) {
|
|
230
|
-
await db.query('SET search_path TO ' + wrapIdentifier(stage.schema))
|
|
246
|
+
await db.query('SET LOCAL search_path TO ' + wrapIdentifier(stage.schema))
|
|
231
247
|
try {
|
|
232
248
|
await db.query(sql)
|
|
233
249
|
} catch (e) {
|
|
@@ -34,11 +34,10 @@ export class SchemaProvider {
|
|
|
34
34
|
|
|
35
35
|
const partialResult = newMigrations.reduce<SchemaWithMeta>(
|
|
36
36
|
(schema, migration) => {
|
|
37
|
-
if (migration.type !== 'schema') {
|
|
38
|
-
return schema
|
|
39
|
-
}
|
|
40
37
|
return {
|
|
41
|
-
schema:
|
|
38
|
+
schema: migration.type !== 'schema'
|
|
39
|
+
? schema.schema
|
|
40
|
+
: this.schemaMigrator.applyModifications(schema.schema, migration.modifications, migration.formatVersion),
|
|
42
41
|
meta: {
|
|
43
42
|
version: migration.version,
|
|
44
43
|
id: migration.id,
|
|
@@ -63,7 +62,7 @@ export class SchemaProvider {
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
public async fetch({ db, currentSchema
|
|
65
|
+
public async fetch({ db, currentSchema }: {
|
|
67
66
|
db: DatabaseContext
|
|
68
67
|
currentSchema?: SchemaWithMeta | null
|
|
69
68
|
}): Promise<SchemaWithMeta> {
|