@prisma-psm/core 1.0.6 → 1.0.8
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/.idea/developer-tools.xml +6 -0
- package/README.en.md +5 -5
- package/README.md +5 -5
- package/README.pt.md +1 -1
- package/package.json +4 -4
- package/src/driver.d.ts +53 -0
- package/src/driver.d.ts.map +1 -1
- package/src/driver.ts +62 -2
- package/src/launcher/commands/check.ts +1 -1
- package/src/launcher/commands/commit.d.ts +1 -1
- package/src/launcher/commands/commit.d.ts.map +1 -1
- package/src/launcher/commands/commit.js +2 -2
- package/src/launcher/commands/commit.js.map +1 -1
- package/src/launcher/commands/commit.ts +2 -2
- package/src/launcher/commands/generate.js.map +1 -1
- package/src/launcher/commands/generate.ts +1 -1
- package/src/tools/{migrate.d.ts → commit.d.ts} +2 -2
- package/src/tools/commit.d.ts.map +1 -0
- package/src/tools/{migrate.js → commit.js} +28 -35
- package/src/tools/commit.js.map +1 -0
- package/src/tools/{migrate.ts → commit.ts} +29 -38
- package/src/tools/common.d.ts +14 -0
- package/src/tools/common.d.ts.map +1 -0
- package/src/tools/common.js +70 -0
- package/src/tools/common.js.map +1 -0
- package/src/tools/common.ts +46 -0
- package/src/tools/deploy.d.ts +41 -0
- package/src/tools/deploy.d.ts.map +1 -1
- package/src/tools/deploy.js +72 -62
- package/src/tools/deploy.js.map +1 -1
- package/src/tools/deploy.ts +78 -66
- package/src/tools/generate.d.ts.map +1 -1
- package/src/tools/generate.js.map +1 -1
- package/src/tools/generate.ts +6 -3
- package/src/tools/migrate.d.ts.map +0 -1
- package/src/tools/migrate.js.map +0 -1
package/README.en.md
CHANGED
|
@@ -30,10 +30,10 @@ In your `schema.prisma` file, configure the PSM generator to generate the SQL fi
|
|
|
30
30
|
|
|
31
31
|
```prisma
|
|
32
32
|
generator psm {
|
|
33
|
-
provider = "psm generate"
|
|
34
|
-
output = "./psm/"
|
|
35
|
-
driver = "@prisma-psm/pg"
|
|
36
|
-
url = env("DATABASE_URL")
|
|
33
|
+
provider = "psm generate"
|
|
34
|
+
output = "./psm/"
|
|
35
|
+
driver = "@prisma-psm/pg"
|
|
36
|
+
url = env("DATABASE_URL")
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -85,7 +85,7 @@ PSM uses a temporary shadow schema to ensure data security:
|
|
|
85
85
|
4. Applies constraints (keys, indexes, relationships) to the temporary tables.
|
|
86
86
|
5. If everything passes during validation (check):
|
|
87
87
|
- Removes the shadow schema and temporary tables.
|
|
88
|
-
6. If everything passes during application (
|
|
88
|
+
6. If everything passes during application (commit next):
|
|
89
89
|
- Removes the real tables.
|
|
90
90
|
- Moves the temporary tables from the shadow schema to the final schema.
|
|
91
91
|
- Renames the temporary tables to their real names.
|
package/README.md
CHANGED
|
@@ -30,10 +30,10 @@ In your `schema.prisma` file, configure the PSM generator to generate the SQL fi
|
|
|
30
30
|
|
|
31
31
|
```prisma
|
|
32
32
|
generator psm {
|
|
33
|
-
provider = "psm generate"
|
|
34
|
-
output = "./psm/"
|
|
35
|
-
driver = "@prisma-psm/pg"
|
|
36
|
-
url = env("DATABASE_URL")
|
|
33
|
+
provider = "psm generate"
|
|
34
|
+
output = "./psm/"
|
|
35
|
+
driver = "@prisma-psm/pg"
|
|
36
|
+
url = env("DATABASE_URL")
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -85,7 +85,7 @@ PSM uses a temporary shadow schema to ensure data security:
|
|
|
85
85
|
4. Applies constraints (keys, indexes, relationships) to the temporary tables.
|
|
86
86
|
5. If everything passes during validation (check):
|
|
87
87
|
- Removes the shadow schema and temporary tables.
|
|
88
|
-
6. If everything passes during application (
|
|
88
|
+
6. If everything passes during application (commit next):
|
|
89
89
|
- Removes the real tables.
|
|
90
90
|
- Moves the temporary tables from the shadow schema to the final schema.
|
|
91
91
|
- Renames the temporary tables to their real names.
|
package/README.pt.md
CHANGED
|
@@ -89,7 +89,7 @@ O PSM usa um esquema shadow temporário para garantir segurança dos dados:
|
|
|
89
89
|
4. Aplica as constraints (chaves, índices, relacionamentos) nas tabelas temporárias.
|
|
90
90
|
5. Se na validação (check) tudo passar:
|
|
91
91
|
- Remove o schema shadow e as tabelas temporárias.
|
|
92
|
-
6. Se na aplicação (
|
|
92
|
+
6. Se na aplicação (commit next) tudo passar:
|
|
93
93
|
- Remove as tabelas reais.
|
|
94
94
|
- Move as tabelas temporárias do schema shadow para o schema final.
|
|
95
95
|
- Renomeia as tabelas temporárias para os nomes reais.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-psm/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "PSM - Prisma SAFE MIGRATE: ferramenta CLI para migração segura de bancos Prisma com suporte avançado.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"json5": "^2.2.3",
|
|
19
19
|
"moment": "^2.30.1",
|
|
20
20
|
"nanoid": "^5.1.5",
|
|
21
|
-
"yaml": "^2.8.1"
|
|
21
|
+
"yaml": "^2.8.1",
|
|
22
|
+
"yargs": "^18.0.0"
|
|
22
23
|
},
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|
|
@@ -44,7 +45,6 @@
|
|
|
44
45
|
],
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/yaml": "^1.9.6",
|
|
47
|
-
"@types/yargs": "^17.0.33"
|
|
48
|
-
"yargs": "^18.0.0"
|
|
48
|
+
"@types/yargs": "^17.0.33"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/driver.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export interface PSMModel {
|
|
|
70
70
|
apply?: "ALWAYS" | "WHEN" | "WHEN_EXCEPTION";
|
|
71
71
|
from?: "query" | "query:linked" | "relation" | "model";
|
|
72
72
|
expression?: string;
|
|
73
|
+
exists?: string;
|
|
73
74
|
when?: string;
|
|
74
75
|
};
|
|
75
76
|
};
|
|
@@ -131,15 +132,67 @@ export interface PSMMigrator {
|
|
|
131
132
|
test(): Promise<PSMMigrationResult>;
|
|
132
133
|
migrate(): Promise<PSMMigrationResult>;
|
|
133
134
|
}
|
|
135
|
+
export interface QueryBuilderResult {
|
|
136
|
+
sql: string;
|
|
137
|
+
template: string[];
|
|
138
|
+
values: any;
|
|
139
|
+
push(...builders: QueryBuilderResult[]): void;
|
|
140
|
+
}
|
|
141
|
+
export type ScriptLine = {
|
|
142
|
+
line: number;
|
|
143
|
+
filename: string;
|
|
144
|
+
error: Error;
|
|
145
|
+
column: number;
|
|
146
|
+
func: string;
|
|
147
|
+
};
|
|
148
|
+
export type RevisionProps<Props extends {
|
|
149
|
+
[p in keyof Props]: Props[p];
|
|
150
|
+
}> = Props;
|
|
151
|
+
export type RevisionWhen<Props> = boolean | ((props: RevisionProps<Props>) => boolean) | ((props: RevisionProps<Props>) => Promise<boolean>);
|
|
152
|
+
export interface RegistryOptions<Props> {
|
|
153
|
+
identifier?: string;
|
|
154
|
+
connection?: string | "default" | "standard" | "superuser";
|
|
155
|
+
unique?: boolean;
|
|
156
|
+
force?: string;
|
|
157
|
+
flags?: string[];
|
|
158
|
+
level?: "critical" | "normal" | "optional";
|
|
159
|
+
line?: ScriptLine;
|
|
160
|
+
when?: RevisionWhen<Props>;
|
|
161
|
+
}
|
|
162
|
+
export interface SimpleFile {
|
|
163
|
+
filename: string;
|
|
164
|
+
}
|
|
165
|
+
export type PatchOptions<Props> = RegistryOptions<Props> & {
|
|
166
|
+
module?: NodeModule | SimpleFile;
|
|
167
|
+
};
|
|
168
|
+
export type RevisionListener = {
|
|
169
|
+
onRegister?(error: Error, onRelease: () => void): void;
|
|
170
|
+
};
|
|
171
|
+
type SQLTemplate = (sqlTemplate: TemplateStringsArray, ...values: any[]) => QueryBuilderResult & {
|
|
172
|
+
sql: SQLTemplate;
|
|
173
|
+
joins(...builders: QueryBuilderResult[]): void;
|
|
174
|
+
};
|
|
175
|
+
export interface SqlPatch<Props> {
|
|
176
|
+
opts: RegistryOptions<Props> & PatchOptions<Props>;
|
|
177
|
+
str: string | QueryBuilderResult;
|
|
178
|
+
values: any[] | RevisionListener;
|
|
179
|
+
listener?: RevisionListener;
|
|
180
|
+
line: ScriptLine;
|
|
181
|
+
}
|
|
134
182
|
export interface PSMDriver {
|
|
135
183
|
migrated: (opts: PSMMigratedOptions) => Promise<PSMMigrated>;
|
|
136
184
|
generator: (opts: PSMParserOptions) => PSMGenerator;
|
|
137
185
|
migrator: (opts: PSMMigrationOptions) => PSMMigrator;
|
|
138
186
|
prepare: (model: ModelOptions) => Promise<any> | void;
|
|
187
|
+
sql: SQLTemplate;
|
|
188
|
+
joins(...builders: QueryBuilderResult[]): void;
|
|
189
|
+
patch<Props>(opts: PatchOptions<Props>, sql: QueryBuilderResult, listener?: RevisionListener): SqlPatch<Props>;
|
|
190
|
+
patchSQL<Props>(opts?: PatchOptions<Props>, listener?: RevisionListener): SQLTemplate;
|
|
139
191
|
}
|
|
140
192
|
export interface DriverConfigs {
|
|
141
193
|
driver: string;
|
|
142
194
|
url: string;
|
|
143
195
|
sys: string;
|
|
144
196
|
}
|
|
197
|
+
export {};
|
|
145
198
|
//# sourceMappingURL=driver.d.ts.map
|
package/src/driver.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["driver.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACrB,OAAO,CAAC,EAAC,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QACN,UAAU,CAAC,EAAC,MAAM,CAAA;KACrB,CAAA;CACJ;
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["driver.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACrB,OAAO,CAAC,EAAC,MAAM,CAAA;IACf,OAAO,CAA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AAC,EAAE,GAAG,EAAC,kBAAkB,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC5G,QAAQ,CAAE,KAAK,EAAE,IAAI,CAAC,EAAC,YAAY,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAE,WAAW,CAAA;CACvF;AAED,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAC,MAAM,CAAC;IACd,GAAG,EAAC,MAAM,CAAC;IACX,GAAG,EAAC,MAAM,CAAC;CACd"}
|
package/src/driver.ts
CHANGED
|
@@ -5,7 +5,6 @@ export interface PSMField {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
export interface UniqueOptions {
|
|
10
9
|
name:string,
|
|
11
10
|
fields:string[]
|
|
@@ -73,6 +72,7 @@ export interface PSMModel {
|
|
|
73
72
|
apply?:"ALWAYS"|"WHEN"|"WHEN_EXCEPTION",
|
|
74
73
|
from?: "query"|"query:linked"|"relation"|"model"
|
|
75
74
|
expression?:string
|
|
75
|
+
exists?:string
|
|
76
76
|
when?:string
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -145,11 +145,71 @@ export interface PSMMigrator {
|
|
|
145
145
|
test():Promise<PSMMigrationResult>,
|
|
146
146
|
migrate():Promise<PSMMigrationResult>,
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
export interface QueryBuilderResult {
|
|
150
|
+
sql:string,
|
|
151
|
+
template:string[],
|
|
152
|
+
values:any
|
|
153
|
+
push( ...builders:QueryBuilderResult[] ):void
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type ScriptLine = {
|
|
157
|
+
line:number,
|
|
158
|
+
filename: string,
|
|
159
|
+
error:Error,
|
|
160
|
+
column:number,
|
|
161
|
+
func:string
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type RevisionProps<Props extends {[p in keyof Props]:Props[p]}> = Props
|
|
165
|
+
export type RevisionWhen<Props> = boolean|( (props:RevisionProps<Props>)=>boolean)|( (props:RevisionProps<Props>)=>Promise<boolean>);
|
|
166
|
+
|
|
167
|
+
export interface RegistryOptions <Props>{
|
|
168
|
+
identifier?: string;
|
|
169
|
+
connection?: string|"default"|"standard"|"superuser";
|
|
170
|
+
unique?: boolean;
|
|
171
|
+
force?: string;
|
|
172
|
+
flags?: string[];
|
|
173
|
+
level?: "critical" | "normal" | "optional";
|
|
174
|
+
line?:ScriptLine,
|
|
175
|
+
when?:RevisionWhen<Props>
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface SimpleFile {
|
|
179
|
+
filename: string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export type PatchOptions<Props> = RegistryOptions<Props> & {
|
|
183
|
+
module?: NodeModule | SimpleFile
|
|
184
|
+
}
|
|
185
|
+
// Define o tipo de ouvinte de revisão que inclui tratamento de atualização
|
|
186
|
+
export type RevisionListener = {
|
|
187
|
+
onRegister?(error: Error, onRelease: () => void): void;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type SQLTemplate = ( sqlTemplate:TemplateStringsArray, ...values:any[] ) => QueryBuilderResult & {
|
|
191
|
+
sql:SQLTemplate
|
|
192
|
+
joins( ...builders:QueryBuilderResult[] ):void
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface SqlPatch <Props>{
|
|
196
|
+
opts:RegistryOptions<Props> & PatchOptions<Props>
|
|
197
|
+
str: string | QueryBuilderResult;
|
|
198
|
+
values: any[] | RevisionListener;
|
|
199
|
+
listener?: RevisionListener;
|
|
200
|
+
line:ScriptLine
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
148
204
|
export interface PSMDriver {
|
|
149
205
|
migrated:( opts:PSMMigratedOptions )=>Promise<PSMMigrated>,
|
|
150
206
|
generator:( opts:PSMParserOptions )=>PSMGenerator,
|
|
151
207
|
migrator:( opts:PSMMigrationOptions ) =>PSMMigrator,
|
|
152
|
-
prepare: ( model:ModelOptions )=>Promise<any>|void
|
|
208
|
+
prepare: ( model:ModelOptions )=>Promise<any>|void,
|
|
209
|
+
sql:SQLTemplate,
|
|
210
|
+
joins( ...builders:QueryBuilderResult[] ):void
|
|
211
|
+
patch <Props>(opts:PatchOptions<Props>, sql:QueryBuilderResult, listener?: RevisionListener):SqlPatch<Props>
|
|
212
|
+
patchSQL <Props>(opts?:PatchOptions<Props>, listener?: RevisionListener):SQLTemplate
|
|
153
213
|
}
|
|
154
214
|
|
|
155
215
|
export interface DriverConfigs {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandModule } from "yargs";
|
|
2
|
-
import { MigrateOptions } from "../../tools/
|
|
2
|
+
import { MigrateOptions } from "../../tools/commit";
|
|
3
3
|
declare const command: CommandModule<MigrateOptions, MigrateOptions>;
|
|
4
4
|
export = command;
|
|
5
5
|
//# sourceMappingURL=commit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AACpC,OAAO,EAAS,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAG1D,QAAA,MAAM,OAAO,EAAC,aAAa,CAAC,cAAc,EAAE,cAAc,CA4BzD,CAAA;AAED,SAAS,OAAO,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
2
|
+
const commit_1 = require("../../tools/commit");
|
|
3
3
|
const command = {
|
|
4
4
|
command: "commit",
|
|
5
5
|
describe: "Migrate next schema structure into dev environment",
|
|
@@ -20,7 +20,7 @@ const command = {
|
|
|
20
20
|
return args;
|
|
21
21
|
},
|
|
22
22
|
handler: (argv) => {
|
|
23
|
-
(0,
|
|
23
|
+
(0, commit_1.commit)(argv).then(value => {
|
|
24
24
|
console.log("Commited!");
|
|
25
25
|
}).catch(reason => {
|
|
26
26
|
console.error(reason);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit.js","sourceRoot":"","sources":["commit.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"commit.js","sourceRoot":"","sources":["commit.ts"],"names":[],"mappings":";AACA,+CAA0D;AAG1D,MAAM,OAAO,GAAiD;IAC1D,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,oDAAoD;IAC9D,OAAO,EAAE,IAAI,CAAC,EAAE;QACZ,IAAI,CAAC,OAAO,CAAE,QAAQ,EAAE;YACpB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;SACb,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE;YACnB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,GAAG;SACb,CAAC,CAAC,OAAO,CAAE,OAAO,EAAE;YACjB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;SAEb,CAAC,CAAC,OAAO,CAAE,kBAAkB,EAAE;YAC5B,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;SACb,CAAC,CAAA;QAEF,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,EAAC,CAAE,IAAI,EAAE,EAAE;QACd,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACtB,OAAO,CAAC,GAAG,CAAE,WAAW,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAC,KAAK,CAAE,MAAM,CAAC,EAAE;YACf,OAAO,CAAC,KAAK,CAAE,MAAM,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;IACN,CAAC;CACJ,CAAA;AAED,iBAAS,OAAO,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CommandModule} from "yargs";
|
|
2
|
-
import {
|
|
2
|
+
import {commit, MigrateOptions} from "../../tools/commit";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const command:CommandModule<MigrateOptions, MigrateOptions> = {
|
|
@@ -24,7 +24,7 @@ const command:CommandModule<MigrateOptions, MigrateOptions> = {
|
|
|
24
24
|
return args;
|
|
25
25
|
},
|
|
26
26
|
handler:( argv) =>{
|
|
27
|
-
|
|
27
|
+
commit(argv).then(value => {
|
|
28
28
|
console.log( "Commited!")
|
|
29
29
|
}).catch( reason => {
|
|
30
30
|
console.error( reason)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["generate.ts"],"names":[],"mappings":";AACA,mDAA8C;AAG9C,MAAM,OAAO,GAAiB;IAC1B,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,+BAA+B;IACzC,OAAO,EAAE,IAAI,CAAC,EAAE;QACZ,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,IAAI,CAAC,EAAE;QACZ,IAAA,mBAAQ,GAAE,
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["generate.ts"],"names":[],"mappings":";AACA,mDAA8C;AAG9C,MAAM,OAAO,GAAiB;IAC1B,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,+BAA+B;IACzC,OAAO,EAAE,IAAI,CAAC,EAAE;QACZ,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,IAAI,CAAC,EAAE;QACZ,IAAA,mBAAQ,GAAE,CAAA;IACd,CAAC;CACJ,CAAA;AAED,iBAAS,OAAO,CAAC"}
|
|
@@ -4,5 +4,5 @@ export interface MigrateOptions {
|
|
|
4
4
|
label?: string;
|
|
5
5
|
"generate-command": string;
|
|
6
6
|
}
|
|
7
|
-
export declare function
|
|
8
|
-
//# sourceMappingURL=
|
|
7
|
+
export declare function commit(opts: MigrateOptions): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=commit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["commit.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,cAAc;IAC3B,MAAM,CAAC,EAAC,MAAM,CAAA;IACd,QAAQ,CAAC,EAAC,MAAM,CAAA;IAChB,KAAK,CAAC,EAAC,MAAM,CAAA;IACb,kBAAkB,EAAC,MAAM,CAAA;CAC5B;AACD,wBAAsB,MAAM,CAAC,IAAI,EAAC,cAAc,iBA+F/C"}
|
|
@@ -31,17 +31,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
34
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
38
|
+
exports.commit = commit;
|
|
36
39
|
const fs = __importStar(require("node:fs"));
|
|
37
|
-
const yaml = __importStar(require("yaml"));
|
|
38
40
|
const Path = __importStar(require("node:path"));
|
|
41
|
+
const yaml = __importStar(require("yaml"));
|
|
39
42
|
const node_child_process_1 = require("node:child_process");
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function migrate(opts) {
|
|
43
|
+
const deploy_1 = require("./deploy");
|
|
44
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
const common_1 = require("./common");
|
|
46
|
+
function commit(opts) {
|
|
45
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
48
|
require('dotenv').config();
|
|
47
49
|
if (opts.generate) {
|
|
@@ -52,36 +54,15 @@ function migrate(opts) {
|
|
|
52
54
|
cwd: process.cwd()
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
|
-
|
|
56
|
-
if (!schema) {
|
|
57
|
-
schema = prisma.find(value => {
|
|
58
|
-
return fs.existsSync(value);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (!schema) {
|
|
62
|
-
return console.error("Migrate error: schema.prisma file not found!");
|
|
63
|
-
}
|
|
64
|
-
console.log(`PSM migrate base do schema ${schema}`);
|
|
65
|
-
const home = Path.dirname(schema);
|
|
66
|
-
const psm_yml = Path.join(home, "psm.yml");
|
|
67
|
-
const psm_sql = Path.join(home, "psm.sql");
|
|
68
|
-
if (!fs.existsSync(psm_yml)) {
|
|
69
|
-
return console.error("Migrate error: psm.yml file not found!");
|
|
70
|
-
}
|
|
71
|
-
if (!fs.existsSync(psm_sql)) {
|
|
72
|
-
return console.error("Migrate error: psm.sql file not found!");
|
|
73
|
-
}
|
|
74
|
-
console.log(`PSM migrate using ${psm_yml}`);
|
|
75
|
-
const psm = yaml.parse(fs.readFileSync(psm_yml).toString());
|
|
57
|
+
const { psm, psm_sql, driver, home } = yield (0, common_1.psmLockup)({ schema: opts.schema });
|
|
76
58
|
const next = Path.join(psm.psm.output, "next/migration.next.sql");
|
|
77
59
|
const check = Path.join(psm.psm.output, "next/migration.next.check.sql");
|
|
78
60
|
if (!fs.existsSync(check)) {
|
|
79
|
-
|
|
61
|
+
throw new Error("Migrate error: next/migration.next.check.sql file not found!");
|
|
80
62
|
}
|
|
81
63
|
if (!fs.existsSync(next)) {
|
|
82
|
-
|
|
64
|
+
throw new Error("Migrate error: next/migration.next.sql file not found!");
|
|
83
65
|
}
|
|
84
|
-
const driver = yield Promise.resolve(`${psm.psm.driver}`).then(s => __importStar(require(s)));
|
|
85
66
|
const migrator = driver.migrator({
|
|
86
67
|
url: process.env[psm.psm.url],
|
|
87
68
|
migrate: fs.readFileSync(next).toString(),
|
|
@@ -94,7 +75,19 @@ function migrate(opts) {
|
|
|
94
75
|
result.messages.forEach(error => {
|
|
95
76
|
console.error(error);
|
|
96
77
|
});
|
|
97
|
-
|
|
78
|
+
throw new Error("Migrate error: Core failed!");
|
|
79
|
+
}
|
|
80
|
+
const fetchResponse = yield (0, deploy_1.fetch)({
|
|
81
|
+
psm: psm,
|
|
82
|
+
driver: driver,
|
|
83
|
+
home: home
|
|
84
|
+
});
|
|
85
|
+
if (fetchResponse.error) {
|
|
86
|
+
throw fetchResponse.error;
|
|
87
|
+
}
|
|
88
|
+
const noPulled = fetchResponse.revs.filter(n => !n.pulled);
|
|
89
|
+
if (noPulled.length) {
|
|
90
|
+
throw new Error(`Commit not pulled already exists! Please run ${chalk_1.default.bold("psm deploy")} first!`);
|
|
98
91
|
}
|
|
99
92
|
result = yield migrator.test();
|
|
100
93
|
if (!result.success) {
|
|
@@ -102,7 +95,7 @@ function migrate(opts) {
|
|
|
102
95
|
result.messages.forEach(error => {
|
|
103
96
|
console.error(error);
|
|
104
97
|
});
|
|
105
|
-
|
|
98
|
+
throw new Error("Migrate error: Check shadow failed!");
|
|
106
99
|
}
|
|
107
100
|
result = yield migrator.migrate();
|
|
108
101
|
if (!result.success) {
|
|
@@ -110,7 +103,7 @@ function migrate(opts) {
|
|
|
110
103
|
result.messages.forEach(error => {
|
|
111
104
|
console.error(error);
|
|
112
105
|
});
|
|
113
|
-
|
|
106
|
+
throw new Error("Migrate error: Commit migration failed!");
|
|
114
107
|
}
|
|
115
108
|
const moment = require('moment');
|
|
116
109
|
let label = "";
|
|
@@ -152,4 +145,4 @@ function sanitizeLabel(label) {
|
|
|
152
145
|
.trim()
|
|
153
146
|
.replace(/\s+/g, ' '); // normaliza espaços
|
|
154
147
|
}
|
|
155
|
-
//# sourceMappingURL=
|
|
148
|
+
//# sourceMappingURL=commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","sourceRoot":"","sources":["commit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,wBA+FC;AA/GD,4CAA8B;AAC9B,gDAAkC;AAClC,2CAA6B;AAE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IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC3B,CAAC;AAED,SAAS,aAAa,CAAE,KAAY;IAChC,OAAO,KAAK;SACP,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC,CAAC,yCAAyC;SAC/E,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAE,yCAAyC;SAC/E,IAAI,EAAE;SACN,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAiB,oBAAoB;AACnE,CAAC"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
import * as yaml from "yaml";
|
|
3
2
|
import * as Path from "node:path";
|
|
3
|
+
import * as yaml from "yaml";
|
|
4
4
|
import {PSMConfigFile} from "../configs";
|
|
5
|
-
import {PSMDriver} from "../driver";
|
|
6
5
|
import { spawnSync } from "node:child_process";
|
|
7
|
-
import
|
|
6
|
+
import {fetch} from "./deploy";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import {psmLockup} from "./common";
|
|
8
9
|
|
|
9
|
-
const prisma = [
|
|
10
|
-
`${process.cwd()}/schema.prisma`,
|
|
11
|
-
`${process.cwd()}/prisma/schema.prisma`,
|
|
12
|
-
];
|
|
13
10
|
|
|
14
11
|
export interface MigrateOptions {
|
|
15
12
|
schema?:string
|
|
@@ -17,7 +14,7 @@ export interface MigrateOptions {
|
|
|
17
14
|
label?:string
|
|
18
15
|
"generate-command":string
|
|
19
16
|
}
|
|
20
|
-
export async function
|
|
17
|
+
export async function commit(opts:MigrateOptions ) {
|
|
21
18
|
require('dotenv').config();
|
|
22
19
|
if( opts.generate ) {
|
|
23
20
|
let command = opts["generate-command"];
|
|
@@ -26,44 +23,21 @@ export async function migrate( opts:MigrateOptions ) {
|
|
|
26
23
|
cwd: process.cwd()
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
|
-
let schema = opts.schema;
|
|
30
|
-
if( !schema ) {
|
|
31
|
-
schema = prisma.find( value => {
|
|
32
|
-
return fs.existsSync( value );
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
if( !schema ) {
|
|
36
|
-
return console.error( "Migrate error: schema.prisma file not found!" );
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
console.log(`PSM migrate base do schema ${schema}`);
|
|
40
|
-
|
|
41
|
-
const home = Path.dirname( schema );
|
|
42
|
-
const psm_yml = Path.join( home, "psm.yml" );
|
|
43
|
-
const psm_sql = Path.join( home, "psm.sql");
|
|
44
|
-
if( !fs.existsSync( psm_yml ) ) {
|
|
45
|
-
return console.error( "Migrate error: psm.yml file not found!" );
|
|
46
|
-
}
|
|
47
|
-
if( !fs.existsSync( psm_sql ) ) {
|
|
48
|
-
return console.error( "Migrate error: psm.sql file not found!" );
|
|
49
|
-
}
|
|
50
26
|
|
|
51
|
-
|
|
52
|
-
const psm = yaml.parse( fs.readFileSync( psm_yml ).toString() ) as PSMConfigFile;
|
|
27
|
+
const { psm, psm_sql, driver, home } = await psmLockup({ schema: opts.schema });
|
|
53
28
|
const next = Path.join( psm.psm.output, "next/migration.next.sql");
|
|
54
29
|
const check = Path.join( psm.psm.output, "next/migration.next.check.sql");
|
|
55
30
|
|
|
56
31
|
if( !fs.existsSync( check) ) {
|
|
57
|
-
|
|
32
|
+
throw new Error( "Migrate error: next/migration.next.check.sql file not found!" );
|
|
58
33
|
}
|
|
59
34
|
if( !fs.existsSync( next) ) {
|
|
60
|
-
|
|
35
|
+
throw new Error( "Migrate error: next/migration.next.sql file not found!" );
|
|
61
36
|
}
|
|
62
37
|
|
|
63
38
|
|
|
64
|
-
const driver = await import( psm.psm.driver ) as PSMDriver;
|
|
65
39
|
const migrator = driver.migrator({
|
|
66
|
-
url: process.env[psm.psm.url],
|
|
40
|
+
url: process.env[ psm.psm.url ],
|
|
67
41
|
migrate: fs.readFileSync( next ).toString(),
|
|
68
42
|
check: fs.readFileSync( check ).toString(),
|
|
69
43
|
core: fs.readFileSync( psm_sql ).toString(),
|
|
@@ -75,7 +49,24 @@ export async function migrate( opts:MigrateOptions ) {
|
|
|
75
49
|
result.messages.forEach( error => {
|
|
76
50
|
console.error( error );
|
|
77
51
|
});
|
|
78
|
-
|
|
52
|
+
throw new Error( "Migrate error: Core failed!" );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const fetchResponse = await fetch({
|
|
56
|
+
psm: psm,
|
|
57
|
+
driver: driver,
|
|
58
|
+
home: home
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if( fetchResponse.error ) {
|
|
62
|
+
throw fetchResponse.error;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const noPulled = fetchResponse.revs.filter( n=> !n.pulled );
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if( noPulled.length ) {
|
|
69
|
+
throw new Error( `Commit not pulled already exists! Please run ${chalk.bold("psm deploy")} first!` );
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
result = await migrator.test();
|
|
@@ -84,7 +75,7 @@ export async function migrate( opts:MigrateOptions ) {
|
|
|
84
75
|
result.messages.forEach( error => {
|
|
85
76
|
console.error( error );
|
|
86
77
|
});
|
|
87
|
-
|
|
78
|
+
throw new Error( "Migrate error: Check shadow failed!" );
|
|
88
79
|
}
|
|
89
80
|
|
|
90
81
|
|
|
@@ -94,7 +85,7 @@ export async function migrate( opts:MigrateOptions ) {
|
|
|
94
85
|
result.messages.forEach( error => {
|
|
95
86
|
console.error( error );
|
|
96
87
|
});
|
|
97
|
-
|
|
88
|
+
throw new Error( "Migrate error: Commit migration failed!" );
|
|
98
89
|
}
|
|
99
90
|
|
|
100
91
|
const moment = require('moment');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PSMConfigFile } from "../configs";
|
|
2
|
+
import { PSMDriver } from "../driver";
|
|
3
|
+
export interface CommonSchema {
|
|
4
|
+
schema: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function psmLockup(opts: CommonSchema): Promise<{
|
|
7
|
+
schema: string;
|
|
8
|
+
psm_yml: string;
|
|
9
|
+
psm_sql: string;
|
|
10
|
+
psm: PSMConfigFile;
|
|
11
|
+
driver: PSMDriver;
|
|
12
|
+
home: string;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["common.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AASpC,MAAM,WAAW,YAAY;IACzB,MAAM,EAAC,MAAM,CAAA;CAChB;AACD,wBAAsB,SAAS,CAAE,IAAI,EAAC,YAAY;;;;;;;GA6BjD"}
|