@contember/migrations-client 2.1.0-alpha.3 → 2.1.0-alpha.35
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/package.json +13 -8
- package/src/JsLoader.ts +3 -9
- package/src/MigrationExecuteHelper.ts +5 -4
- package/src/MigrationFile.ts +5 -2
- package/src/MigrationFilesManager.ts +1 -1
- package/src/MigrationsResolver.ts +1 -4
- package/src/SchemaVersionBuilder.ts +1 -2
- package/src/index.ts +2 -5
- package/src/migrations.ts +20 -7
- package/dist/development/index.cjs +0 -53
- package/dist/development/index.cjs.map +0 -1
- package/dist/development/index.js +0 -35
- package/dist/development/index.js.map +0 -1
- package/dist/development/src/JsLoader.cjs +0 -30
- package/dist/development/src/JsLoader.cjs.map +0 -1
- package/dist/development/src/JsLoader.js +0 -30
- package/dist/development/src/JsLoader.js.map +0 -1
- package/dist/development/src/JsonLoader.cjs +0 -33
- package/dist/development/src/JsonLoader.cjs.map +0 -1
- package/dist/development/src/JsonLoader.js +0 -16
- package/dist/development/src/JsonLoader.js.map +0 -1
- package/dist/development/src/MigrationCreator.cjs +0 -46
- package/dist/development/src/MigrationCreator.cjs.map +0 -1
- package/dist/development/src/MigrationCreator.js +0 -46
- package/dist/development/src/MigrationCreator.js.map +0 -1
- package/dist/development/src/MigrationExecuteHelper.cjs +0 -68
- package/dist/development/src/MigrationExecuteHelper.cjs.map +0 -1
- package/dist/development/src/MigrationExecuteHelper.js +0 -68
- package/dist/development/src/MigrationExecuteHelper.js.map +0 -1
- package/dist/development/src/MigrationFile.cjs +0 -5
- package/dist/development/src/MigrationFile.cjs.map +0 -1
- package/dist/development/src/MigrationFile.js +0 -5
- package/dist/development/src/MigrationFile.js.map +0 -1
- package/dist/development/src/MigrationFilesManager.cjs +0 -106
- package/dist/development/src/MigrationFilesManager.cjs.map +0 -1
- package/dist/development/src/MigrationFilesManager.js +0 -89
- package/dist/development/src/MigrationFilesManager.js.map +0 -1
- package/dist/development/src/MigrationParser.cjs +0 -31
- package/dist/development/src/MigrationParser.cjs.map +0 -1
- package/dist/development/src/MigrationParser.js +0 -31
- package/dist/development/src/MigrationParser.js.map +0 -1
- package/dist/development/src/MigrationsResolver.cjs +0 -36
- package/dist/development/src/MigrationsResolver.cjs.map +0 -1
- package/dist/development/src/MigrationsResolver.js +0 -36
- package/dist/development/src/MigrationsResolver.js.map +0 -1
- package/dist/development/src/SchemaVersionBuilder.cjs +0 -26
- package/dist/development/src/SchemaVersionBuilder.cjs.map +0 -1
- package/dist/development/src/SchemaVersionBuilder.js +0 -26
- package/dist/development/src/SchemaVersionBuilder.js.map +0 -1
- package/dist/development/src/SystemClient.cjs +0 -117
- package/dist/development/src/SystemClient.cjs.map +0 -1
- package/dist/development/src/SystemClient.js +0 -117
- package/dist/development/src/SystemClient.js.map +0 -1
- package/dist/development/src/migrations.cjs +0 -97
- package/dist/development/src/migrations.cjs.map +0 -1
- package/dist/development/src/migrations.js +0 -97
- package/dist/development/src/migrations.js.map +0 -1
- package/dist/development/src/utils/assertNever.cjs +0 -7
- package/dist/development/src/utils/assertNever.cjs.map +0 -1
- package/dist/development/src/utils/assertNever.js +0 -7
- package/dist/development/src/utils/assertNever.js.map +0 -1
- package/dist/production/index.cjs +0 -53
- package/dist/production/index.cjs.map +0 -1
- package/dist/production/index.js +0 -35
- package/dist/production/index.js.map +0 -1
- package/dist/production/src/JsLoader.cjs +0 -30
- package/dist/production/src/JsLoader.cjs.map +0 -1
- package/dist/production/src/JsLoader.js +0 -30
- package/dist/production/src/JsLoader.js.map +0 -1
- package/dist/production/src/JsonLoader.cjs +0 -33
- package/dist/production/src/JsonLoader.cjs.map +0 -1
- package/dist/production/src/JsonLoader.js +0 -16
- package/dist/production/src/JsonLoader.js.map +0 -1
- package/dist/production/src/MigrationCreator.cjs +0 -46
- package/dist/production/src/MigrationCreator.cjs.map +0 -1
- package/dist/production/src/MigrationCreator.js +0 -46
- package/dist/production/src/MigrationCreator.js.map +0 -1
- package/dist/production/src/MigrationExecuteHelper.cjs +0 -68
- package/dist/production/src/MigrationExecuteHelper.cjs.map +0 -1
- package/dist/production/src/MigrationExecuteHelper.js +0 -68
- package/dist/production/src/MigrationExecuteHelper.js.map +0 -1
- package/dist/production/src/MigrationFile.cjs +0 -5
- package/dist/production/src/MigrationFile.cjs.map +0 -1
- package/dist/production/src/MigrationFile.js +0 -5
- package/dist/production/src/MigrationFile.js.map +0 -1
- package/dist/production/src/MigrationFilesManager.cjs +0 -106
- package/dist/production/src/MigrationFilesManager.cjs.map +0 -1
- package/dist/production/src/MigrationFilesManager.js +0 -89
- package/dist/production/src/MigrationFilesManager.js.map +0 -1
- package/dist/production/src/MigrationParser.cjs +0 -31
- package/dist/production/src/MigrationParser.cjs.map +0 -1
- package/dist/production/src/MigrationParser.js +0 -31
- package/dist/production/src/MigrationParser.js.map +0 -1
- package/dist/production/src/MigrationsResolver.cjs +0 -36
- package/dist/production/src/MigrationsResolver.cjs.map +0 -1
- package/dist/production/src/MigrationsResolver.js +0 -36
- package/dist/production/src/MigrationsResolver.js.map +0 -1
- package/dist/production/src/SchemaVersionBuilder.cjs +0 -26
- package/dist/production/src/SchemaVersionBuilder.cjs.map +0 -1
- package/dist/production/src/SchemaVersionBuilder.js +0 -26
- package/dist/production/src/SchemaVersionBuilder.js.map +0 -1
- package/dist/production/src/SystemClient.cjs +0 -117
- package/dist/production/src/SystemClient.cjs.map +0 -1
- package/dist/production/src/SystemClient.js +0 -117
- package/dist/production/src/SystemClient.js.map +0 -1
- package/dist/production/src/migrations.cjs +0 -97
- package/dist/production/src/migrations.cjs.map +0 -1
- package/dist/production/src/migrations.js +0 -97
- package/dist/production/src/migrations.js.map +0 -1
- package/dist/production/src/utils/assertNever.cjs +0 -7
- package/dist/production/src/utils/assertNever.cjs.map +0 -1
- package/dist/production/src/utils/assertNever.js +0 -7
- package/dist/production/src/utils/assertNever.js.map +0 -1
- package/dist/types/JsLoader.d.ts +0 -10
- package/dist/types/JsLoader.d.ts.map +0 -1
- package/dist/types/JsonLoader.d.ts +0 -9
- package/dist/types/JsonLoader.d.ts.map +0 -1
- package/dist/types/MigrationCreator.d.ts +0 -21
- package/dist/types/MigrationCreator.d.ts.map +0 -1
- package/dist/types/MigrationExecuteHelper.d.ts +0 -13
- package/dist/types/MigrationExecuteHelper.d.ts.map +0 -1
- package/dist/types/MigrationFile.d.ts +0 -36
- package/dist/types/MigrationFile.d.ts.map +0 -1
- package/dist/types/MigrationFileLoader.d.ts +0 -5
- package/dist/types/MigrationFileLoader.d.ts.map +0 -1
- package/dist/types/MigrationFilesManager.d.ts +0 -18
- package/dist/types/MigrationFilesManager.d.ts.map +0 -1
- package/dist/types/MigrationParser.d.ts +0 -6
- package/dist/types/MigrationParser.d.ts.map +0 -1
- package/dist/types/MigrationsResolver.d.ts +0 -14
- package/dist/types/MigrationsResolver.d.ts.map +0 -1
- package/dist/types/SchemaVersionBuilder.d.ts +0 -13
- package/dist/types/SchemaVersionBuilder.d.ts.map +0 -1
- package/dist/types/SystemClient.d.ts +0 -29
- package/dist/types/SystemClient.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -15
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/migrations.d.ts +0 -56
- package/dist/types/migrations.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/dist/types/utils/assertNever.d.ts +0 -2
- package/dist/types/utils/assertNever.d.ts.map +0 -1
- package/dist/types/utils/json.d.ts +0 -7
- package/dist/types/utils/json.d.ts.map +0 -1
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.35",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,14 +26,19 @@
|
|
|
26
26
|
"test": "echo 'No tests'"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/engine-common": "
|
|
30
|
-
"@contember/graphql-client": "
|
|
31
|
-
"@contember/schema": "
|
|
32
|
-
"@contember/schema-migrations": "
|
|
33
|
-
"@contember/schema-utils": "
|
|
29
|
+
"@contember/engine-common": "workspace:*",
|
|
30
|
+
"@contember/graphql-client": "workspace:*",
|
|
31
|
+
"@contember/schema": "workspace:*",
|
|
32
|
+
"@contember/schema-migrations": "workspace:*",
|
|
33
|
+
"@contember/schema-utils": "workspace:*"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "
|
|
36
|
+
"@types/node": "catalog:"
|
|
37
37
|
},
|
|
38
|
-
"type": "module"
|
|
38
|
+
"type": "module",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/contember/contember.git",
|
|
42
|
+
"directory": "packages/migrations-client"
|
|
43
|
+
}
|
|
39
44
|
}
|
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(
|
|
@@ -9,12 +9,7 @@ export class JsLoader implements MigrationFileLoader {
|
|
|
9
9
|
) {
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
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
13
|
const exports = await this.jsExecutor(file.path)
|
|
19
14
|
if (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {
|
|
20
15
|
throw `export "default" or "query" is required in ${file.path}`
|
|
@@ -25,15 +20,14 @@ export class JsLoader implements MigrationFileLoader {
|
|
|
25
20
|
|
|
26
21
|
return {
|
|
27
22
|
type: 'factory',
|
|
28
|
-
factory: async (): Promise<ContentMigration> => {
|
|
29
|
-
const result = await exports.default()
|
|
23
|
+
factory: async (args: ContentMigrationFactoryArgs): Promise<ContentMigration> => {
|
|
24
|
+
const result = await exports.default(args)
|
|
30
25
|
const migration = this.migrationParser.parse(file, result ?? { queries: [] })
|
|
31
26
|
if (migration.type !== 'content') {
|
|
32
27
|
throw new Error()
|
|
33
28
|
}
|
|
34
29
|
return migration
|
|
35
30
|
},
|
|
36
|
-
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
33
|
}
|
|
@@ -3,9 +3,7 @@ import { ContentMigrationFactoryArgs, ResolvedMigrationContent } from './Migrati
|
|
|
3
3
|
import { assertNever } from './utils/assertNever'
|
|
4
4
|
import { SystemClient } from './SystemClient'
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
export class MigrationExecutor {
|
|
8
|
-
|
|
9
7
|
async executeMigrations({
|
|
10
8
|
client,
|
|
11
9
|
migrations,
|
|
@@ -15,7 +13,7 @@ export class MigrationExecutor {
|
|
|
15
13
|
}: {
|
|
16
14
|
client: SystemClient
|
|
17
15
|
migrations: MigrationToExecuteOkStatus[]
|
|
18
|
-
contentMigrationFactoryArgs: ContentMigrationFactoryArgs
|
|
16
|
+
contentMigrationFactoryArgs: Omit<ContentMigrationFactoryArgs, 'migration'>
|
|
19
17
|
log: (message: string) => void
|
|
20
18
|
force?: boolean
|
|
21
19
|
}): Promise<void> {
|
|
@@ -66,7 +64,10 @@ export class MigrationExecutor {
|
|
|
66
64
|
const migrationContent = await migration.localMigration.getContent()
|
|
67
65
|
if (migrationContent.type === 'factory') {
|
|
68
66
|
await executeMigrations()
|
|
69
|
-
const result = await migrationContent.factory(
|
|
67
|
+
const result = await migrationContent.factory({
|
|
68
|
+
...contentMigrationFactoryArgs,
|
|
69
|
+
migration: migration.localMigration,
|
|
70
|
+
})
|
|
70
71
|
migrationsToRun.push(result)
|
|
71
72
|
await executeMigrations()
|
|
72
73
|
} 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
|
|
@@ -9,7 +10,8 @@ export interface MigrationFile {
|
|
|
9
10
|
getContent: () => Promise<MigrationContent>
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>
|
|
13
|
+
export const isSchemaMigration = (content: MigrationContent): content is SchemaMigration =>
|
|
14
|
+
typeof content !== 'function' && 'modifications' in content
|
|
13
15
|
|
|
14
16
|
export type ResolvedMigrationContent =
|
|
15
17
|
| SchemaMigration
|
|
@@ -36,6 +38,8 @@ export type ContentMigrationFactoryArgs = {
|
|
|
36
38
|
apiBaseUrl: string
|
|
37
39
|
projectName: string
|
|
38
40
|
apiToken: string
|
|
41
|
+
migration: MigrationFile
|
|
42
|
+
schemaVersionBuilder: SchemaVersionBuilder
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export type ContentMigrationFactory = {
|
|
@@ -49,4 +53,3 @@ export type ContentMigrationQuery = {
|
|
|
49
53
|
stage?: string
|
|
50
54
|
checkMutationResult?: boolean
|
|
51
55
|
}
|
|
52
|
-
|
|
@@ -83,7 +83,7 @@ export class MigrationFilesManager {
|
|
|
83
83
|
const files = await this.tryReadDir()
|
|
84
84
|
|
|
85
85
|
const extensions = Object.keys(this.loaders).join('|')
|
|
86
|
-
const regex = new RegExp('^\\d{4}-\\d{2}-\\d{2}-\\d{6}-[\\w-]+\\.(' + extensions
|
|
86
|
+
const regex = new RegExp('^\\d{4}-\\d{2}-\\d{2}-\\d{6}-[\\w-]+\\.(' + extensions + ')$')
|
|
87
87
|
const filteredFiles = await Promise.all(
|
|
88
88
|
files
|
|
89
89
|
.filter(it => it.isFile())
|
|
@@ -4,7 +4,6 @@ import { isSchemaMigration, MigrationFile } from './MigrationFile'
|
|
|
4
4
|
import { MigrationVersionHelper } from '@contember/engine-common'
|
|
5
5
|
|
|
6
6
|
export class MigrationsResolver {
|
|
7
|
-
|
|
8
7
|
constructor(private readonly migrationFilesManager: MigrationFilesManager) {}
|
|
9
8
|
|
|
10
9
|
public get directory(): string {
|
|
@@ -31,9 +30,7 @@ export class MigrationsResolver {
|
|
|
31
30
|
public async findSchemaMigrationByVersion(version: string): Promise<Migration | null> {
|
|
32
31
|
const migrations = await this.getSchemaMigrations()
|
|
33
32
|
return migrations
|
|
34
|
-
.find(it =>
|
|
35
|
-
MigrationVersionHelper.extractVersion(it.version) === MigrationVersionHelper.extractVersion(version),
|
|
36
|
-
)
|
|
33
|
+
.find(it => MigrationVersionHelper.extractVersion(it.version) === MigrationVersionHelper.extractVersion(version))
|
|
37
34
|
?? null
|
|
38
35
|
}
|
|
39
36
|
|
|
@@ -25,8 +25,7 @@ export class SchemaVersionBuilder {
|
|
|
25
25
|
return (await this.migrationsResolver.getSchemaMigrations())
|
|
26
26
|
.filter(({ version }) => condition(version))
|
|
27
27
|
.reduce<Schema>(
|
|
28
|
-
(schema, { modifications, formatVersion }) =>
|
|
29
|
-
this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
|
|
28
|
+
(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
|
|
30
29
|
initialSchema,
|
|
31
30
|
)
|
|
32
31
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
export {
|
|
2
|
+
calculateMigrationChecksum,
|
|
2
3
|
MigrationDescriber,
|
|
3
4
|
ModificationHandlerFactory,
|
|
4
5
|
SchemaDiffer,
|
|
5
6
|
SchemaMigrator,
|
|
6
7
|
VERSION_LATEST,
|
|
7
|
-
calculateMigrationChecksum,
|
|
8
|
-
} from '@contember/schema-migrations'
|
|
9
|
-
export type {
|
|
10
|
-
MigrationInfo,
|
|
11
|
-
Migration,
|
|
12
8
|
} from '@contember/schema-migrations'
|
|
9
|
+
export type { Migration, MigrationInfo } from '@contember/schema-migrations'
|
|
13
10
|
export * from './JsLoader'
|
|
14
11
|
export * from './JsonLoader'
|
|
15
12
|
export * from './MigrationCreator'
|
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,26 @@ 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
|
+
|
|
53
58
|
export type ErrorMigrationStatus =
|
|
54
59
|
| MigrationToExecuteInvalidStatus
|
|
55
60
|
| MigrationExecutedMissingStatus
|
|
@@ -59,6 +64,7 @@ export type AnyMigrationStatus =
|
|
|
59
64
|
| ErrorMigrationStatus
|
|
60
65
|
| MigrationToExecuteOkStatus
|
|
61
66
|
| MigrationExecutedOkStatus
|
|
67
|
+
| MigrationSkipStatus
|
|
62
68
|
|
|
63
69
|
const isErrorMigrationStatus = (migration: AnyMigrationStatus): migration is ErrorMigrationStatus =>
|
|
64
70
|
[MigrationState.EXECUTED_ERROR, MigrationState.EXECUTED_MISSING, MigrationState.TO_EXECUTE_ERROR].includes(
|
|
@@ -70,7 +76,6 @@ export const sortMigrations = <M extends { version: string }>(migrations: M[]):
|
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
export class MigrationsStatusResolver {
|
|
73
|
-
|
|
74
79
|
async getMigrationsStatus(
|
|
75
80
|
executedMigrations: ExecutedMigrationInfo[],
|
|
76
81
|
localMigrations: MigrationFile[],
|
|
@@ -124,6 +129,16 @@ export class MigrationsStatusResolver {
|
|
|
124
129
|
if (allMigrations.find(it => it.version === localMigration.version)) {
|
|
125
130
|
continue
|
|
126
131
|
}
|
|
132
|
+
const migrationContent = await localMigration.getContent()
|
|
133
|
+
if (isSchemaMigration(migrationContent) && migrationContent.modifications.length === 0) {
|
|
134
|
+
allMigrations.push({
|
|
135
|
+
state: MigrationState.SKIP_EMPTY,
|
|
136
|
+
localMigration,
|
|
137
|
+
version: localMigration.version,
|
|
138
|
+
name: localMigration.name,
|
|
139
|
+
})
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
127
142
|
|
|
128
143
|
if (latestExecuted && latestExecuted.version > localMigration.version) {
|
|
129
144
|
allMigrations.push({
|
|
@@ -148,10 +163,8 @@ export class MigrationsStatusResolver {
|
|
|
148
163
|
allMigrations: allMigrationsSorted,
|
|
149
164
|
errorMigrations: allMigrationsSorted.filter(isErrorMigrationStatus),
|
|
150
165
|
migrationsToExecute: allMigrationsSorted.filter(
|
|
151
|
-
(it): it is MigrationToExecuteOkStatus =>
|
|
152
|
-
it.state === MigrationState.TO_EXECUTE_OK || (force && it.state === MigrationState.TO_EXECUTE_ERROR),
|
|
166
|
+
(it): it is MigrationToExecuteOkStatus => it.state === MigrationState.TO_EXECUTE_OK || (force && it.state === MigrationState.TO_EXECUTE_ERROR),
|
|
153
167
|
),
|
|
154
168
|
}
|
|
155
169
|
}
|
|
156
|
-
|
|
157
170
|
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const schemaMigrations = require("@contember/schema-migrations");
|
|
4
|
-
const JsLoader = require("./src/JsLoader.cjs");
|
|
5
|
-
const JsonLoader = require("./src/JsonLoader.cjs");
|
|
6
|
-
const MigrationCreator = require("./src/MigrationCreator.cjs");
|
|
7
|
-
const MigrationExecuteHelper = require("./src/MigrationExecuteHelper.cjs");
|
|
8
|
-
const MigrationFile = require("./src/MigrationFile.cjs");
|
|
9
|
-
const MigrationFilesManager = require("./src/MigrationFilesManager.cjs");
|
|
10
|
-
const MigrationParser = require("./src/MigrationParser.cjs");
|
|
11
|
-
const migrations = require("./src/migrations.cjs");
|
|
12
|
-
const MigrationsResolver = require("./src/MigrationsResolver.cjs");
|
|
13
|
-
const SchemaVersionBuilder = require("./src/SchemaVersionBuilder.cjs");
|
|
14
|
-
const SystemClient = require("./src/SystemClient.cjs");
|
|
15
|
-
Object.defineProperty(exports, "MigrationDescriber", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: () => schemaMigrations.MigrationDescriber
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "ModificationHandlerFactory", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: () => schemaMigrations.ModificationHandlerFactory
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports, "SchemaDiffer", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: () => schemaMigrations.SchemaDiffer
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(exports, "SchemaMigrator", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: () => schemaMigrations.SchemaMigrator
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "VERSION_LATEST", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: () => schemaMigrations.VERSION_LATEST
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(exports, "calculateMigrationChecksum", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: () => schemaMigrations.calculateMigrationChecksum
|
|
38
|
-
});
|
|
39
|
-
exports.JsLoader = JsLoader.JsLoader;
|
|
40
|
-
exports.JsonLoader = JsonLoader.JsonLoader;
|
|
41
|
-
exports.MigrationCreator = MigrationCreator.MigrationCreator;
|
|
42
|
-
exports.MigrationExecutor = MigrationExecuteHelper.MigrationExecutor;
|
|
43
|
-
exports.isSchemaMigration = MigrationFile.isSchemaMigration;
|
|
44
|
-
exports.MigrationFilesManager = MigrationFilesManager.MigrationFilesManager;
|
|
45
|
-
exports.MigrationParser = MigrationParser.MigrationParser;
|
|
46
|
-
exports.MigrationState = migrations.MigrationState;
|
|
47
|
-
exports.MigrationsStatusResolver = migrations.MigrationsStatusResolver;
|
|
48
|
-
exports.sortMigrations = migrations.sortMigrations;
|
|
49
|
-
exports.MigrationsResolver = MigrationsResolver.MigrationsResolver;
|
|
50
|
-
exports.SchemaVersionBuilder = SchemaVersionBuilder.SchemaVersionBuilder;
|
|
51
|
-
exports.MigrateErrorCode = SystemClient.MigrateErrorCode;
|
|
52
|
-
exports.SystemClient = SystemClient.SystemClient;
|
|
53
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { MigrationDescriber, ModificationHandlerFactory, SchemaDiffer, SchemaMigrator, VERSION_LATEST, calculateMigrationChecksum } from "@contember/schema-migrations";
|
|
2
|
-
import { JsLoader } from "./src/JsLoader.js";
|
|
3
|
-
import { JsonLoader } from "./src/JsonLoader.js";
|
|
4
|
-
import { MigrationCreator } from "./src/MigrationCreator.js";
|
|
5
|
-
import { MigrationExecutor } from "./src/MigrationExecuteHelper.js";
|
|
6
|
-
import { isSchemaMigration } from "./src/MigrationFile.js";
|
|
7
|
-
import { MigrationFilesManager } from "./src/MigrationFilesManager.js";
|
|
8
|
-
import { MigrationParser } from "./src/MigrationParser.js";
|
|
9
|
-
import { MigrationState, MigrationsStatusResolver, sortMigrations } from "./src/migrations.js";
|
|
10
|
-
import { MigrationsResolver } from "./src/MigrationsResolver.js";
|
|
11
|
-
import { SchemaVersionBuilder } from "./src/SchemaVersionBuilder.js";
|
|
12
|
-
import { MigrateErrorCode, SystemClient } from "./src/SystemClient.js";
|
|
13
|
-
export {
|
|
14
|
-
JsLoader,
|
|
15
|
-
JsonLoader,
|
|
16
|
-
MigrateErrorCode,
|
|
17
|
-
MigrationCreator,
|
|
18
|
-
MigrationDescriber,
|
|
19
|
-
MigrationExecutor,
|
|
20
|
-
MigrationFilesManager,
|
|
21
|
-
MigrationParser,
|
|
22
|
-
MigrationState,
|
|
23
|
-
MigrationsResolver,
|
|
24
|
-
MigrationsStatusResolver,
|
|
25
|
-
ModificationHandlerFactory,
|
|
26
|
-
SchemaDiffer,
|
|
27
|
-
SchemaMigrator,
|
|
28
|
-
SchemaVersionBuilder,
|
|
29
|
-
SystemClient,
|
|
30
|
-
VERSION_LATEST,
|
|
31
|
-
calculateMigrationChecksum,
|
|
32
|
-
isSchemaMigration,
|
|
33
|
-
sortMigrations
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
class JsLoader {
|
|
4
|
-
constructor(migrationParser, jsExecutor) {
|
|
5
|
-
this.migrationParser = migrationParser;
|
|
6
|
-
this.jsExecutor = jsExecutor;
|
|
7
|
-
}
|
|
8
|
-
async load(file) {
|
|
9
|
-
const exports2 = await this.jsExecutor(file.path);
|
|
10
|
-
if (!("default" in exports2) && !("query" in exports2) && !("queries" in exports2)) {
|
|
11
|
-
throw `export "default" or "query" is required in ${file.path}`;
|
|
12
|
-
}
|
|
13
|
-
if (typeof exports2.default !== "function") {
|
|
14
|
-
return this.migrationParser.parse(file, exports2.default || exports2);
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
type: "factory",
|
|
18
|
-
factory: async () => {
|
|
19
|
-
const result = await exports2.default();
|
|
20
|
-
const migration = this.migrationParser.parse(file, result ?? { queries: [] });
|
|
21
|
-
if (migration.type !== "content") {
|
|
22
|
-
throw new Error();
|
|
23
|
-
}
|
|
24
|
-
return migration;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.JsLoader = JsLoader;
|
|
30
|
-
//# sourceMappingURL=JsLoader.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JsLoader.cjs","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationParser } from './MigrationParser'\nimport { ContentMigration, MigrationContent, MigrationFile } from './MigrationFile'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\n\t\t// const code = await buildJs(file.path)\n\t\t// const fn = new Function(`var module = {}; ((module) => { ${code} })(module); return module`)\n\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default()\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\n\t\t}\n\t}\n}\n"],"names":["exports"],"mappings":";;AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAAA;AAAA,EAKlB,MAAa,KAAK,MAAgD;AAKjE,UAAMA,WAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC3C,QAAA,EAAE,aAAaA,aAAY,EAAE,WAAWA,aAAY,EAAE,aAAaA,WAAU;AAC1E,YAAA,8CAA8C,KAAK,IAAI;AAAA,IAAA;AAE1D,QAAA,OAAOA,SAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAMA,SAAQ,WAAWA,QAAO;AAAA,IAAA;AAG5D,WAAA;AAAA,MACN,MAAM;AAAA,MACN,SAAS,YAAuC;AACzC,cAAA,SAAS,MAAMA,SAAQ,QAAQ;AAC/B,cAAA,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AACxE,YAAA,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAM;AAAA,QAAA;AAEV,eAAA;AAAA,MAAA;AAAA,IAGT;AAAA,EAAA;AAEF;;"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
class JsLoader {
|
|
2
|
-
constructor(migrationParser, jsExecutor) {
|
|
3
|
-
this.migrationParser = migrationParser;
|
|
4
|
-
this.jsExecutor = jsExecutor;
|
|
5
|
-
}
|
|
6
|
-
async load(file) {
|
|
7
|
-
const exports = await this.jsExecutor(file.path);
|
|
8
|
-
if (!("default" in exports) && !("query" in exports) && !("queries" in exports)) {
|
|
9
|
-
throw `export "default" or "query" is required in ${file.path}`;
|
|
10
|
-
}
|
|
11
|
-
if (typeof exports.default !== "function") {
|
|
12
|
-
return this.migrationParser.parse(file, exports.default || exports);
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
type: "factory",
|
|
16
|
-
factory: async () => {
|
|
17
|
-
const result = await exports.default();
|
|
18
|
-
const migration = this.migrationParser.parse(file, result ?? { queries: [] });
|
|
19
|
-
if (migration.type !== "content") {
|
|
20
|
-
throw new Error();
|
|
21
|
-
}
|
|
22
|
-
return migration;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
JsLoader
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=JsLoader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JsLoader.js","sources":["../../../../packages/migrations-client/src/JsLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport { MigrationParser } from './MigrationParser'\nimport { ContentMigration, MigrationContent, MigrationFile } from './MigrationFile'\n\nexport class JsLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t\tprivate readonly jsExecutor: (file: string) => Promise<any>,\n\t) {\n\t}\n\n\n\tpublic async load(file: MigrationFile): Promise<MigrationContent> {\n\n\t\t// const code = await buildJs(file.path)\n\t\t// const fn = new Function(`var module = {}; ((module) => { ${code} })(module); return module`)\n\n\t\tconst exports = await this.jsExecutor(file.path)\n\t\tif (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {\n\t\t\tthrow `export \"default\" or \"query\" is required in ${file.path}`\n\t\t}\n\t\tif (typeof exports.default !== 'function') {\n\t\t\treturn this.migrationParser.parse(file, exports.default || exports)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'factory',\n\t\t\tfactory: async (): Promise<ContentMigration> => {\n\t\t\t\tconst result = await exports.default()\n\t\t\t\tconst migration = this.migrationParser.parse(file, result ?? { queries: [] })\n\t\t\t\tif (migration.type !== 'content') {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\treturn migration\n\t\t\t},\n\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAIO,MAAM,SAAwC;AAAA,EACpD,YACkB,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EAAA;AAAA,EAKlB,MAAa,KAAK,MAAgD;AAKjE,UAAM,UAAU,MAAM,KAAK,WAAW,KAAK,IAAI;AAC3C,QAAA,EAAE,aAAa,YAAY,EAAE,WAAW,YAAY,EAAE,aAAa,UAAU;AAC1E,YAAA,8CAA8C,KAAK,IAAI;AAAA,IAAA;AAE1D,QAAA,OAAO,QAAQ,YAAY,YAAY;AAC1C,aAAO,KAAK,gBAAgB,MAAM,MAAM,QAAQ,WAAW,OAAO;AAAA,IAAA;AAG5D,WAAA;AAAA,MACN,MAAM;AAAA,MACN,SAAS,YAAuC;AACzC,cAAA,SAAS,MAAM,QAAQ,QAAQ;AAC/B,cAAA,YAAY,KAAK,gBAAgB,MAAM,MAAM,UAAU,EAAE,SAAS,CAAA,GAAI;AACxE,YAAA,UAAU,SAAS,WAAW;AACjC,gBAAM,IAAI,MAAM;AAAA,QAAA;AAEV,eAAA;AAAA,MAAA;AAAA,IAGT;AAAA,EAAA;AAEF;"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fs = require("node:fs/promises");
|
|
4
|
-
function _interopNamespaceDefault(e) {
|
|
5
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
-
if (e) {
|
|
7
|
-
for (const k in e) {
|
|
8
|
-
if (k !== "default") {
|
|
9
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
10
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: () => e[k]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
n.default = e;
|
|
18
|
-
return Object.freeze(n);
|
|
19
|
-
}
|
|
20
|
-
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
21
|
-
class JsonLoader {
|
|
22
|
-
constructor(migrationParser) {
|
|
23
|
-
this.migrationParser = migrationParser;
|
|
24
|
-
}
|
|
25
|
-
async load(file) {
|
|
26
|
-
return this.migrationParser.parse(
|
|
27
|
-
file,
|
|
28
|
-
JSON.parse(await fs__namespace.readFile(file.path, { encoding: "utf8" }))
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.JsonLoader = JsonLoader;
|
|
33
|
-
//# sourceMappingURL=JsonLoader.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JsonLoader.cjs","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser'\nimport { MigrationFile } from './MigrationFile'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAAA;AAAA,EAIlB,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAMA,cAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAC9D;AAAA,EAAA;AAEF;;"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
|
-
class JsonLoader {
|
|
3
|
-
constructor(migrationParser) {
|
|
4
|
-
this.migrationParser = migrationParser;
|
|
5
|
-
}
|
|
6
|
-
async load(file) {
|
|
7
|
-
return this.migrationParser.parse(
|
|
8
|
-
file,
|
|
9
|
-
JSON.parse(await fs.readFile(file.path, { encoding: "utf8" }))
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export {
|
|
14
|
-
JsonLoader
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=JsonLoader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JsonLoader.js","sources":["../../../../packages/migrations-client/src/JsonLoader.ts"],"sourcesContent":["import { MigrationFileLoader } from './MigrationFileLoader'\nimport * as fs from 'node:fs/promises'\nimport { MigrationParser } from './MigrationParser'\nimport { MigrationFile } from './MigrationFile'\n\nexport class JsonLoader implements MigrationFileLoader {\n\tconstructor(\n\t\tprivate readonly migrationParser: MigrationParser,\n\t) {\n\t}\n\n\tpublic async load(file: MigrationFile) {\n\t\treturn this.migrationParser.parse(\n\t\t\tfile,\n\t\t\tJSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,WAA0C;AAAA,EACtD,YACkB,iBAChB;AADgB,SAAA,kBAAA;AAAA,EAAA;AAAA,EAIlB,MAAa,KAAK,MAAqB;AACtC,WAAO,KAAK,gBAAgB;AAAA,MAC3B;AAAA,MACA,KAAK,MAAM,MAAM,GAAG,SAAS,KAAK,MAAM,EAAE,UAAU,QAAQ,CAAC;AAAA,IAC9D;AAAA,EAAA;AAEF;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const schemaMigrations = require("@contember/schema-migrations");
|
|
4
|
-
const engineCommon = require("@contember/engine-common");
|
|
5
|
-
class MigrationCreator {
|
|
6
|
-
constructor(migrationFilesManager, schemaDiffer, emptyTemplates = {}) {
|
|
7
|
-
this.migrationFilesManager = migrationFilesManager;
|
|
8
|
-
this.schemaDiffer = schemaDiffer;
|
|
9
|
-
this.emptyTemplates = emptyTemplates;
|
|
10
|
-
}
|
|
11
|
-
async createEmptyMigrationFile(migrationName, format) {
|
|
12
|
-
if (!this.emptyTemplates.hasOwnProperty(format)) {
|
|
13
|
-
throw new Error(`Unknown format ${format}`);
|
|
14
|
-
}
|
|
15
|
-
await this.migrationFilesManager.createDirIfNotExist();
|
|
16
|
-
const [, fullName] = engineCommon.MigrationVersionHelper.createVersion(migrationName);
|
|
17
|
-
const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
|
|
18
|
-
return filename;
|
|
19
|
-
}
|
|
20
|
-
async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
|
|
21
|
-
await this.migrationFilesManager.createDirIfNotExist();
|
|
22
|
-
const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
|
|
23
|
-
if (modifications.length === 0) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
const migration = this.createMigration(modifications, migrationName);
|
|
27
|
-
return { initialSchema, migration };
|
|
28
|
-
}
|
|
29
|
-
async saveMigration(migration) {
|
|
30
|
-
const jsonDiff = MigrationCreator.createContent(migration);
|
|
31
|
-
const filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name);
|
|
32
|
-
return filename;
|
|
33
|
-
}
|
|
34
|
-
async removeMigration(name) {
|
|
35
|
-
await this.migrationFilesManager.removeFile(name);
|
|
36
|
-
}
|
|
37
|
-
createMigration(modifications, name) {
|
|
38
|
-
const [version, fullName] = engineCommon.MigrationVersionHelper.createVersion(name);
|
|
39
|
-
return { formatVersion: schemaMigrations.VERSION_LATEST, modifications, version, name: fullName };
|
|
40
|
-
}
|
|
41
|
-
static createContent({ modifications, formatVersion }) {
|
|
42
|
-
return JSON.stringify({ formatVersion, modifications }, void 0, " ") + "\n";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.MigrationCreator = MigrationCreator;
|
|
46
|
-
//# sourceMappingURL=MigrationCreator.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationCreator.cjs","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false }: { skipInitialSchemaValidation?: boolean } = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":["MigrationVersionHelper","VERSION_LATEST"],"mappings":";;;;AAKO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,uBACA,cACA,iBAAyC,CAAA,GACzD;AAHgB,SAAA,wBAAA;AACA,SAAA,eAAA;AACA,SAAA,iBAAA;AAAA,EAAA;AAAA,EAGlB,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAAA;AAErC,UAAA,KAAK,sBAAsB,oBAAoB;AACrD,UAAM,CAAG,EAAA,QAAQ,IAAIA,oCAAuB,cAAc,aAAa;AACjE,UAAA,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAEnG,WAAA;AAAA,EAAA;AAAA,EAGR,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,MAAqD,IAAA,IACnB;AAC5D,UAAA,KAAK,sBAAsB,oBAAoB;AAE/C,UAAA,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B;AACzG,QAAA,cAAc,WAAW,GAAG;AACxB,aAAA;AAAA,IAAA;AAGR,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAE5D,WAAA,EAAE,eAAe,UAAU;AAAA,EAAA;AAAA,EAGnC,MAAM,cAAc,WAAuC;AACpD,UAAA,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AAC9E,WAAA;AAAA,EAAA;AAAA,EAGR,MAAM,gBAAgB,MAA6B;AAC5C,UAAA,KAAK,sBAAsB,WAAW,IAAI;AAAA,EAAA;AAAA,EAGzC,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAIA,aAAAA,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAeC,iBAAA,gBAAgB,eAAe,SAAS,MAAM,SAAS;AAAA,EAAA;AAAA,EAGhF,OAAc,cAAc,EAAE,eAAe,iBAAoC;AACzE,WAAA,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAAA;AAE7E;;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { VERSION_LATEST } from "@contember/schema-migrations";
|
|
2
|
-
import { MigrationVersionHelper } from "@contember/engine-common";
|
|
3
|
-
class MigrationCreator {
|
|
4
|
-
constructor(migrationFilesManager, schemaDiffer, emptyTemplates = {}) {
|
|
5
|
-
this.migrationFilesManager = migrationFilesManager;
|
|
6
|
-
this.schemaDiffer = schemaDiffer;
|
|
7
|
-
this.emptyTemplates = emptyTemplates;
|
|
8
|
-
}
|
|
9
|
-
async createEmptyMigrationFile(migrationName, format) {
|
|
10
|
-
if (!this.emptyTemplates.hasOwnProperty(format)) {
|
|
11
|
-
throw new Error(`Unknown format ${format}`);
|
|
12
|
-
}
|
|
13
|
-
await this.migrationFilesManager.createDirIfNotExist();
|
|
14
|
-
const [, fullName] = MigrationVersionHelper.createVersion(migrationName);
|
|
15
|
-
const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format);
|
|
16
|
-
return filename;
|
|
17
|
-
}
|
|
18
|
-
async prepareMigration(initialSchema, newSchema, migrationName, { skipInitialSchemaValidation = false } = {}) {
|
|
19
|
-
await this.migrationFilesManager.createDirIfNotExist();
|
|
20
|
-
const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation });
|
|
21
|
-
if (modifications.length === 0) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const migration = this.createMigration(modifications, migrationName);
|
|
25
|
-
return { initialSchema, migration };
|
|
26
|
-
}
|
|
27
|
-
async saveMigration(migration) {
|
|
28
|
-
const jsonDiff = MigrationCreator.createContent(migration);
|
|
29
|
-
const filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name);
|
|
30
|
-
return filename;
|
|
31
|
-
}
|
|
32
|
-
async removeMigration(name) {
|
|
33
|
-
await this.migrationFilesManager.removeFile(name);
|
|
34
|
-
}
|
|
35
|
-
createMigration(modifications, name) {
|
|
36
|
-
const [version, fullName] = MigrationVersionHelper.createVersion(name);
|
|
37
|
-
return { formatVersion: VERSION_LATEST, modifications, version, name: fullName };
|
|
38
|
-
}
|
|
39
|
-
static createContent({ modifications, formatVersion }) {
|
|
40
|
-
return JSON.stringify({ formatVersion, modifications }, void 0, " ") + "\n";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
MigrationCreator
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=MigrationCreator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationCreator.js","sources":["../../../../packages/migrations-client/src/MigrationCreator.ts"],"sourcesContent":["import { MigrationFilesManager } from './MigrationFilesManager'\nimport { Schema } from '@contember/schema'\nimport { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'\nimport { MigrationVersionHelper } from '@contember/engine-common'\n\nexport class MigrationCreator {\n\tconstructor(\n\t\tprivate readonly migrationFilesManager: MigrationFilesManager,\n\t\tprivate readonly schemaDiffer: SchemaDiffer,\n\t\tprivate readonly emptyTemplates: Record<string, string> = {},\n\t) {}\n\n\tasync createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {\n\t\tif (!this.emptyTemplates.hasOwnProperty(format)) {\n\t\t\tthrow new Error(`Unknown format ${format}`)\n\t\t}\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\t\tconst [, fullName] = MigrationVersionHelper.createVersion(migrationName)\n\t\tconst filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)\n\n\t\treturn filename\n\t}\n\n\tasync prepareMigration(\n\t\tinitialSchema: Schema,\n\t\tnewSchema: Schema,\n\t\tmigrationName: string,\n\t\t{ skipInitialSchemaValidation = false }: { skipInitialSchemaValidation?: boolean } = {},\n\t): Promise<{ migration: Migration; initialSchema: Schema } | null> {\n\t\tawait this.migrationFilesManager.createDirIfNotExist()\n\n\t\tconst modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation })\n\t\tif (modifications.length === 0) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst migration = this.createMigration(modifications, migrationName)\n\n\t\treturn { initialSchema, migration }\n\t}\n\n\tasync saveMigration(migration: Migration): Promise<string> {\n\t\tconst jsonDiff = MigrationCreator.createContent(migration)\n\t\tconst filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)\n\t\treturn filename\n\t}\n\n\tasync removeMigration(name: string): Promise<void> {\n\t\tawait this.migrationFilesManager.removeFile(name)\n\t}\n\n\tprivate createMigration(modifications: Migration.Modification[], name: string): Migration {\n\t\tconst [version, fullName] = MigrationVersionHelper.createVersion(name)\n\t\treturn { formatVersion: VERSION_LATEST, modifications, version, name: fullName }\n\t}\n\n\tpublic static createContent({ modifications, formatVersion }: Migration): string {\n\t\treturn JSON.stringify({ formatVersion, modifications }, undefined, '\\t') + '\\n'\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,iBAAiB;AAAA,EAC7B,YACkB,uBACA,cACA,iBAAyC,CAAA,GACzD;AAHgB,SAAA,wBAAA;AACA,SAAA,eAAA;AACA,SAAA,iBAAA;AAAA,EAAA;AAAA,EAGlB,MAAM,yBAAyB,eAAuB,QAAiC;AACtF,QAAI,CAAC,KAAK,eAAe,eAAe,MAAM,GAAG;AAChD,YAAM,IAAI,MAAM,kBAAkB,MAAM,EAAE;AAAA,IAAA;AAErC,UAAA,KAAK,sBAAsB,oBAAoB;AACrD,UAAM,CAAG,EAAA,QAAQ,IAAI,uBAAuB,cAAc,aAAa;AACjE,UAAA,WAAW,MAAM,KAAK,sBAAsB,WAAW,KAAK,eAAe,MAAM,GAAG,UAAU,MAAM;AAEnG,WAAA;AAAA,EAAA;AAAA,EAGR,MAAM,iBACL,eACA,WACA,eACA,EAAE,8BAA8B,MAAqD,IAAA,IACnB;AAC5D,UAAA,KAAK,sBAAsB,oBAAoB;AAE/C,UAAA,gBAAgB,KAAK,aAAa,YAAY,eAAe,WAAW,EAAE,6BAA6B;AACzG,QAAA,cAAc,WAAW,GAAG;AACxB,aAAA;AAAA,IAAA;AAGR,UAAM,YAAY,KAAK,gBAAgB,eAAe,aAAa;AAE5D,WAAA,EAAE,eAAe,UAAU;AAAA,EAAA;AAAA,EAGnC,MAAM,cAAc,WAAuC;AACpD,UAAA,WAAW,iBAAiB,cAAc,SAAS;AACzD,UAAM,WAAW,MAAM,KAAK,sBAAsB,WAAW,UAAU,UAAU,IAAI;AAC9E,WAAA;AAAA,EAAA;AAAA,EAGR,MAAM,gBAAgB,MAA6B;AAC5C,UAAA,KAAK,sBAAsB,WAAW,IAAI;AAAA,EAAA;AAAA,EAGzC,gBAAgB,eAAyC,MAAyB;AACzF,UAAM,CAAC,SAAS,QAAQ,IAAI,uBAAuB,cAAc,IAAI;AACrE,WAAO,EAAE,eAAe,gBAAgB,eAAe,SAAS,MAAM,SAAS;AAAA,EAAA;AAAA,EAGhF,OAAc,cAAc,EAAE,eAAe,iBAAoC;AACzE,WAAA,KAAK,UAAU,EAAE,eAAe,iBAAiB,QAAW,GAAI,IAAI;AAAA,EAAA;AAE7E;"}
|