@prisma-psm/core 1.0.28 → 1.0.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/package.json +1 -1
- package/src/tools/deploy.d.ts +3 -16
- package/src/tools/deploy.d.ts.map +1 -1
- package/src/tools/deploy.js +41 -37
- package/src/tools/deploy.js.map +1 -1
- package/src/tools/deploy.ts +69 -51
package/package.json
CHANGED
package/src/tools/deploy.d.ts
CHANGED
|
@@ -19,31 +19,18 @@ export declare function fetch(opts: FetchOptions): Promise<{
|
|
|
19
19
|
pulled: boolean;
|
|
20
20
|
label: string;
|
|
21
21
|
message: string[];
|
|
22
|
-
date: Date;
|
|
23
|
-
}[];
|
|
24
|
-
error?: undefined;
|
|
25
|
-
hint?: undefined;
|
|
26
|
-
} | {
|
|
27
|
-
revs: {
|
|
28
|
-
psm: PSMConfigFile;
|
|
29
|
-
migrate: string;
|
|
30
|
-
pulled: boolean;
|
|
31
|
-
label: string;
|
|
32
|
-
message: string[];
|
|
33
|
-
date: Date;
|
|
22
|
+
date: Date | null;
|
|
34
23
|
}[];
|
|
35
24
|
error: Error;
|
|
36
|
-
hint?: undefined;
|
|
37
25
|
} | {
|
|
38
|
-
error: Error;
|
|
39
|
-
hint: any;
|
|
40
26
|
revs: {
|
|
41
27
|
psm: PSMConfigFile;
|
|
42
28
|
migrate: string;
|
|
43
29
|
pulled: boolean;
|
|
44
30
|
label: string;
|
|
45
31
|
message: string[];
|
|
46
|
-
date: Date;
|
|
32
|
+
date: Date | null;
|
|
47
33
|
}[];
|
|
34
|
+
error?: undefined;
|
|
48
35
|
}>;
|
|
49
36
|
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAGpC,MAAM,WAAW,aAAa;IAC1B,MAAM,CAAC,EAAC,MAAM,CAAA;IACd,QAAQ,CAAC,EAAC,MAAM,CAAA;IAChB,KAAK,CAAC,EAAC,MAAM,CAAA;IACb,kBAAkB,EAAC,MAAM,CAAA;CAC5B;AAID,wBAAsB,MAAM,CAAE,IAAI,EAAE,aAAa,iBA6DhD;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,EAAC,MAAM,CAAC;IACZ,MAAM,EAAC,SAAS,CAAC;IACjB,GAAG,EAAC,aAAa,CAAA;CACpB;AACD,wBAAsB,KAAK,CAAC,IAAI,EAAE,YAAY;;aAKjC,aAAa;iBACT,MAAM;gBACP,OAAO;eACR,MAAM;iBACJ,MAAM,EAAE;cACX,IAAI,GAAG,IAAI;;;;;aALZ,aAAa;iBACT,MAAM;gBACP,OAAO;eACR,MAAM;iBACJ,MAAM,EAAE;cACX,IAAI,GAAG,IAAI;;;GA2ExB"}
|
package/src/tools/deploy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// filename: src/tools/deploy.ts
|
|
2
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
4
|
if (k2 === undefined) k2 = k;
|
|
4
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -37,6 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
39
|
exports.deploy = deploy;
|
|
39
40
|
exports.fetch = fetch;
|
|
41
|
+
const tar_1 = __importDefault(require("tar"));
|
|
42
|
+
const os = __importStar(require("node:os"));
|
|
40
43
|
const fs = __importStar(require("node:fs"));
|
|
41
44
|
const yaml = __importStar(require("yaml"));
|
|
42
45
|
const Path = __importStar(require("node:path"));
|
|
@@ -101,67 +104,68 @@ function deploy(opts) {
|
|
|
101
104
|
function fetch(opts) {
|
|
102
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
106
|
var _a;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
const revisionsDir = Path.join(opts.home, "psm/revisions/schema");
|
|
108
|
+
const revFiles = fs.readdirSync(revisionsDir).filter(n => n.endsWith(".tar.gz"));
|
|
109
|
+
const revs = [];
|
|
110
|
+
for (const file of revFiles) {
|
|
111
|
+
const tempDir = fs.mkdtempSync(Path.join(os.tmpdir(), "psm-"));
|
|
112
|
+
yield tar_1.default.x({
|
|
113
|
+
file: Path.join(revisionsDir, file),
|
|
114
|
+
cwd: tempDir,
|
|
115
|
+
});
|
|
116
|
+
const extractedDir = fs.readdirSync(tempDir)[0];
|
|
117
|
+
const fullPath = Path.join(tempDir, extractedDir);
|
|
118
|
+
const psmPath = Path.join(fullPath, "psm.yml");
|
|
119
|
+
const migrationPath = Path.join(fullPath, "migration.sql");
|
|
120
|
+
if (!fs.existsSync(psmPath) || !fs.existsSync(migrationPath)) {
|
|
121
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
122
|
+
throw new Error(`Invalid migration archive: ${file}`);
|
|
123
|
+
}
|
|
124
|
+
const psm = yaml.parse(fs.readFileSync(psmPath, "utf-8"));
|
|
125
|
+
const migrate = fs.readFileSync(migrationPath, "utf-8");
|
|
126
|
+
revs.push({
|
|
111
127
|
psm,
|
|
112
128
|
migrate,
|
|
113
129
|
pulled: false,
|
|
114
130
|
label: "",
|
|
115
131
|
message: [],
|
|
116
132
|
date: null,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
if (!revs.length) {
|
|
120
|
-
return {
|
|
121
|
-
revs: revs,
|
|
122
|
-
};
|
|
133
|
+
});
|
|
134
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
123
135
|
}
|
|
136
|
+
// verificar previews faltantes
|
|
124
137
|
const missedPreviews = revs.filter((n, i) => {
|
|
125
138
|
return (!!n.psm.migration.preview && !revs.find(p => p.psm.migration.revision === n.psm.migration.preview))
|
|
126
139
|
|| (i > 0 && !n.psm.migration.preview);
|
|
127
140
|
});
|
|
128
|
-
if (
|
|
141
|
+
if (missedPreviews.length) {
|
|
129
142
|
const missed = missedPreviews.map(n => `${n.psm.psm.migration} - ${n.psm.migration.label} at ${n.psm.migration.instante}`);
|
|
130
143
|
return {
|
|
131
|
-
revs
|
|
132
|
-
error: new Error(`MISSING PREVIEW migration for...\n
|
|
144
|
+
revs,
|
|
145
|
+
error: new Error(`MISSING PREVIEW migration for...\n${missed.join(", ")}`),
|
|
133
146
|
};
|
|
134
147
|
}
|
|
135
|
-
|
|
148
|
+
// marcar revisões já migradas
|
|
149
|
+
const migrated = yield opts.driver.migrated({
|
|
136
150
|
url: process.env[opts.psm.psm.url],
|
|
137
|
-
sys: opts.psm.psm.sys
|
|
151
|
+
sys: opts.psm.psm.sys,
|
|
138
152
|
});
|
|
139
153
|
if (!migrated.success) {
|
|
140
154
|
console.error(migrated.error);
|
|
141
|
-
migrated.messages.forEach(error
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
return {
|
|
145
|
-
error: new Error("Load Migrated failed!"),
|
|
146
|
-
hint: migrated.error,
|
|
147
|
-
revs: revs
|
|
148
|
-
};
|
|
155
|
+
migrated.messages.forEach(console.error);
|
|
156
|
+
return { revs, error: new Error("Load Migrated failed!") };
|
|
149
157
|
}
|
|
150
|
-
for (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
next.label = label;
|
|
156
|
-
if (!!mig) {
|
|
158
|
+
for (const next of revs) {
|
|
159
|
+
const pl = ((_a = next.psm.migration.label) === null || _a === void 0 ? void 0 : _a.length) ? ` - ${next.psm.migration.label} ` : " ";
|
|
160
|
+
next.label = `RevNo ${next.psm.migration.revision}${pl}commited at ${next.psm.migration.instante}`;
|
|
161
|
+
const mig = migrated.migrated.find(v => v.sid === next.psm.psm.migration);
|
|
162
|
+
if (mig) {
|
|
157
163
|
next.date = mig.date;
|
|
158
|
-
next.message.push(`${label} is migrated at ${mig.date}`);
|
|
164
|
+
next.message.push(`${next.label} is migrated at ${mig.date}`);
|
|
159
165
|
next.pulled = true;
|
|
160
166
|
}
|
|
161
167
|
}
|
|
162
|
-
return {
|
|
163
|
-
revs
|
|
164
|
-
};
|
|
168
|
+
return { revs };
|
|
165
169
|
});
|
|
166
170
|
}
|
|
167
171
|
//# sourceMappingURL=deploy.js.map
|
package/src/tools/deploy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBhC,wBA6DC;AAOD,sBAqFC;AA5KD,8CAAsB;AACtB,4CAA8B;AAC9B,4CAA8B;AAC9B,2CAA6B;AAC7B,gDAAkC;AAElC,kDAA0B;AAE1B,qCAAmC;AASnC,MAAM,GAAG,GAAG,cAAc,CAAA;AAE1B,SAAsB,MAAM,CAAE,IAAmB;;;QAC7C,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;QAE3B,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,GAAG,MAAM,IAAA,kBAAS,EAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAE/E,IAAI,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;YAC3B,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;YAC7B,OAAO,EAAE,E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,OAAO,EAAE,IAAI,EAAE,CAAC;IACpB,CAAC;CAAA"}
|
package/src/tools/deploy.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// filename: src/tools/deploy.ts
|
|
2
|
+
|
|
3
|
+
import tar from "tar";
|
|
4
|
+
import * as os from "node:os";
|
|
1
5
|
import * as fs from "node:fs";
|
|
2
6
|
import * as yaml from "yaml";
|
|
3
7
|
import * as Path from "node:path";
|
|
@@ -83,75 +87,89 @@ export interface FetchOptions {
|
|
|
83
87
|
driver:PSMDriver,
|
|
84
88
|
psm:PSMConfigFile
|
|
85
89
|
}
|
|
86
|
-
export async function fetch(opts:FetchOptions){
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
export async function fetch(opts: FetchOptions) {
|
|
91
|
+
const revisionsDir = Path.join(opts.home, "psm/revisions/schema");
|
|
92
|
+
const revFiles = fs.readdirSync(revisionsDir).filter(n => n.endsWith(".tar.gz"));
|
|
93
|
+
|
|
94
|
+
const revs: Array<{
|
|
95
|
+
psm: PSMConfigFile;
|
|
96
|
+
migrate: string;
|
|
97
|
+
pulled: boolean;
|
|
98
|
+
label: string;
|
|
99
|
+
message: string[];
|
|
100
|
+
date: Date | null;
|
|
101
|
+
}> = [];
|
|
102
|
+
|
|
103
|
+
for (const file of revFiles) {
|
|
104
|
+
const tempDir = fs.mkdtempSync(Path.join(os.tmpdir(), "psm-"));
|
|
105
|
+
|
|
106
|
+
await tar.x({
|
|
107
|
+
file: Path.join(revisionsDir, file),
|
|
108
|
+
cwd: tempDir,
|
|
102
109
|
});
|
|
103
110
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
revs: revs,
|
|
111
|
+
const extractedDir = fs.readdirSync(tempDir)[0];
|
|
112
|
+
const fullPath = Path.join(tempDir, extractedDir);
|
|
107
113
|
|
|
108
|
-
|
|
114
|
+
const psmPath = Path.join(fullPath, "psm.yml");
|
|
115
|
+
const migrationPath = Path.join(fullPath, "migration.sql");
|
|
116
|
+
|
|
117
|
+
if (!fs.existsSync(psmPath) || !fs.existsSync(migrationPath)) {
|
|
118
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
119
|
+
throw new Error(`Invalid migration archive: ${file}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const psm = yaml.parse(fs.readFileSync(psmPath, "utf-8")) as PSMConfigFile;
|
|
123
|
+
const migrate = fs.readFileSync(migrationPath, "utf-8");
|
|
124
|
+
|
|
125
|
+
revs.push({
|
|
126
|
+
psm,
|
|
127
|
+
migrate,
|
|
128
|
+
pulled: false,
|
|
129
|
+
label: "",
|
|
130
|
+
message: [],
|
|
131
|
+
date: null,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
109
135
|
}
|
|
110
136
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
137
|
+
// verificar previews faltantes
|
|
138
|
+
const missedPreviews = revs.filter((n, i) => {
|
|
139
|
+
return (!!n.psm.migration.preview && !revs.find(p => p.psm.migration.revision === n.psm.migration.preview))
|
|
140
|
+
|| (i > 0 && !n.psm.migration.preview);
|
|
114
141
|
});
|
|
115
142
|
|
|
116
|
-
if(
|
|
117
|
-
const missed = missedPreviews.map(n=> `${n.psm.psm.migration} - ${n.psm.migration.label} at ${n.psm.migration.instante}`
|
|
143
|
+
if (missedPreviews.length) {
|
|
144
|
+
const missed = missedPreviews.map(n => `${n.psm.psm.migration} - ${n.psm.migration.label} at ${n.psm.migration.instante}`);
|
|
118
145
|
return {
|
|
119
|
-
revs
|
|
120
|
-
error: new Error(`MISSING PREVIEW migration for...\n
|
|
146
|
+
revs,
|
|
147
|
+
error: new Error(`MISSING PREVIEW migration for...\n${missed.join(", ")}`),
|
|
121
148
|
};
|
|
122
149
|
}
|
|
123
150
|
|
|
124
|
-
|
|
125
|
-
|
|
151
|
+
// marcar revisões já migradas
|
|
152
|
+
const migrated = await opts.driver.migrated({
|
|
126
153
|
url: process.env[opts.psm.psm.url],
|
|
127
|
-
sys: opts.psm.psm.sys
|
|
154
|
+
sys: opts.psm.psm.sys,
|
|
128
155
|
});
|
|
129
156
|
|
|
130
|
-
if(
|
|
131
|
-
console.error(
|
|
132
|
-
migrated.messages.forEach(
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
return {
|
|
136
|
-
error: new Error( "Load Migrated failed!" ),
|
|
137
|
-
hint: migrated.error,
|
|
138
|
-
revs: revs
|
|
139
|
-
};
|
|
157
|
+
if (!migrated.success) {
|
|
158
|
+
console.error(migrated.error);
|
|
159
|
+
migrated.messages.forEach(console.error);
|
|
160
|
+
return { revs, error: new Error("Load Migrated failed!") };
|
|
140
161
|
}
|
|
141
162
|
|
|
142
|
-
for (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
next.label = label;
|
|
148
|
-
if( !!mig ) {
|
|
163
|
+
for (const next of revs) {
|
|
164
|
+
const pl = next.psm.migration.label?.length ? ` - ${next.psm.migration.label} ` : " ";
|
|
165
|
+
next.label = `RevNo ${next.psm.migration.revision}${pl}commited at ${next.psm.migration.instante}`;
|
|
166
|
+
const mig = migrated.migrated.find(v => v.sid === next.psm.psm.migration);
|
|
167
|
+
if (mig) {
|
|
149
168
|
next.date = mig.date;
|
|
150
|
-
next.message.push(`${label} is migrated at ${mig.date}`);
|
|
169
|
+
next.message.push(`${next.label} is migrated at ${mig.date}`);
|
|
151
170
|
next.pulled = true;
|
|
152
171
|
}
|
|
153
172
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
173
|
+
|
|
174
|
+
return { revs };
|
|
157
175
|
}
|