@contember/migrations-client 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/JsLoader.cjs +2 -2
- package/dist/development/src/JsLoader.cjs.map +1 -1
- package/dist/development/src/JsLoader.js +2 -2
- package/dist/development/src/JsLoader.js.map +1 -1
- package/dist/development/src/MigrationExecuteHelper.cjs +4 -1
- package/dist/development/src/MigrationExecuteHelper.cjs.map +1 -1
- package/dist/development/src/MigrationExecuteHelper.js +4 -1
- package/dist/development/src/MigrationExecuteHelper.js.map +1 -1
- package/dist/development/src/MigrationFile.cjs.map +1 -1
- package/dist/development/src/MigrationFile.js.map +1 -1
- package/dist/development/src/migrations.cjs +11 -0
- package/dist/development/src/migrations.cjs.map +1 -1
- package/dist/development/src/migrations.js +11 -0
- package/dist/development/src/migrations.js.map +1 -1
- package/dist/production/src/JsLoader.cjs +2 -2
- package/dist/production/src/JsLoader.cjs.map +1 -1
- package/dist/production/src/JsLoader.js +2 -2
- package/dist/production/src/JsLoader.js.map +1 -1
- package/dist/production/src/MigrationExecuteHelper.cjs +4 -1
- package/dist/production/src/MigrationExecuteHelper.cjs.map +1 -1
- package/dist/production/src/MigrationExecuteHelper.js +4 -1
- package/dist/production/src/MigrationExecuteHelper.js.map +1 -1
- package/dist/production/src/MigrationFile.cjs.map +1 -1
- package/dist/production/src/MigrationFile.js.map +1 -1
- package/dist/production/src/migrations.cjs +11 -0
- package/dist/production/src/migrations.cjs.map +1 -1
- package/dist/production/src/migrations.js +11 -0
- package/dist/production/src/migrations.js.map +1 -1
- package/dist/types/JsLoader.d.ts.map +1 -1
- package/dist/types/MigrationExecuteHelper.d.ts +1 -1
- package/dist/types/MigrationExecuteHelper.d.ts.map +1 -1
- package/dist/types/MigrationFile.d.ts +3 -0
- package/dist/types/MigrationFile.d.ts.map +1 -1
- package/dist/types/migrations.d.ts +5 -1
- package/dist/types/migrations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/JsLoader.ts +3 -7
- package/src/MigrationExecuteHelper.ts +5 -2
- package/src/MigrationFile.ts +3 -0
- package/src/migrations.ts +20 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/migrations-client",
|
|
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",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"test": "echo 'No tests'"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/engine-common": "2.1.0-alpha.
|
|
30
|
-
"@contember/graphql-client": "2.1.0-alpha.
|
|
31
|
-
"@contember/schema": "2.1.0-alpha.
|
|
32
|
-
"@contember/schema-migrations": "2.1.0-alpha.
|
|
33
|
-
"@contember/schema-utils": "2.1.0-alpha.
|
|
29
|
+
"@contember/engine-common": "2.1.0-alpha.30",
|
|
30
|
+
"@contember/graphql-client": "2.1.0-alpha.30",
|
|
31
|
+
"@contember/schema": "2.1.0-alpha.30",
|
|
32
|
+
"@contember/schema-migrations": "2.1.0-alpha.30",
|
|
33
|
+
"@contember/schema-utils": "2.1.0-alpha.30"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^20.17.22"
|
package/src/JsLoader.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MigrationFileLoader } from './MigrationFileLoader'
|
|
2
2
|
import { MigrationParser } from './MigrationParser'
|
|
3
|
-
import { ContentMigration, MigrationContent, MigrationFile } from './MigrationFile'
|
|
3
|
+
import { ContentMigration, ContentMigrationFactoryArgs, MigrationContent, MigrationFile } from './MigrationFile'
|
|
4
4
|
|
|
5
5
|
export class JsLoader implements MigrationFileLoader {
|
|
6
6
|
constructor(
|
|
@@ -11,10 +11,6 @@ export class JsLoader implements MigrationFileLoader {
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
public async load(file: MigrationFile): Promise<MigrationContent> {
|
|
14
|
-
|
|
15
|
-
// const code = await buildJs(file.path)
|
|
16
|
-
// const fn = new Function(`var module = {}; ((module) => { ${code} })(module); return module`)
|
|
17
|
-
|
|
18
14
|
const exports = await this.jsExecutor(file.path)
|
|
19
15
|
if (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {
|
|
20
16
|
throw `export "default" or "query" is required in ${file.path}`
|
|
@@ -25,8 +21,8 @@ export class JsLoader implements MigrationFileLoader {
|
|
|
25
21
|
|
|
26
22
|
return {
|
|
27
23
|
type: 'factory',
|
|
28
|
-
factory: async (): Promise<ContentMigration> => {
|
|
29
|
-
const result = await exports.default()
|
|
24
|
+
factory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {
|
|
25
|
+
const result = await exports.default(args)
|
|
30
26
|
const migration = this.migrationParser.parse(file, result ?? { queries: [] })
|
|
31
27
|
if (migration.type !== 'content') {
|
|
32
28
|
throw new Error()
|
|
@@ -15,7 +15,7 @@ export class MigrationExecutor {
|
|
|
15
15
|
}: {
|
|
16
16
|
client: SystemClient
|
|
17
17
|
migrations: MigrationToExecuteOkStatus[]
|
|
18
|
-
contentMigrationFactoryArgs: ContentMigrationFactoryArgs
|
|
18
|
+
contentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>
|
|
19
19
|
log: (message: string) => void
|
|
20
20
|
force?: boolean
|
|
21
21
|
}): Promise<void> {
|
|
@@ -66,7 +66,10 @@ export class MigrationExecutor {
|
|
|
66
66
|
const migrationContent = await migration.localMigration.getContent()
|
|
67
67
|
if (migrationContent.type === 'factory') {
|
|
68
68
|
await executeMigrations()
|
|
69
|
-
const result = await migrationContent.factory(
|
|
69
|
+
const result = await migrationContent.factory({
|
|
70
|
+
...contentMigrationFactoryArgs,
|
|
71
|
+
migration: migration.localMigration,
|
|
72
|
+
})
|
|
70
73
|
migrationsToRun.push(result)
|
|
71
74
|
await executeMigrations()
|
|
72
75
|
} else {
|
package/src/MigrationFile.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Migration } from '@contember/schema-migrations'
|
|
2
2
|
import { JSONObject } from './utils/json'
|
|
3
|
+
import { SchemaVersionBuilder } from './SchemaVersionBuilder'
|
|
3
4
|
|
|
4
5
|
export interface MigrationFile {
|
|
5
6
|
path: string
|
|
@@ -36,6 +37,8 @@ export type ContentMigrationFactoryArgs = {
|
|
|
36
37
|
apiBaseUrl: string
|
|
37
38
|
projectName: string
|
|
38
39
|
apiToken: string
|
|
40
|
+
migration: MigrationFile
|
|
41
|
+
schemaVersionBuilder: SchemaVersionBuilder
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
export type ContentMigrationFactory = {
|
package/src/migrations.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface ExecutedMigration extends Migration {
|
|
|
14
14
|
export enum MigrationState {
|
|
15
15
|
TO_EXECUTE_OK = 'to_execute_ok',
|
|
16
16
|
TO_EXECUTE_ERROR = 'to_execute_error',
|
|
17
|
+
SKIP_EMPTY = 'skip_empty',
|
|
17
18
|
EXECUTED_OK = 'executed_ok',
|
|
18
19
|
EXECUTED_ERROR = 'executed_error',
|
|
19
20
|
EXECUTED_MISSING = 'executed_missing',
|
|
@@ -34,22 +35,27 @@ interface MigrationToExecuteInvalidStatus extends MigrationStatusBase<MigrationS
|
|
|
34
35
|
errorMessage: string
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
interface MigrationExecutedOkStatus extends MigrationStatusBase<MigrationState.EXECUTED_OK>{
|
|
38
|
+
interface MigrationExecutedOkStatus extends MigrationStatusBase<MigrationState.EXECUTED_OK> {
|
|
38
39
|
executedMigration: ExecutedMigrationInfo
|
|
39
40
|
localMigration: MigrationFile
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
interface MigrationExecutedMissingStatus extends MigrationStatusBase<MigrationState.EXECUTED_MISSING>{
|
|
43
|
+
interface MigrationExecutedMissingStatus extends MigrationStatusBase<MigrationState.EXECUTED_MISSING> {
|
|
43
44
|
executedMigration: ExecutedMigrationInfo
|
|
44
45
|
errorMessage: string
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
interface MigrationExecutedErrorStatus extends MigrationStatusBase<MigrationState.EXECUTED_ERROR>{
|
|
48
|
+
interface MigrationExecutedErrorStatus extends MigrationStatusBase<MigrationState.EXECUTED_ERROR> {
|
|
48
49
|
executedMigration: ExecutedMigrationInfo
|
|
49
50
|
localMigration: MigrationFile
|
|
50
51
|
errorMessage: string
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
export interface MigrationSkipStatus extends MigrationStatusBase<MigrationState.SKIP_EMPTY> {
|
|
55
|
+
localMigration: MigrationFile
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
53
59
|
export type ErrorMigrationStatus =
|
|
54
60
|
| MigrationToExecuteInvalidStatus
|
|
55
61
|
| MigrationExecutedMissingStatus
|
|
@@ -59,6 +65,7 @@ export type AnyMigrationStatus =
|
|
|
59
65
|
| ErrorMigrationStatus
|
|
60
66
|
| MigrationToExecuteOkStatus
|
|
61
67
|
| MigrationExecutedOkStatus
|
|
68
|
+
| MigrationSkipStatus
|
|
62
69
|
|
|
63
70
|
const isErrorMigrationStatus = (migration: AnyMigrationStatus): migration is ErrorMigrationStatus =>
|
|
64
71
|
[MigrationState.EXECUTED_ERROR, MigrationState.EXECUTED_MISSING, MigrationState.TO_EXECUTE_ERROR].includes(
|
|
@@ -124,6 +131,16 @@ export class MigrationsStatusResolver {
|
|
|
124
131
|
if (allMigrations.find(it => it.version === localMigration.version)) {
|
|
125
132
|
continue
|
|
126
133
|
}
|
|
134
|
+
const migrationContent = await localMigration.getContent()
|
|
135
|
+
if (isSchemaMigration(migrationContent) && migrationContent.modifications.length === 0) {
|
|
136
|
+
allMigrations.push({
|
|
137
|
+
state: MigrationState.SKIP_EMPTY,
|
|
138
|
+
localMigration,
|
|
139
|
+
version: localMigration.version,
|
|
140
|
+
name: localMigration.name,
|
|
141
|
+
})
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
127
144
|
|
|
128
145
|
if (latestExecuted && latestExecuted.version > localMigration.version) {
|
|
129
146
|
allMigrations.push({
|