@prisma-psm/core 1.0.55 → 1.0.56
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.map +1 -1
- package/src/tools/deploy.js +11 -7
- package/src/tools/deploy.js.map +1 -1
- package/src/tools/deploy.ts +53 -46
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,WAAW,aAAa;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;CAC9B;AAID,wBAAsB,MAAM,CAAC,IAAI,EAAE,aAAa,iBA0E/C;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;IAClB,GAAG,EAAE,aAAa,CAAC;CACtB;AAED,wBAAsB,KAAK,CAAC,IAAI,EAAE,YAAY;;cAKhC,MAAM;aACP,aAAa;iBACT,MAAM;iBACN,MAAM;gBACP,OAAO;eACR,MAAM;iBACJ,MAAM,EAAE;cACX,IAAI,GAAG,IAAI;;;;;;cAPX,MAAM;aACP,aAAa;iBACT,MAAM;iBACN,MAAM;gBACP,OAAO;eACR,MAAM;iBACJ,MAAM,EAAE;cACX,IAAI,GAAG,IAAI;;;;;;cAPX,MAAM;aACP,aAAa;iBACT,MAAM;iBACN,MAAM;gBACP,OAAO;eACR,MAAM;iBACJ,MAAM,EAAE;cACX,IAAI,GAAG,IAAI;;;;GAuFxB"}
|
package/src/tools/deploy.js
CHANGED
|
@@ -68,7 +68,7 @@ function deploy(opts) {
|
|
|
68
68
|
const pullResponse = yield fetch({
|
|
69
69
|
home: home,
|
|
70
70
|
driver: driver,
|
|
71
|
-
psm: psm
|
|
71
|
+
psm: psm,
|
|
72
72
|
});
|
|
73
73
|
if (pullResponse.error) {
|
|
74
74
|
pullResponse.clean();
|
|
@@ -78,7 +78,9 @@ function deploy(opts) {
|
|
|
78
78
|
pullResponse.clean();
|
|
79
79
|
throw new Error(`No migrate commited! Use ${chalk_1.default.bold("psm migrate commit")} first!`);
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
let revs = pullResponse.revs;
|
|
82
|
+
// Ordena as revisões por instante (cronologicamente)
|
|
83
|
+
revs.sort((a, b) => a.psm.migration.instante.localeCompare(b.psm.migration.instante));
|
|
82
84
|
for (let i = 0; i < revs.length; i++) {
|
|
83
85
|
let next = revs[i];
|
|
84
86
|
const migrator = driver.migrator({
|
|
@@ -88,9 +90,11 @@ function deploy(opts) {
|
|
|
88
90
|
core: "",
|
|
89
91
|
});
|
|
90
92
|
next.message.forEach(console.log);
|
|
93
|
+
// CORREÇÃO: se já foi migrada, apenas continua para a próxima
|
|
91
94
|
if (next.pulled)
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
continue;
|
|
96
|
+
// Restaura backup apenas na primeira revisão não aplicada (se houver)
|
|
97
|
+
if (i === 0 && !!next.backup) {
|
|
94
98
|
yield migrator.restore(next.backup);
|
|
95
99
|
}
|
|
96
100
|
const result = yield migrator.migrate();
|
|
@@ -138,7 +142,7 @@ function fetch(opts) {
|
|
|
138
142
|
message: [],
|
|
139
143
|
date: null,
|
|
140
144
|
backup: backup,
|
|
141
|
-
temp: tempDir
|
|
145
|
+
temp: tempDir,
|
|
142
146
|
};
|
|
143
147
|
if (fs.existsSync(backup))
|
|
144
148
|
rev.backup = backup;
|
|
@@ -154,7 +158,7 @@ function fetch(opts) {
|
|
|
154
158
|
return {
|
|
155
159
|
revs,
|
|
156
160
|
error: new Error(`MISSING PREVIEW migration for...\n${missed.join(", ")}`),
|
|
157
|
-
clean() { }
|
|
161
|
+
clean() { },
|
|
158
162
|
};
|
|
159
163
|
}
|
|
160
164
|
// marcar revisões já migradas
|
|
@@ -183,7 +187,7 @@ function fetch(opts) {
|
|
|
183
187
|
revs.forEach(value => {
|
|
184
188
|
fs.rmSync(value.temp, { recursive: true, force: true });
|
|
185
189
|
});
|
|
186
|
-
}
|
|
190
|
+
},
|
|
187
191
|
};
|
|
188
192
|
});
|
|
189
193
|
}
|
package/src/tools/deploy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBhC,
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["deploy.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBhC,wBA0EC;AAQD,sBAmGC;AAxMD,8CAAsB;AACtB,4CAA8B;AAC9B,4CAA8B;AAC9B,2CAA6B;AAC7B,gDAAkC;AAElC,kDAA0B;AAE1B,qCAAqC;AASrC,MAAM,GAAG,GAAG,cAAc,CAAC;AAE3B,SAAsB,MAAM,CAAC,IAAmB;;;QAC5C,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;QAE3B,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,kBAAS,EAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAEhF,IAAI,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;YAC3B,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,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,SAAS,CAAC,KAAK,0CAAE,MAAM,EAAC,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACtF,IAAI,CAAC,KAAK,GAAG,SAAS,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,GAAG,EAAE,eAAe,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACnG,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC1E,IAAI,GAAG,EAAE,CAAC;gBACN,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC9D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACvB,CAAC;QACL,CAAC;QAED,OAAO;YACH,IAAI;YACJ,KAAK;gBACD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;oBACjB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC5D,CAAC,CAAC,CAAC;YACP,CAAC;SACJ,CAAC;IACN,CAAC;CAAA"}
|
package/src/tools/deploy.ts
CHANGED
|
@@ -5,58 +5,61 @@ import * as os from "node:os";
|
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
6
|
import * as yaml from "yaml";
|
|
7
7
|
import * as Path from "node:path";
|
|
8
|
-
import {PSMConfigFile} from "../configs";
|
|
8
|
+
import { PSMConfigFile } from "../configs";
|
|
9
9
|
import chalk from "chalk";
|
|
10
|
-
import {PSMDriver} from "../driver";
|
|
11
|
-
import {psmLockup} from "./common";
|
|
10
|
+
import { PSMDriver } from "../driver";
|
|
11
|
+
import { psmLockup } from "./common";
|
|
12
12
|
|
|
13
13
|
export interface DeployOptions {
|
|
14
|
-
schema?:string
|
|
15
|
-
generate?:string
|
|
16
|
-
label?:string
|
|
17
|
-
"generate-command":string
|
|
14
|
+
schema?: string;
|
|
15
|
+
generate?: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
"generate-command": string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const TAG = "PSM DEPLOY >"
|
|
20
|
+
const TAG = "PSM DEPLOY >";
|
|
21
21
|
|
|
22
|
-
export async function deploy(
|
|
22
|
+
export async function deploy(opts: DeployOptions) {
|
|
23
23
|
require('dotenv').config();
|
|
24
24
|
|
|
25
|
-
const { psm, psm_sql, driver, home} = await psmLockup({ schema: opts.schema });
|
|
25
|
+
const { psm, psm_sql, driver, home } = await psmLockup({ schema: opts.schema });
|
|
26
26
|
|
|
27
27
|
let migrator = driver.migrator({
|
|
28
28
|
url: process.env[psm.psm.url],
|
|
29
29
|
migrate: "",
|
|
30
30
|
check: "",
|
|
31
|
-
core: fs.readFileSync(
|
|
31
|
+
core: fs.readFileSync(psm_sql).toString(),
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
let result = await migrator.core();
|
|
35
|
-
if(
|
|
36
|
-
console.error(
|
|
37
|
-
result.messages.forEach(
|
|
38
|
-
console.error(
|
|
35
|
+
if (!result.success) {
|
|
36
|
+
console.error(result.error);
|
|
37
|
+
result.messages.forEach(error => {
|
|
38
|
+
console.error(error);
|
|
39
39
|
});
|
|
40
|
-
throw new Error(
|
|
40
|
+
throw new Error("Migrate error: Core failed!");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const pullResponse = await fetch({
|
|
44
44
|
home: home,
|
|
45
45
|
driver: driver,
|
|
46
|
-
psm: psm
|
|
46
|
+
psm: psm,
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
if(
|
|
49
|
+
if (pullResponse.error) {
|
|
50
50
|
pullResponse.clean();
|
|
51
|
-
throw
|
|
51
|
+
throw pullResponse.error;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
if(
|
|
54
|
+
if (!pullResponse.revs?.length) {
|
|
55
55
|
pullResponse.clean();
|
|
56
|
-
throw new Error(`No migrate commited! Use ${
|
|
56
|
+
throw new Error(`No migrate commited! Use ${chalk.bold("psm migrate commit")} first!`);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
let revs = pullResponse.revs;
|
|
60
|
+
|
|
61
|
+
// Ordena as revisões por instante (cronologicamente)
|
|
62
|
+
revs.sort((a, b) => a.psm.migration.instante.localeCompare(b.psm.migration.instante));
|
|
60
63
|
|
|
61
64
|
for (let i = 0; i < revs.length; i++) {
|
|
62
65
|
let next = revs[i];
|
|
@@ -66,40 +69,44 @@ export async function deploy( opts: DeployOptions) {
|
|
|
66
69
|
check: "",
|
|
67
70
|
core: "",
|
|
68
71
|
});
|
|
69
|
-
next.message.forEach(
|
|
72
|
+
next.message.forEach(console.log);
|
|
73
|
+
|
|
74
|
+
// CORREÇÃO: se já foi migrada, apenas continua para a próxima
|
|
75
|
+
if (next.pulled) continue;
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
await migrator.restore(
|
|
77
|
+
// Restaura backup apenas na primeira revisão não aplicada (se houver)
|
|
78
|
+
if (i === 0 && !!next.backup) {
|
|
79
|
+
await migrator.restore(next.backup);
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
const result = await migrator.migrate();
|
|
77
83
|
|
|
78
|
-
if(
|
|
79
|
-
console.error(
|
|
80
|
-
result.messages.forEach(
|
|
81
|
-
console.error(
|
|
84
|
+
if (!result.success) {
|
|
85
|
+
console.error(result.error);
|
|
86
|
+
result.messages.forEach(error => {
|
|
87
|
+
console.error(error);
|
|
82
88
|
});
|
|
83
|
-
console.error(
|
|
84
|
-
throw new Error(
|
|
89
|
+
console.error(`${next.label} is migrated at ${next.date} - ${chalk.redBright.bold("FAILED")}`);
|
|
90
|
+
throw new Error("Migrate error: Push migration failed!");
|
|
85
91
|
}
|
|
86
|
-
console.log(
|
|
92
|
+
console.log(`${next.label} is migrated at ${next.date} - ${chalk.greenBright.bold("SUCCESS")}`);
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
pullResponse.clean();
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
export interface FetchOptions {
|
|
93
|
-
home:string
|
|
94
|
-
driver:PSMDriver
|
|
95
|
-
psm:PSMConfigFile
|
|
99
|
+
home: string;
|
|
100
|
+
driver: PSMDriver;
|
|
101
|
+
psm: PSMConfigFile;
|
|
96
102
|
}
|
|
103
|
+
|
|
97
104
|
export async function fetch(opts: FetchOptions) {
|
|
98
105
|
const revisionsDir = Path.join(opts.home, "psm/revisions/schema");
|
|
99
106
|
const revFiles = fs.readdirSync(revisionsDir).filter(n => n.endsWith(".tar.gz"));
|
|
100
107
|
|
|
101
108
|
const revs: Array<{
|
|
102
|
-
temp:string
|
|
109
|
+
temp: string;
|
|
103
110
|
psm: PSMConfigFile;
|
|
104
111
|
migrate: string;
|
|
105
112
|
backup?: string;
|
|
@@ -132,7 +139,7 @@ export async function fetch(opts: FetchOptions) {
|
|
|
132
139
|
const psm = yaml.parse(fs.readFileSync(psmPath, "utf-8")) as PSMConfigFile;
|
|
133
140
|
const migrate = fs.readFileSync(migrationPath, "utf-8");
|
|
134
141
|
|
|
135
|
-
const rev:typeof revs[number] = {
|
|
142
|
+
const rev: typeof revs[number] = {
|
|
136
143
|
psm,
|
|
137
144
|
migrate,
|
|
138
145
|
pulled: false,
|
|
@@ -140,10 +147,10 @@ export async function fetch(opts: FetchOptions) {
|
|
|
140
147
|
message: [],
|
|
141
148
|
date: null,
|
|
142
149
|
backup: backup,
|
|
143
|
-
temp: tempDir
|
|
144
|
-
}
|
|
150
|
+
temp: tempDir,
|
|
151
|
+
};
|
|
145
152
|
|
|
146
|
-
if(
|
|
153
|
+
if (fs.existsSync(backup)) rev.backup = backup;
|
|
147
154
|
revs.push(rev);
|
|
148
155
|
}
|
|
149
156
|
|
|
@@ -158,7 +165,7 @@ export async function fetch(opts: FetchOptions) {
|
|
|
158
165
|
return {
|
|
159
166
|
revs,
|
|
160
167
|
error: new Error(`MISSING PREVIEW migration for...\n${missed.join(", ")}`),
|
|
161
|
-
clean(){}
|
|
168
|
+
clean() {},
|
|
162
169
|
};
|
|
163
170
|
}
|
|
164
171
|
|
|
@@ -187,10 +194,10 @@ export async function fetch(opts: FetchOptions) {
|
|
|
187
194
|
|
|
188
195
|
return {
|
|
189
196
|
revs,
|
|
190
|
-
clean(){
|
|
191
|
-
revs.forEach(
|
|
197
|
+
clean() {
|
|
198
|
+
revs.forEach(value => {
|
|
192
199
|
fs.rmSync(value.temp, { recursive: true, force: true });
|
|
193
|
-
})
|
|
194
|
-
}
|
|
200
|
+
});
|
|
201
|
+
},
|
|
195
202
|
};
|
|
196
203
|
}
|