@contember/cli 1.4.0-alpha.3 → 1.4.0-alpha.5
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/src/commands/deploy/DeployCommand.js +2 -2
- package/dist/src/commands/deploy/DeployCommand.js.map +1 -1
- package/dist/src/commands/migrations/MigrationDiffCommand.js +2 -2
- package/dist/src/commands/migrations/MigrationDiffCommand.js.map +1 -1
- package/dist/src/commands/migrations/MigrationExecuteCommand.js +2 -2
- package/dist/src/commands/migrations/MigrationExecuteCommand.js.map +1 -1
- package/dist/src/commands/migrations/MigrationStatusCommand.d.ts.map +1 -1
- package/dist/src/commands/migrations/MigrationStatusCommand.js +5 -4
- package/dist/src/commands/migrations/MigrationStatusCommand.js.map +1 -1
- package/dist/src/commands/migrations/SystemApiClientResolver.d.ts +1 -1
- package/dist/src/commands/migrations/SystemApiClientResolver.d.ts.map +1 -1
- package/dist/src/commands/migrations/SystemApiClientResolver.js +2 -2
- package/dist/src/commands/migrations/SystemApiClientResolver.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/utils/migrations/MigrationCreateHelper.d.ts +1 -5
- package/dist/src/utils/migrations/MigrationCreateHelper.d.ts.map +1 -1
- package/dist/src/utils/migrations/MigrationCreateHelper.js.map +1 -1
- package/dist/src/utils/migrations/MigrationExecuteHelper.d.ts +6 -7
- package/dist/src/utils/migrations/MigrationExecuteHelper.d.ts.map +1 -1
- package/dist/src/utils/migrations/MigrationExecuteHelper.js +12 -52
- package/dist/src/utils/migrations/MigrationExecuteHelper.js.map +1 -1
- package/dist/src/utils/migrations/MigrationsContainer.d.ts +4 -4
- package/dist/src/utils/migrations/MigrationsContainer.d.ts.map +1 -1
- package/dist/src/utils/migrations/MigrationsContainer.js +23 -15
- package/dist/src/utils/migrations/MigrationsContainer.js.map +1 -1
- package/dist/src/utils/migrations/migrations.d.ts +2 -54
- package/dist/src/utils/migrations/migrations.d.ts.map +1 -1
- package/dist/src/utils/migrations/migrations.js +7 -88
- package/dist/src/utils/migrations/migrations.js.map +1 -1
- package/package.json +10 -10
- package/src/commands/deploy/DeployCommand.ts +1 -1
- package/src/commands/migrations/MigrationDiffCommand.ts +1 -1
- package/src/commands/migrations/MigrationExecuteCommand.ts +1 -1
- package/src/commands/migrations/MigrationStatusCommand.ts +3 -2
- package/src/commands/migrations/SystemApiClientResolver.ts +1 -1
- package/src/tsconfig.json +1 -1
- package/src/utils/migrations/MigrationCreateHelper.ts +8 -5
- package/src/utils/migrations/MigrationExecuteHelper.ts +23 -61
- package/src/utils/migrations/MigrationsContainer.ts +20 -12
- package/src/utils/migrations/migrations.ts +3 -148
- package/dist/src/utils/migrations/JsLoader.d.ts +0 -9
- package/dist/src/utils/migrations/JsLoader.d.ts.map +0 -1
- package/dist/src/utils/migrations/JsLoader.js +0 -33
- package/dist/src/utils/migrations/JsLoader.js.map +0 -1
- package/dist/src/utils/migrations/JsonLoader.d.ts +0 -9
- package/dist/src/utils/migrations/JsonLoader.d.ts.map +0 -1
- package/dist/src/utils/migrations/JsonLoader.js +0 -17
- package/dist/src/utils/migrations/JsonLoader.js.map +0 -1
- package/dist/src/utils/migrations/MigrationCreator.d.ts +0 -21
- package/dist/src/utils/migrations/MigrationCreator.d.ts.map +0 -1
- package/dist/src/utils/migrations/MigrationCreator.js +0 -47
- package/dist/src/utils/migrations/MigrationCreator.js.map +0 -1
- package/dist/src/utils/migrations/MigrationFile.d.ts +0 -36
- package/dist/src/utils/migrations/MigrationFile.d.ts.map +0 -1
- package/dist/src/utils/migrations/MigrationFile.js +0 -6
- package/dist/src/utils/migrations/MigrationFile.js.map +0 -1
- package/dist/src/utils/migrations/MigrationFileLoader.d.ts +0 -5
- package/dist/src/utils/migrations/MigrationFileLoader.d.ts.map +0 -1
- package/dist/src/utils/migrations/MigrationFileLoader.js +0 -3
- package/dist/src/utils/migrations/MigrationFileLoader.js.map +0 -1
- package/dist/src/utils/migrations/MigrationFilesManager.d.ts +0 -18
- package/dist/src/utils/migrations/MigrationFilesManager.d.ts.map +0 -1
- package/dist/src/utils/migrations/MigrationFilesManager.js +0 -114
- package/dist/src/utils/migrations/MigrationFilesManager.js.map +0 -1
- package/dist/src/utils/migrations/MigrationParser.d.ts +0 -6
- package/dist/src/utils/migrations/MigrationParser.d.ts.map +0 -1
- package/dist/src/utils/migrations/MigrationParser.js +0 -33
- package/dist/src/utils/migrations/MigrationParser.js.map +0 -1
- package/dist/src/utils/migrations/MigrationsResolver.d.ts +0 -14
- package/dist/src/utils/migrations/MigrationsResolver.d.ts.map +0 -1
- package/dist/src/utils/migrations/MigrationsResolver.js +0 -37
- package/dist/src/utils/migrations/MigrationsResolver.js.map +0 -1
- package/dist/src/utils/migrations/SchemaVersionBuilder.d.ts +0 -13
- package/dist/src/utils/migrations/SchemaVersionBuilder.d.ts.map +0 -1
- package/dist/src/utils/migrations/SchemaVersionBuilder.js +0 -26
- package/dist/src/utils/migrations/SchemaVersionBuilder.js.map +0 -1
- package/dist/src/utils/system/index.d.ts +0 -30
- package/dist/src/utils/system/index.d.ts.map +0 -1
- package/dist/src/utils/system/index.js +0 -118
- package/dist/src/utils/system/index.js.map +0 -1
- package/src/utils/migrations/JsLoader.ts +0 -37
- package/src/utils/migrations/JsonLoader.ts +0 -18
- package/src/utils/migrations/MigrationCreator.ts +0 -60
- package/src/utils/migrations/MigrationFile.ts +0 -52
- package/src/utils/migrations/MigrationFileLoader.ts +0 -5
- package/src/utils/migrations/MigrationFilesManager.ts +0 -102
- package/src/utils/migrations/MigrationParser.ts +0 -32
- package/src/utils/migrations/MigrationsResolver.ts +0 -44
- package/src/utils/migrations/SchemaVersionBuilder.ts +0 -33
- package/src/utils/system/index.ts +0 -150
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.MigrationFilesManager = void 0;
|
|
27
|
-
const engine_common_1 = require("@contember/engine-common");
|
|
28
|
-
const fs = __importStar(require("node:fs/promises"));
|
|
29
|
-
const node_path_1 = require("node:path");
|
|
30
|
-
class MigrationFilesManager {
|
|
31
|
-
constructor(directory, loaders) {
|
|
32
|
-
this.directory = directory;
|
|
33
|
-
this.loaders = loaders;
|
|
34
|
-
this.migrations = null;
|
|
35
|
-
}
|
|
36
|
-
async createFile(content, name, extension = 'json') {
|
|
37
|
-
this.migrations = null;
|
|
38
|
-
const path = this.formatPath(name, extension);
|
|
39
|
-
await fs.writeFile(path, content, { encoding: 'utf8' });
|
|
40
|
-
return await fs.realpath(path);
|
|
41
|
-
}
|
|
42
|
-
async removeFile(name) {
|
|
43
|
-
this.migrations = null;
|
|
44
|
-
const path = this.formatPath(name);
|
|
45
|
-
await fs.unlink(path);
|
|
46
|
-
}
|
|
47
|
-
async moveFile(oldName, newName) {
|
|
48
|
-
this.migrations = null;
|
|
49
|
-
await fs.rename(this.formatPath(oldName), this.formatPath(newName));
|
|
50
|
-
}
|
|
51
|
-
async createDirIfNotExist() {
|
|
52
|
-
try {
|
|
53
|
-
await fs.mkdir(this.directory);
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
if (!(e instanceof Error) || !('code' in e) || e.code !== 'EEXIST') {
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async readFiles() {
|
|
62
|
-
var _a;
|
|
63
|
-
return (_a = this.migrations) !== null && _a !== void 0 ? _a : (this.migrations = this.forceReadFiles());
|
|
64
|
-
}
|
|
65
|
-
async forceReadFiles() {
|
|
66
|
-
const files = (await this.listFiles()).map(it => ({
|
|
67
|
-
filename: it,
|
|
68
|
-
version: engine_common_1.MigrationVersionHelper.extractVersion(it),
|
|
69
|
-
}));
|
|
70
|
-
return files.map(({ version, filename }) => {
|
|
71
|
-
const ext = filename.substring(filename.lastIndexOf('.') + 1);
|
|
72
|
-
const path = (0, node_path_1.join)(this.directory, filename);
|
|
73
|
-
let content = null;
|
|
74
|
-
const file = {
|
|
75
|
-
path: path,
|
|
76
|
-
version: version,
|
|
77
|
-
name: engine_common_1.MigrationVersionHelper.extractName(path.substring(path.lastIndexOf('/') + 1)),
|
|
78
|
-
getContent: () => {
|
|
79
|
-
content !== null && content !== void 0 ? content : (content = this.loaders[ext].load(file));
|
|
80
|
-
return content;
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
return file;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async tryReadDir() {
|
|
87
|
-
try {
|
|
88
|
-
return await fs.readdir(this.directory, { withFileTypes: true });
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
throw e;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async listFiles() {
|
|
98
|
-
const files = await this.tryReadDir();
|
|
99
|
-
const extensions = Object.keys(this.loaders).join('|');
|
|
100
|
-
const regex = new RegExp('^\\d{4}-\\d{2}-\\d{2}-\\d{6}-[\\w-]+\\.(' + extensions + ')$');
|
|
101
|
-
const filteredFiles = await Promise.all(files
|
|
102
|
-
.filter(it => it.isFile())
|
|
103
|
-
.map(it => it.name)
|
|
104
|
-
.filter(it => it.match(regex)));
|
|
105
|
-
return filteredFiles.sort();
|
|
106
|
-
}
|
|
107
|
-
formatPath(version, extension = 'json') {
|
|
108
|
-
const filename = `${version}.${extension}`;
|
|
109
|
-
const path = `${this.directory}/${filename}`;
|
|
110
|
-
return path;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.MigrationFilesManager = MigrationFilesManager;
|
|
114
|
-
//# sourceMappingURL=MigrationFilesManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationFilesManager.js","sourceRoot":"","sources":["../../../../src/utils/migrations/MigrationFilesManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAiE;AACjE,qDAAsC;AAGtC,yCAAgC;AAGhC,MAAa,qBAAqB;IAGjC,YACiB,SAAiB,EAChB,OAA4C;QAD7C,cAAS,GAAT,SAAS,CAAQ;QAChB,YAAO,GAAP,OAAO,CAAqC;QAJtD,eAAU,GAAoC,IAAI,CAAA;IAKvD,CAAC;IAEG,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,IAAY,EAAE,SAAS,GAAG,MAAM;QACxE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAC7C,MAAM,EAAE,CAAC,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MAAM,IAAI,CAAC,UAAU,EAAE,CAAA;QAErC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACtD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,0CAA0C,GAAG,UAAU,GAAI,IAAI,CAAC,CAAA;QACzF,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CACtC,KAAK;aACH,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;aACzB,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;aAClB,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAC/B,CAAA;QAED,OAAO,aAAa,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;IAEO,UAAU,CAAC,OAAe,EAAE,SAAS,GAAG,MAAM;QACrD,MAAM,QAAQ,GAAG,GAAG,OAAO,IAAI,SAAS,EAAE,CAAA;QAC1C,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,IAAI,QAAQ,EAAE,CAAA;QAC5C,OAAO,IAAI,CAAA;IACZ,CAAC;CACD;AA9FD,sDA8FC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { JSONValue } from '@contember/cli-common';
|
|
2
|
-
import { MigrationFile, ResolvedMigrationContent } from './MigrationFile';
|
|
3
|
-
export declare class MigrationParser {
|
|
4
|
-
parse(migrationFile: MigrationFile, content: JSONValue): ResolvedMigrationContent;
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=MigrationParser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationParser.d.ts","sourceRoot":"","sources":["../../../../src/utils/migrations/MigrationParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,EAAyB,aAAa,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAEhG,qBAAa,eAAe;IACpB,KAAK,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,GAAG,wBAAwB;CA0BxF"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MigrationParser = void 0;
|
|
4
|
-
const schema_migrations_1 = require("@contember/schema-migrations");
|
|
5
|
-
class MigrationParser {
|
|
6
|
-
parse(migrationFile, content) {
|
|
7
|
-
if (typeof content !== 'object' || content === null) {
|
|
8
|
-
throw new Error('Invalid migration');
|
|
9
|
-
}
|
|
10
|
-
if ('modifications' in content) {
|
|
11
|
-
const validated = content; // todo validate
|
|
12
|
-
return {
|
|
13
|
-
type: 'schema',
|
|
14
|
-
version: migrationFile.version,
|
|
15
|
-
name: migrationFile.name,
|
|
16
|
-
formatVersion: validated.formatVersion || schema_migrations_1.VERSION_INITIAL,
|
|
17
|
-
modifications: validated.modifications,
|
|
18
|
-
...(validated.skippedErrors ? { skippedErrors: validated.skippedErrors } : {}),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
else if ('queries' in content || 'query' in content) {
|
|
22
|
-
return {
|
|
23
|
-
type: 'content',
|
|
24
|
-
version: migrationFile.version,
|
|
25
|
-
name: migrationFile.name,
|
|
26
|
-
queries: ('queries' in content ? content.queries : [content]),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
throw new Error('Invalid migration content');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.MigrationParser = MigrationParser;
|
|
33
|
-
//# sourceMappingURL=MigrationParser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationParser.js","sourceRoot":"","sources":["../../../../src/utils/migrations/MigrationParser.ts"],"names":[],"mappings":";;;AACA,oEAAyE;AAGzE,MAAa,eAAe;IACpB,KAAK,CAAC,aAA4B,EAAE,OAAkB;QAC5D,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE;YACpD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;SACpC;QAED,IAAI,eAAe,IAAI,OAAO,EAAE;YAC/B,MAAM,SAAS,GAAG,OAAoB,CAAA,CAAC,gBAAgB;YAEvD,OAAO;gBACN,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,IAAI,EAAE,aAAa,CAAC,IAAI;gBACxB,aAAa,EAAE,SAAS,CAAC,aAAa,IAAI,mCAAe;gBACzD,aAAa,EAAE,SAAS,CAAC,aAAa;gBACtC,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9E,CAAA;SACD;aAAM,IAAI,SAAS,IAAI,OAAO,IAAI,OAAO,IAAI,OAAO,EAAE;YACtD,OAAO;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,IAAI,EAAE,aAAa,CAAC,IAAI;gBACxB,OAAO,EAAE,CAAC,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAA4B;aACxF,CAAA;SACD;QACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAC7C,CAAC;CACD;AA3BD,0CA2BC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { MigrationFilesManager } from './MigrationFilesManager';
|
|
2
|
-
import { Migration } from '@contember/schema-migrations';
|
|
3
|
-
import { MigrationFile } from './MigrationFile';
|
|
4
|
-
export declare class MigrationsResolver {
|
|
5
|
-
private readonly migrationFilesManager;
|
|
6
|
-
constructor(migrationFilesManager: MigrationFilesManager);
|
|
7
|
-
get directory(): string;
|
|
8
|
-
getMigrationFiles(): Promise<MigrationFile[]>;
|
|
9
|
-
getSchemaMigrations(): Promise<Migration[]>;
|
|
10
|
-
findLatestSchemaMigration(): Promise<Migration | null>;
|
|
11
|
-
findSchemaMigrationByVersion(version: string): Promise<Migration | null>;
|
|
12
|
-
private convertMigrationFileToSchemaMigration;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=MigrationsResolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationsResolver.d.ts","sourceRoot":"","sources":["../../../../src/utils/migrations/MigrationsResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAqB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAGlE,qBAAa,kBAAkB;IAElB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;gBAArB,qBAAqB,EAAE,qBAAqB;IAEzE,IAAW,SAAS,IAAI,MAAM,CAE7B;IAEY,iBAAiB,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI7C,mBAAmB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAQ3C,yBAAyB,IAAI,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAKtD,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;YASvE,qCAAqC;CAInD"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MigrationsResolver = void 0;
|
|
4
|
-
const MigrationFile_1 = require("./MigrationFile");
|
|
5
|
-
const engine_common_1 = require("@contember/engine-common");
|
|
6
|
-
class MigrationsResolver {
|
|
7
|
-
constructor(migrationFilesManager) {
|
|
8
|
-
this.migrationFilesManager = migrationFilesManager;
|
|
9
|
-
}
|
|
10
|
-
get directory() {
|
|
11
|
-
return this.migrationFilesManager.directory;
|
|
12
|
-
}
|
|
13
|
-
async getMigrationFiles() {
|
|
14
|
-
return await this.migrationFilesManager.readFiles();
|
|
15
|
-
}
|
|
16
|
-
async getSchemaMigrations() {
|
|
17
|
-
const migrationFiles = await this.getMigrationFiles();
|
|
18
|
-
const migrations = await Promise.all(migrationFiles.map(this.convertMigrationFileToSchemaMigration));
|
|
19
|
-
return migrations.filter((it) => it !== null);
|
|
20
|
-
}
|
|
21
|
-
async findLatestSchemaMigration() {
|
|
22
|
-
const migrations = await this.getSchemaMigrations();
|
|
23
|
-
return migrations.length > 0 ? migrations[migrations.length - 1] : null;
|
|
24
|
-
}
|
|
25
|
-
async findSchemaMigrationByVersion(version) {
|
|
26
|
-
var _a;
|
|
27
|
-
const migrations = await this.getSchemaMigrations();
|
|
28
|
-
return (_a = migrations
|
|
29
|
-
.find(it => engine_common_1.MigrationVersionHelper.extractVersion(it.version) === engine_common_1.MigrationVersionHelper.extractVersion(version))) !== null && _a !== void 0 ? _a : null;
|
|
30
|
-
}
|
|
31
|
-
async convertMigrationFileToSchemaMigration(file) {
|
|
32
|
-
const result = await file.getContent();
|
|
33
|
-
return (0, MigrationFile_1.isSchemaMigration)(result) ? result : null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.MigrationsResolver = MigrationsResolver;
|
|
37
|
-
//# sourceMappingURL=MigrationsResolver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationsResolver.js","sourceRoot":"","sources":["../../../../src/utils/migrations/MigrationsResolver.ts"],"names":[],"mappings":";;;AAEA,mDAAkE;AAClE,4DAAiE;AAEjE,MAAa,kBAAkB;IAE9B,YAA6B,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;IAAG,CAAC;IAE7E,IAAW,SAAS;QACnB,OAAO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gDAsCC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@contember/schema';
|
|
2
|
-
import { SchemaMigrator } from '@contember/schema-migrations';
|
|
3
|
-
import { MigrationsResolver } from './MigrationsResolver';
|
|
4
|
-
export declare class SchemaVersionBuilder {
|
|
5
|
-
private readonly migrationsResolver;
|
|
6
|
-
private readonly schemaMigrator;
|
|
7
|
-
constructor(migrationsResolver: MigrationsResolver, schemaMigrator: SchemaMigrator);
|
|
8
|
-
buildSchema(targetVersion?: string): Promise<Schema>;
|
|
9
|
-
buildSchemaUntil(targetVersion: string): Promise<Schema>;
|
|
10
|
-
continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema>;
|
|
11
|
-
buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=SchemaVersionBuilder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaVersionBuilder.d.ts","sourceRoot":"","sources":["../../../../src/utils/migrations/SchemaVersionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,qBAAa,oBAAoB;IAE/B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc;gBADd,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,cAAc;IAG1C,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIpD,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzF,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CASjH"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaVersionBuilder = void 0;
|
|
4
|
-
const schema_utils_1 = require("@contember/schema-utils");
|
|
5
|
-
class SchemaVersionBuilder {
|
|
6
|
-
constructor(migrationsResolver, schemaMigrator) {
|
|
7
|
-
this.migrationsResolver = migrationsResolver;
|
|
8
|
-
this.schemaMigrator = schemaMigrator;
|
|
9
|
-
}
|
|
10
|
-
async buildSchema(targetVersion) {
|
|
11
|
-
return this.buildSchemaAdvanced(schema_utils_1.emptySchema, version => !targetVersion || version <= targetVersion);
|
|
12
|
-
}
|
|
13
|
-
async buildSchemaUntil(targetVersion) {
|
|
14
|
-
return this.buildSchemaAdvanced(schema_utils_1.emptySchema, version => version < targetVersion);
|
|
15
|
-
}
|
|
16
|
-
async continue(schema, previousVersion, targetVersion) {
|
|
17
|
-
return this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''));
|
|
18
|
-
}
|
|
19
|
-
async buildSchemaAdvanced(initialSchema, condition) {
|
|
20
|
-
return (await this.migrationsResolver.getSchemaMigrations())
|
|
21
|
-
.filter(({ version }) => condition(version))
|
|
22
|
-
.reduce((schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion), initialSchema);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.SchemaVersionBuilder = SchemaVersionBuilder;
|
|
26
|
-
//# sourceMappingURL=SchemaVersionBuilder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaVersionBuilder.js","sourceRoot":"","sources":["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
-
import { GraphQLClient } from 'graphql-request';
|
|
2
|
-
import { ExecutedMigration, ExecutedMigrationInfo } from '../migrations/migrations';
|
|
3
|
-
export type MigrateError = {
|
|
4
|
-
readonly code: MigrateErrorCode;
|
|
5
|
-
readonly migration: string;
|
|
6
|
-
readonly message: string;
|
|
7
|
-
};
|
|
8
|
-
export declare enum MigrateErrorCode {
|
|
9
|
-
MustFollowLatest = "MUST_FOLLOW_LATEST",
|
|
10
|
-
AlreadyExecuted = "ALREADY_EXECUTED",
|
|
11
|
-
InvalidFormat = "INVALID_FORMAT",
|
|
12
|
-
InvalidSchema = "INVALID_SCHEMA",
|
|
13
|
-
MigrationFailed = "MIGRATION_FAILED"
|
|
14
|
-
}
|
|
15
|
-
export type MigrateResponse = {
|
|
16
|
-
readonly ok: boolean;
|
|
17
|
-
readonly errors: MigrateError[];
|
|
18
|
-
};
|
|
19
|
-
export declare const createSystemUrl: (baseUrl: string, projectName: string) => string;
|
|
20
|
-
export declare class SystemClient {
|
|
21
|
-
private readonly apiClient;
|
|
22
|
-
constructor(apiClient: GraphQLClient);
|
|
23
|
-
static create(baseUrl: string, projectName: string, apiToken: string): SystemClient;
|
|
24
|
-
migrate(migrations: any[], force?: boolean): Promise<void>;
|
|
25
|
-
migrationDelete(version: string): Promise<void>;
|
|
26
|
-
migrationModify(version: string, modification: Partial<any>): Promise<void>;
|
|
27
|
-
listExecutedMigrations(): Promise<ExecutedMigrationInfo[]>;
|
|
28
|
-
getExecutedMigration(version: string): Promise<ExecutedMigration>;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/system/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAEnF,MAAM,MA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4
|
-
const graphql_request_1 = require("graphql-request");
|
|
5
|
-
var MigrateErrorCode;
|
|
6
|
-
(function (MigrateErrorCode) {
|
|
7
|
-
MigrateErrorCode["MustFollowLatest"] = "MUST_FOLLOW_LATEST";
|
|
8
|
-
MigrateErrorCode["AlreadyExecuted"] = "ALREADY_EXECUTED";
|
|
9
|
-
MigrateErrorCode["InvalidFormat"] = "INVALID_FORMAT";
|
|
10
|
-
MigrateErrorCode["InvalidSchema"] = "INVALID_SCHEMA";
|
|
11
|
-
MigrateErrorCode["MigrationFailed"] = "MIGRATION_FAILED";
|
|
12
|
-
})(MigrateErrorCode || (exports.MigrateErrorCode = MigrateErrorCode = {}));
|
|
13
|
-
const createSystemUrl = (baseUrl, projectName) => {
|
|
14
|
-
if (baseUrl.endsWith('/')) {
|
|
15
|
-
baseUrl = baseUrl.substring(0, baseUrl.length - 1);
|
|
16
|
-
}
|
|
17
|
-
return baseUrl + '/system/' + projectName;
|
|
18
|
-
};
|
|
19
|
-
exports.createSystemUrl = createSystemUrl;
|
|
20
|
-
class SystemClient {
|
|
21
|
-
constructor(apiClient) {
|
|
22
|
-
this.apiClient = apiClient;
|
|
23
|
-
}
|
|
24
|
-
static create(baseUrl, projectName, apiToken) {
|
|
25
|
-
const graphqlClient = new graphql_request_1.GraphQLClient((0, exports.createSystemUrl)(baseUrl, projectName), {
|
|
26
|
-
headers: {
|
|
27
|
-
Authorization: `Bearer ${apiToken}`,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
return new SystemClient(graphqlClient);
|
|
31
|
-
}
|
|
32
|
-
async migrate(migrations, force = false) {
|
|
33
|
-
const query = `
|
|
34
|
-
mutation($migrations: [Migration!]!) {
|
|
35
|
-
migrate: ${force ? 'forceMigrate' : 'migrate'}(migrations: $migrations) {
|
|
36
|
-
ok
|
|
37
|
-
errors {
|
|
38
|
-
code
|
|
39
|
-
migration
|
|
40
|
-
message: developerMessage
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
45
|
-
const result = (await this.apiClient.request(query, {
|
|
46
|
-
migrations,
|
|
47
|
-
})).migrate;
|
|
48
|
-
if (!result.ok) {
|
|
49
|
-
throw result.errors;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async migrationDelete(version) {
|
|
53
|
-
var _a;
|
|
54
|
-
const query = `
|
|
55
|
-
mutation($version: String!) {
|
|
56
|
-
migrationDelete(migration: $version) {
|
|
57
|
-
ok
|
|
58
|
-
error {
|
|
59
|
-
developerMessage
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
`;
|
|
64
|
-
const result = (await this.apiClient.request(query, {
|
|
65
|
-
version,
|
|
66
|
-
})).migrationDelete;
|
|
67
|
-
if (!result.ok) {
|
|
68
|
-
throw (_a = result.error) === null || _a === void 0 ? void 0 : _a.developerMessage;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async migrationModify(version, modification) {
|
|
72
|
-
var _a;
|
|
73
|
-
const query = `
|
|
74
|
-
mutation($version: String!, $modification: MigrationModification!) {
|
|
75
|
-
migrationModify(migration: $version, modification: $modification) {
|
|
76
|
-
ok
|
|
77
|
-
error {
|
|
78
|
-
developerMessage
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
`;
|
|
83
|
-
const result = (await this.apiClient.request(query, {
|
|
84
|
-
version,
|
|
85
|
-
modification,
|
|
86
|
-
})).migrationModify;
|
|
87
|
-
if (!result.ok) {
|
|
88
|
-
throw (_a = result.error) === null || _a === void 0 ? void 0 : _a.developerMessage;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async listExecutedMigrations() {
|
|
92
|
-
const query = `query {
|
|
93
|
-
executedMigrations {
|
|
94
|
-
name
|
|
95
|
-
version
|
|
96
|
-
formatVersion
|
|
97
|
-
checksum
|
|
98
|
-
executedAt
|
|
99
|
-
}
|
|
100
|
-
}`;
|
|
101
|
-
return (await this.apiClient.request(query, {})).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }));
|
|
102
|
-
}
|
|
103
|
-
async getExecutedMigration(version) {
|
|
104
|
-
const query = `query($version: String!) {
|
|
105
|
-
executedMigrations(version: $version) {
|
|
106
|
-
name
|
|
107
|
-
version
|
|
108
|
-
formatVersion
|
|
109
|
-
checksum
|
|
110
|
-
executedAt
|
|
111
|
-
modifications
|
|
112
|
-
}
|
|
113
|
-
}`;
|
|
114
|
-
return ((await this.apiClient.request(query, { version })).executedMigrations.map(it => ({ ...it, executedAt: new Date(it.executedAt) }))[0] || null);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.SystemClient = SystemClient;
|
|
118
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/system/index.ts"],"names":[],"mappings":";;;AAAA,qDAA+C;AAS/C,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC3B,2DAAuC,CAAA;IACvC,wDAAoC,CAAA;IACpC,oDAAgC,CAAA;IAChC,oDAAgC,CAAA;IAChC,wDAAoC,CAAA;AACrC,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAOM,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,WAAmB,EAAE,EAAE;IACvE,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC1B,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;KAClD;IACD,OAAO,OAAO,GAAG,UAAU,GAAG,WAAW,CAAA;AAC1C,CAAC,CAAA;AALY,QAAA,eAAe,mBAK3B;AAED,MAAa,YAAY;IACxB,YAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;IAAG,CAAC;IAElD,MAAM,CAAC,MAAM,CAAC,OAAe,EAAE,WAAmB,EAAE,QAAgB;QA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M,MAAA,MAAM,CAAC,KAAK,0CAAE,gBAAgB,CAAA;SACpC;IACF,CAAC;IAEM,KAAK,CAAC,sBAAsB;QAClC,MAAM,KAAK,GAAG;;;;;;;;EAQd,CAAA;QACA,OAAO,CACN,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAEzB,KAAK,EAAE,EAAE,CAAC,CACb,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;IACjF,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,OAAe;QAChD,MAAM,KAAK,GAAG;;;;;;;;;EASd,CAAA;QACA,OAAO,CACN,CACC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAEzB,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CACtB,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAC3F,CAAA;IACF,CAAC;CACD;AAxHD,oCAwHC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { MigrationFileLoader } from './MigrationFileLoader'
|
|
2
|
-
import { buildJs } from '../esbuild'
|
|
3
|
-
import { MigrationParser } from './MigrationParser'
|
|
4
|
-
import { ContentMigration, MigrationContent, MigrationFile } from './MigrationFile'
|
|
5
|
-
|
|
6
|
-
export class JsLoader implements MigrationFileLoader {
|
|
7
|
-
constructor(
|
|
8
|
-
private readonly migrationParser: MigrationParser,
|
|
9
|
-
) {
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
public async load(file: MigrationFile): Promise<MigrationContent> {
|
|
14
|
-
const code = await buildJs(file.path)
|
|
15
|
-
const fn = new Function(`var module = {}; ((module) => { ${code} })(module); return module`)
|
|
16
|
-
const exports = fn().exports
|
|
17
|
-
if (!('default' in exports) && !('query' in exports) && !('queries' in exports)) {
|
|
18
|
-
throw `export "default" or "query" is required in ${file.path}`
|
|
19
|
-
}
|
|
20
|
-
if (typeof exports.default !== 'function') {
|
|
21
|
-
return this.migrationParser.parse(file, exports.default || exports)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
type: 'factory',
|
|
26
|
-
factory: async (): Promise<ContentMigration> => {
|
|
27
|
-
const result = await exports.default()
|
|
28
|
-
const migration = this.migrationParser.parse(file, result ?? { queries: [] })
|
|
29
|
-
if (migration.type !== 'content') {
|
|
30
|
-
throw new Error()
|
|
31
|
-
}
|
|
32
|
-
return migration
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { MigrationFileLoader } from './MigrationFileLoader'
|
|
2
|
-
import fs from 'node:fs/promises'
|
|
3
|
-
import { MigrationParser } from './MigrationParser'
|
|
4
|
-
import { MigrationFile } from './MigrationFile'
|
|
5
|
-
|
|
6
|
-
export class JsonLoader implements MigrationFileLoader {
|
|
7
|
-
constructor(
|
|
8
|
-
private readonly migrationParser: MigrationParser,
|
|
9
|
-
) {
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public async load(file: MigrationFile) {
|
|
13
|
-
return this.migrationParser.parse(
|
|
14
|
-
file,
|
|
15
|
-
JSON.parse(await fs.readFile(file.path, { encoding: 'utf8' })),
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { MigrationFilesManager } from './MigrationFilesManager'
|
|
2
|
-
import { Schema } from '@contember/schema'
|
|
3
|
-
import { Migration, SchemaDiffer, VERSION_LATEST } from '@contember/schema-migrations'
|
|
4
|
-
import { MigrationVersionHelper } from '@contember/engine-common'
|
|
5
|
-
|
|
6
|
-
export class MigrationCreator {
|
|
7
|
-
constructor(
|
|
8
|
-
private readonly migrationFilesManager: MigrationFilesManager,
|
|
9
|
-
private readonly schemaDiffer: SchemaDiffer,
|
|
10
|
-
private readonly emptyTemplates: Record<string, string> = {},
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async createEmptyMigrationFile(migrationName: string, format: string): Promise<string> {
|
|
14
|
-
if (!this.emptyTemplates.hasOwnProperty(format)) {
|
|
15
|
-
throw new Error(`Unknown format ${format}`)
|
|
16
|
-
}
|
|
17
|
-
await this.migrationFilesManager.createDirIfNotExist()
|
|
18
|
-
const [, fullName] = MigrationVersionHelper.createVersion(migrationName)
|
|
19
|
-
const filename = await this.migrationFilesManager.createFile(this.emptyTemplates[format], fullName, format)
|
|
20
|
-
|
|
21
|
-
return filename
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async prepareMigration(
|
|
25
|
-
initialSchema: Schema,
|
|
26
|
-
newSchema: Schema,
|
|
27
|
-
migrationName: string,
|
|
28
|
-
{ skipInitialSchemaValidation = false }: { skipInitialSchemaValidation?: boolean } = {},
|
|
29
|
-
): Promise<{ migration: Migration; initialSchema: Schema } | null> {
|
|
30
|
-
await this.migrationFilesManager.createDirIfNotExist()
|
|
31
|
-
|
|
32
|
-
const modifications = this.schemaDiffer.diffSchemas(initialSchema, newSchema, { skipInitialSchemaValidation })
|
|
33
|
-
if (modifications.length === 0) {
|
|
34
|
-
return null
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const migration = this.createMigration(modifications, migrationName)
|
|
38
|
-
|
|
39
|
-
return { initialSchema, migration }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async saveMigration(migration: Migration): Promise<string> {
|
|
43
|
-
const jsonDiff = MigrationCreator.createContent(migration)
|
|
44
|
-
const filename = await this.migrationFilesManager.createFile(jsonDiff, migration.name)
|
|
45
|
-
return filename
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async removeMigration(name: string): Promise<void> {
|
|
49
|
-
await this.migrationFilesManager.removeFile(name)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private createMigration(modifications: Migration.Modification[], name: string): Migration {
|
|
53
|
-
const [version, fullName] = MigrationVersionHelper.createVersion(name)
|
|
54
|
-
return { formatVersion: VERSION_LATEST, modifications, version, name: fullName }
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public static createContent({ modifications, formatVersion }: Migration): string {
|
|
58
|
-
return JSON.stringify({ formatVersion, modifications }, undefined, '\t') + '\n'
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Migration } from '@contember/schema-migrations'
|
|
2
|
-
import { JSONObject } from '@contember/cli-common'
|
|
3
|
-
|
|
4
|
-
export interface MigrationFile {
|
|
5
|
-
path: string
|
|
6
|
-
version: string
|
|
7
|
-
name: string
|
|
8
|
-
|
|
9
|
-
getContent: () => Promise<MigrationContent>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const isSchemaMigration = (content: MigrationContent): content is SchemaMigration => typeof content !== 'function' && 'modifications' in content
|
|
13
|
-
|
|
14
|
-
export type ResolvedMigrationContent =
|
|
15
|
-
| SchemaMigration
|
|
16
|
-
| ContentMigration
|
|
17
|
-
|
|
18
|
-
export type MigrationContent =
|
|
19
|
-
| ResolvedMigrationContent
|
|
20
|
-
| ContentMigrationFactory
|
|
21
|
-
|
|
22
|
-
export type SchemaMigration =
|
|
23
|
-
& {
|
|
24
|
-
type: 'schema'
|
|
25
|
-
}
|
|
26
|
-
& Migration
|
|
27
|
-
|
|
28
|
-
export type ContentMigration = {
|
|
29
|
-
type: 'content'
|
|
30
|
-
version: string
|
|
31
|
-
name: string
|
|
32
|
-
queries: ContentMigrationQuery[]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type ContentMigrationFactoryArgs = {
|
|
36
|
-
apiBaseUrl: string
|
|
37
|
-
projectName: string
|
|
38
|
-
apiToken: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type ContentMigrationFactory = {
|
|
42
|
-
type: 'factory'
|
|
43
|
-
factory: (args: ContentMigrationFactoryArgs) => Promise<ContentMigration>
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type ContentMigrationQuery = {
|
|
47
|
-
query: string
|
|
48
|
-
variables?: JSONObject
|
|
49
|
-
stage?: string
|
|
50
|
-
checkMutationResult?: boolean
|
|
51
|
-
}
|
|
52
|
-
|