@prisma-psm/pg 1.0.5 → 1.0.7
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/vcs.xml +1 -0
- package/package.json +1 -1
- package/src/index.js +15 -6
- package/src/index.ts +22 -10
- package/src/migration/index.d.ts +2 -1
- package/src/migration/index.d.ts.map +1 -1
- package/src/migration/index.js +39 -0
- package/src/migration/index.js.map +1 -1
- package/src/migration/index.ts +43 -1
- package/src/parser/backup/engine.d.ts +4 -1
- package/src/parser/backup/engine.d.ts.map +1 -1
- package/src/parser/backup/engine.js +53 -33
- package/src/parser/backup/engine.js.map +1 -1
- package/src/parser/backup/engine.ts +58 -33
- package/src/parser/backup/index.d.ts +4 -1
- package/src/parser/backup/index.d.ts.map +1 -1
- package/src/parser/def.d.ts +5 -3
- package/src/parser/def.d.ts.map +1 -1
- package/src/parser/def.ts +9 -2
- package/src/parser/modelParser.d.ts +4 -1
- package/src/parser/modelParser.d.ts.map +1 -1
- package/src/parser/notice.js +1 -1
- package/src/parser/notice.ts +2 -2
- package/src/parser/parser.d.ts +6 -1
- package/src/parser/parser.d.ts.map +1 -1
- package/src/parser/parser.js +16 -16
- package/src/parser/parser.js.map +1 -1
- package/src/parser/parser.ts +31 -18
- package/src/parser/schama.d.ts +3 -0
- package/src/parser/schama.d.ts.map +1 -0
- package/src/parser/schama.js +16 -0
- package/src/parser/schama.js.map +1 -0
- package/src/parser/schama.ts +14 -0
- package/src/parser/sql.d.ts +4 -1
- package/src/parser/sql.d.ts.map +1 -1
- package/src/parser/sql.js +47 -20
- package/src/parser/sql.js.map +1 -1
- package/src/parser/sql.ts +33 -22
- package/src/parser/sys.d.ts.map +1 -1
- package/src/parser/sys.js +2 -6
- package/src/parser/sys.js.map +1 -1
- package/src/parser/sys.ts +3 -5
- package/src/parser/table/engine.js +2 -2
- package/src/parser/table/engine.ts +3 -3
- package/src/sql/catalog-maps.d.ts +1 -0
- package/src/sql/catalog-maps.d.ts.map +1 -0
- package/src/sql/catalog-maps.js +283 -0
- package/src/sql/catalog-maps.js.map +1 -0
- package/src/sql/catalog-maps.ts +281 -0
- package/src/sql/sql-builder.d.ts +1 -0
- package/src/sql/sql-builder.d.ts.map +1 -0
- package/src/sql/sql-builder.js +256 -0
- package/src/sql/sql-builder.js.map +1 -0
- package/src/sql/sql-builder.ts +254 -0
- package/src/utils/escape.d.ts +5 -1
- package/src/utils/escape.d.ts.map +1 -1
- package/src/utils/escape.js +328 -4
- package/src/utils/escape.js.map +1 -1
- package/src/utils/escape.ts +331 -4
- package/src/utils/script-util.d.ts +26 -0
- package/src/utils/script-util.d.ts.map +1 -0
- package/src/utils/script-util.js +95 -0
- package/src/utils/script-util.js.map +1 -0
- package/src/utils/script-util.ts +105 -0
package/src/parser/def.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ModelOptions, PSMParserOptions } from "@prisma-psm/core";
|
|
2
2
|
export interface PostgresParserOptions extends PSMParserOptions {
|
|
3
|
-
mode: "check" | "migrate";
|
|
4
3
|
}
|
|
5
4
|
export interface ParseModelResult {
|
|
6
5
|
model: ModelOptions;
|
|
7
|
-
backup
|
|
6
|
+
backup?: {
|
|
8
7
|
create: string[];
|
|
9
|
-
restore:
|
|
8
|
+
restore: {
|
|
9
|
+
data: string[];
|
|
10
|
+
registry: string[];
|
|
11
|
+
};
|
|
10
12
|
restore_serial: string[];
|
|
11
13
|
clean: string[];
|
|
12
14
|
};
|
package/src/parser/def.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"def.d.ts","sourceRoot":"","sources":["def.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAEhE,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;
|
|
1
|
+
{"version":3,"file":"def.d.ts","sourceRoot":"","sources":["def.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAEhE,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;CAC9D;AAED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,CAAC,EAAE;QACL,MAAM,EAAC,MAAM,EAAE,CAAC;QAChB,OAAO,EAAC;YACJ,IAAI,EAAC,MAAM,EAAE,CAAC;YACd,QAAQ,EAAC,MAAM,EAAE,CAAA;SACpB,CAAC;QACF,cAAc,EAAC,MAAM,EAAE,CAAC;QACxB,KAAK,EAAC,MAAM,EAAE,CAAA;KACjB,CAAA;IACD,KAAK,EAAE;QAAE,MAAM,EAAC,MAAM,EAAE,CAAC;QAAC,IAAI,EAAC,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAC,MAAM,EAAE,CAAA;KAAE,CAAA;IAC5D,OAAO,EAAE;QAAG,MAAM,EAAC,MAAM,EAAE,CAAC;QAAC,IAAI,EAAC,MAAM,EAAE,CAAA;KAAE,CAAA;IAC5C,OAAO,EAAE;QAAE,MAAM,EAAC,MAAM,EAAE,CAAC;QAAC,IAAI,EAAC,MAAM,EAAE,CAAA;KAAE,CAAA;IAC3C,MAAM,EAAE;QAAE,MAAM,EAAC,MAAM,EAAE,CAAC;QAAC,IAAI,EAAC,MAAM,EAAE,CAAA;KAAE,CAAA;IAC1C,OAAO,EAAE;QAAE,MAAM,EAAC,MAAM,EAAE,CAAC;QAAC,IAAI,EAAC,MAAM,EAAE,CAAA;KAAE,CAAA;IAC3C,YAAY,EAAC,MAAM,EAAE,CAAA;IACrB,UAAU,EAAC,MAAM,EAAE,CAAA;CACtB"}
|
package/src/parser/def.ts
CHANGED
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
import {ModelOptions, PSMParserOptions} from "@prisma-psm/core";
|
|
4
4
|
|
|
5
5
|
export interface PostgresParserOptions extends PSMParserOptions{
|
|
6
|
-
mode:"check"|"migrate"
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
export interface ParseModelResult {
|
|
10
9
|
model: ModelOptions,
|
|
11
|
-
backup
|
|
10
|
+
backup?: {
|
|
11
|
+
create:string[],
|
|
12
|
+
restore:{
|
|
13
|
+
data:string[],
|
|
14
|
+
registry:string[]
|
|
15
|
+
},
|
|
16
|
+
restore_serial:string[],
|
|
17
|
+
clean:string[]
|
|
18
|
+
}
|
|
12
19
|
table: { create:string[], drop:string[], allocate:string[] }
|
|
13
20
|
primary: { create:string[], drop:string[] }
|
|
14
21
|
foreign: { create:string[], drop:string[] }
|
|
@@ -12,7 +12,10 @@ export declare function modelParser(model: ModelOptions, parser: PostgresParserO
|
|
|
12
12
|
drop_table: () => string[];
|
|
13
13
|
allocate_table: () => string[];
|
|
14
14
|
create_table: () => string[];
|
|
15
|
-
restore_backup: () =>
|
|
15
|
+
restore_backup: () => {
|
|
16
|
+
data: string[];
|
|
17
|
+
registry: string[];
|
|
18
|
+
};
|
|
16
19
|
restore_serial: () => string[];
|
|
17
20
|
depends: () => string[];
|
|
18
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelParser.d.ts","sourceRoot":"","sources":["modelParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AAM5C,wBAAgB,WAAW,CAAE,KAAK,EAAC,YAAY,EAAE,MAAM,EAAC,qBAAqB
|
|
1
|
+
{"version":3,"file":"modelParser.d.ts","sourceRoot":"","sources":["modelParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AAM5C,wBAAgB,WAAW,CAAE,KAAK,EAAC,YAAY,EAAE,MAAM,EAAC,qBAAqB;;;;;;;;;;;;;;;;;;EAsB5E"}
|
package/src/parser/notice.js
CHANGED
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.notice = notice;
|
|
4
4
|
const escape_1 = require("../utils/escape");
|
|
5
5
|
function notice(message) {
|
|
6
|
-
return `do $$ begin raise notice '%', ${(0, escape_1.
|
|
6
|
+
return `do $$ begin raise notice '%', ${(0, escape_1.lit)(message)}; end $$;`;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=notice.js.map
|
package/src/parser/notice.ts
CHANGED
package/src/parser/parser.d.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { ParseModelResult, PostgresParserOptions } from "./def";
|
|
|
2
2
|
export interface ParserResult {
|
|
3
3
|
options: PostgresParserOptions;
|
|
4
4
|
models: string[];
|
|
5
|
-
core:
|
|
5
|
+
core: {
|
|
6
|
+
schema: string[];
|
|
7
|
+
structure: string[];
|
|
8
|
+
functions: string[];
|
|
9
|
+
migration: string[];
|
|
10
|
+
};
|
|
6
11
|
shadow: {
|
|
7
12
|
create: string[];
|
|
8
13
|
drop: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,gBAAgB,EAAE,qBAAqB,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,gBAAgB,EAAE,qBAAqB,EAAC,MAAM,OAAO,CAAC;AAI9D,MAAM,WAAW,YAAY;IACzB,OAAO,EAAC,qBAAqB,CAAA;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE;QACF,MAAM,EAAC,MAAM,EAAE,CAAA;QACf,SAAS,EAAC,MAAM,EAAE,CAAA;QAClB,SAAS,EAAC,MAAM,EAAE,CAAA;QAClB,SAAS,EAAC,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,MAAM,EAAE;QAAE,MAAM,EAAC,MAAM,EAAE,CAAC;QAAE,IAAI,EAAC,MAAM,EAAE,CAAA;KAAE,CAAC;IAC5C,MAAM,EAAE;QACJ,CAAC,CAAC,EAAC,MAAM,GAAE,gBAAgB,CAAA;KAC9B,CAAA;CACJ;AAED,wBAAgB,MAAM,CAAE,IAAI,EAAC,qBAAqB,gBAyEjD"}
|
package/src/parser/parser.js
CHANGED
|
@@ -7,17 +7,19 @@ const sys_1 = require("./sys");
|
|
|
7
7
|
const dependencies_1 = require("./dependencies");
|
|
8
8
|
const modelParser_1 = require("./modelParser");
|
|
9
9
|
const engine_1 = require("./backup/engine");
|
|
10
|
+
const schama_1 = require("./schama");
|
|
10
11
|
function parser(opts) {
|
|
11
12
|
const schemas = new Set();
|
|
12
13
|
let response = {
|
|
13
14
|
options: opts,
|
|
14
15
|
parsed: {},
|
|
15
16
|
models: [],
|
|
16
|
-
core:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
core: {
|
|
18
|
+
schema: (0, schama_1.schema)(opts),
|
|
19
|
+
structure: (0, sys_1.prepareCore)(opts),
|
|
20
|
+
functions: (0, engine_1.createFunctionRestoreSerial)(opts),
|
|
21
|
+
migration: (0, sys_1.createMigration)(opts),
|
|
22
|
+
},
|
|
21
23
|
shadow: {
|
|
22
24
|
create: [...(0, shadow_1.create_shadow)(opts)],
|
|
23
25
|
drop: [...(0, shadow_1.drop_shadow)(opts)],
|
|
@@ -32,20 +34,20 @@ function parser(opts) {
|
|
|
32
34
|
const modelDDL = (0, modelParser_1.modelParser)(model, opts);
|
|
33
35
|
const parsed = {
|
|
34
36
|
model: model,
|
|
35
|
-
backup: { create: [], restore:
|
|
37
|
+
backup: { create: [], restore: null, restore_serial: [], clean: [] },
|
|
36
38
|
table: { create: [], drop: [], allocate: [] },
|
|
37
39
|
primary: { create: [], drop: [] },
|
|
38
40
|
foreign: { create: [], drop: [] },
|
|
39
41
|
unique: { create: [], drop: [] },
|
|
40
42
|
indexes: { create: [], drop: [] },
|
|
41
43
|
dependencies: [],
|
|
42
|
-
dependents: []
|
|
44
|
+
dependents: [],
|
|
43
45
|
};
|
|
44
46
|
let backup = true;
|
|
45
47
|
if ((_c = (_b = model.psm) === null || _b === void 0 ? void 0 : _b.backup) === null || _c === void 0 ? void 0 : _c.skip)
|
|
46
48
|
backup = false;
|
|
47
49
|
if (backup) {
|
|
48
|
-
parsed.backup.restore
|
|
50
|
+
parsed.backup.restore = modelDDL.restore_backup();
|
|
49
51
|
parsed.backup.restore_serial.push(...modelDDL.restore_serial());
|
|
50
52
|
}
|
|
51
53
|
parsed.table.create.push(...modelDDL.create_table());
|
|
@@ -53,14 +55,12 @@ function parser(opts) {
|
|
|
53
55
|
parsed.foreign.create.push(...modelDDL.create_foreign_key());
|
|
54
56
|
parsed.unique.create.push(...modelDDL.create_unique_key());
|
|
55
57
|
parsed.indexes.create.push(...modelDDL.create_index_key());
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
parsed.indexes.drop.push(...modelDDL.drop_index_key());
|
|
63
|
-
}
|
|
58
|
+
parsed.table.drop.push(...modelDDL.drop_table());
|
|
59
|
+
parsed.table.allocate.push(...modelDDL.allocate_table());
|
|
60
|
+
parsed.foreign.drop.push(...modelDDL.drop_foreign_key());
|
|
61
|
+
parsed.unique.drop.push(...modelDDL.drop_unique_key());
|
|
62
|
+
parsed.primary.drop.push(...modelDDL.drop_primary_keys());
|
|
63
|
+
parsed.indexes.drop.push(...modelDDL.drop_index_key());
|
|
64
64
|
parsed.dependencies.push(...modelDDL.depends());
|
|
65
65
|
response.parsed[model.name] = parsed;
|
|
66
66
|
response.models.push(model.name);
|
package/src/parser/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":";AAAA,qCAAqC;;
|
|
1
|
+
{"version":3,"file":"parser.js","sour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from "./modelParser";
|
|
7
7
|
import {createFunctionRestoreSerial} from "./backup/engine";
|
|
8
8
|
import {ParseModelResult, PostgresParserOptions} from "./def";
|
|
9
|
+
import {schema} from "./schama";
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
export interface ParserResult {
|
|
12
13
|
options:PostgresParserOptions
|
|
13
14
|
models: string[],
|
|
14
|
-
core:
|
|
15
|
+
core: {
|
|
16
|
+
schema:string[]
|
|
17
|
+
structure:string[]
|
|
18
|
+
functions:string[]
|
|
19
|
+
migration:string[]
|
|
20
|
+
}
|
|
15
21
|
shadow: { create:string[], drop:string[] },
|
|
16
22
|
parsed: {
|
|
17
23
|
[p:string]:ParseModelResult
|
|
@@ -24,11 +30,12 @@ export function parser( opts:PostgresParserOptions){
|
|
|
24
30
|
options: opts,
|
|
25
31
|
parsed:{},
|
|
26
32
|
models:[],
|
|
27
|
-
core:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
core: {
|
|
34
|
+
schema: schema( opts ),
|
|
35
|
+
structure: prepareCore(opts),
|
|
36
|
+
functions: createFunctionRestoreSerial(opts),
|
|
37
|
+
migration: createMigration(opts),
|
|
38
|
+
},
|
|
32
39
|
shadow:{
|
|
33
40
|
create: [...create_shadow( opts )],
|
|
34
41
|
drop: [...drop_shadow( opts )],
|
|
@@ -42,46 +49,52 @@ export function parser( opts:PostgresParserOptions){
|
|
|
42
49
|
if( model.psm?.view ) return;
|
|
43
50
|
model.indexes = opts.indexes.filter( value => value.model === model.model );
|
|
44
51
|
|
|
52
|
+
|
|
45
53
|
const modelDDL = modelParser( model, opts );
|
|
46
54
|
const parsed:ParseModelResult = {
|
|
47
55
|
model: model,
|
|
48
|
-
backup:{ create:[], restore:
|
|
56
|
+
backup:{ create:[], restore:null, restore_serial:[], clean:[] },
|
|
49
57
|
table:{ create:[], drop:[], allocate:[]},
|
|
50
58
|
primary:{ create:[], drop:[] },
|
|
51
59
|
foreign:{ create:[], drop:[] },
|
|
52
60
|
unique:{ create:[], drop:[] },
|
|
53
61
|
indexes:{ create:[], drop:[] },
|
|
54
62
|
dependencies:[],
|
|
55
|
-
dependents:[]
|
|
63
|
+
dependents:[],
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
let backup = true;
|
|
59
67
|
if( model.psm?.backup?.skip ) backup = false;
|
|
60
68
|
|
|
69
|
+
|
|
61
70
|
if( backup ){
|
|
62
|
-
|
|
71
|
+
|
|
72
|
+
parsed.backup.restore = modelDDL.restore_backup();
|
|
63
73
|
parsed.backup.restore_serial.push( ...modelDDL.restore_serial());
|
|
64
74
|
}
|
|
65
75
|
|
|
76
|
+
|
|
66
77
|
parsed.table.create.push( ...modelDDL.create_table());
|
|
67
78
|
parsed.primary.create.push( ...modelDDL.create_primary_keys())
|
|
68
79
|
parsed.foreign.create.push( ...modelDDL.create_foreign_key() );
|
|
69
80
|
parsed.unique.create.push( ...modelDDL.create_unique_key());
|
|
70
81
|
parsed.indexes.create.push( ...modelDDL.create_index_key());
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
83
|
+
parsed.table.drop.push( ...modelDDL.drop_table());
|
|
84
|
+
parsed.table.allocate.push( ...modelDDL.allocate_table());
|
|
85
|
+
parsed.foreign.drop.push( ...modelDDL.drop_foreign_key());
|
|
86
|
+
parsed.unique.drop.push( ...modelDDL.drop_unique_key());
|
|
87
|
+
parsed.primary.drop.push(...modelDDL.drop_primary_keys());
|
|
88
|
+
parsed.indexes.drop.push( ...modelDDL.drop_index_key());
|
|
89
|
+
|
|
80
90
|
|
|
81
91
|
parsed.dependencies.push( ...modelDDL.depends());
|
|
82
92
|
response.parsed[model.name] = parsed;
|
|
83
93
|
response.models.push( model.name)
|
|
84
94
|
});
|
|
85
|
-
|
|
95
|
+
|
|
96
|
+
reverseDependencies( Object.values( response.parsed ));
|
|
97
|
+
|
|
98
|
+
|
|
86
99
|
return response;
|
|
87
100
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schama.d.ts","sourceRoot":"","sources":["schama.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AAG5C,wBAAgB,MAAM,CAAE,MAAM,EAAC,qBAAqB,YAUnD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = schema;
|
|
4
|
+
const escape_1 = require("../utils/escape");
|
|
5
|
+
function schema(parser) {
|
|
6
|
+
let schemas = new Set();
|
|
7
|
+
parser.models.forEach(value => {
|
|
8
|
+
let schema = value.schema || "public";
|
|
9
|
+
if (!schemas.has(schema))
|
|
10
|
+
schemas.add(schema);
|
|
11
|
+
});
|
|
12
|
+
return [...schemas].map(value => {
|
|
13
|
+
return `create schema if not exists ${(0, escape_1.oid)(value)};`;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=schama.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schama.js","sourceRoot":"","sources":["schama.ts"],"names":[],"mappings":";;AAGA,wBAUC;AAZD,4CAAoC;AAEpC,SAAgB,MAAM,CAAE,MAA4B;IAChD,IAAI,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAE,KAAK,CAAC,EAAE;QAC3B,IAAI,MAAM,GAAG,KAAK,CAAC,MAAM,IAAE,QAAQ,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAE,MAAM,CAAE;YAAG,OAAO,CAAC,GAAG,CAAE,MAAM,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAE,KAAK,CAAC,EAAE;QAC7B,OAAO,+BAA+B,IAAA,YAAG,EAAC,KAAK,CAAC,GAAG,CAAA;IACvD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {PostgresParserOptions} from "./def";
|
|
2
|
+
import {oid} from "../utils/escape";
|
|
3
|
+
|
|
4
|
+
export function schema( parser:PostgresParserOptions ){
|
|
5
|
+
let schemas = new Set<string>();
|
|
6
|
+
parser.models.forEach( value => {
|
|
7
|
+
let schema = value.schema||"public";
|
|
8
|
+
if( !schemas.has( schema ) ) schemas.add( schema);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return [...schemas].map( value => {
|
|
12
|
+
return `create schema if not exists ${oid(value)};`
|
|
13
|
+
});
|
|
14
|
+
}
|
package/src/parser/sql.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ParserResult } from "./parser";
|
|
2
|
-
export
|
|
2
|
+
export interface SQLOptions {
|
|
3
|
+
mode: "check" | "migrate" | "core";
|
|
4
|
+
}
|
|
5
|
+
export declare function sql(opts: SQLOptions, response: ParserResult): string;
|
|
3
6
|
//# sourceMappingURL=sql.d.ts.map
|
package/src/parser/sql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAEtC,wBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,OAAO,GAAC,SAAS,GAAC,MAAM,CAAA;CACjC;AACD,wBAAgB,GAAG,CAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,UAgF5D"}
|
package/src/parser/sql.js
CHANGED
|
@@ -1,67 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sql = sql;
|
|
4
|
-
function sql(response) {
|
|
4
|
+
function sql(opts, response) {
|
|
5
5
|
let parsed = Object.values(response.parsed);
|
|
6
6
|
const commands = [];
|
|
7
7
|
commands.push(`/*
|
|
8
8
|
@PSM - Prisma SAFE MIGRATE
|
|
9
9
|
@author zootakuxy
|
|
10
10
|
@automation cli psm
|
|
11
|
-
@mode ${
|
|
11
|
+
@mode ${opts.mode}
|
|
12
12
|
@date ${new Date().toISOString()}
|
|
13
13
|
*/`);
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (["core"].includes(opts.mode))
|
|
15
|
+
commands.push(...response.core.structure);
|
|
16
|
+
if (["core"].includes(opts.mode))
|
|
17
|
+
commands.push(...response.core.functions);
|
|
18
|
+
if (["migrate"].includes(opts.mode))
|
|
19
|
+
commands.push(...response.core.migration);
|
|
20
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
21
|
+
commands.push(...response.shadow.create);
|
|
16
22
|
//Create Table
|
|
17
23
|
parsed.filter(value => !!value.table.create.length).forEach(value => {
|
|
18
|
-
|
|
24
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
25
|
+
commands.push(...value.table.create);
|
|
19
26
|
});
|
|
20
27
|
//Restore
|
|
21
|
-
parsed.filter(value => !!value.backup.restore.length).forEach(value => {
|
|
22
|
-
|
|
28
|
+
parsed.filter(value => { var _a, _b, _c; return !!((_c = (_b = (_a = value.backup) === null || _a === void 0 ? void 0 : _a.restore) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.length); }).forEach(value => {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
31
|
+
commands.push(...(_b = (_a = value.backup) === null || _a === void 0 ? void 0 : _a.restore) === null || _b === void 0 ? void 0 : _b.data);
|
|
32
|
+
if (["migrate"].includes(opts.mode))
|
|
33
|
+
commands.push(...value.backup.restore.registry);
|
|
23
34
|
});
|
|
24
35
|
parsed.filter(value => !!value.backup.restore_serial.length).forEach(value => {
|
|
25
|
-
|
|
36
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
37
|
+
commands.push(...value.backup.restore_serial);
|
|
26
38
|
});
|
|
27
39
|
//Create indexes
|
|
28
40
|
parsed.filter(value => !!value.indexes.create.length).forEach(value => {
|
|
29
|
-
|
|
41
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
42
|
+
commands.push(...value.indexes.create);
|
|
30
43
|
});
|
|
31
44
|
//Create constraints
|
|
32
45
|
parsed.filter(value => !!value.primary.create.length).forEach(value => {
|
|
33
|
-
|
|
46
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
47
|
+
commands.push(...value.primary.create);
|
|
34
48
|
});
|
|
35
49
|
parsed.filter(value => !!value.unique.create.length).forEach(value => {
|
|
36
|
-
|
|
50
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
51
|
+
commands.push(...value.unique.create);
|
|
37
52
|
});
|
|
38
53
|
parsed.filter(value => !!value.foreign.create.length).forEach(value => {
|
|
39
|
-
|
|
54
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
55
|
+
commands.push(...value.foreign.create);
|
|
40
56
|
});
|
|
57
|
+
//Schemas
|
|
58
|
+
if (opts.mode === "migrate")
|
|
59
|
+
commands.push(...response.core.schema);
|
|
41
60
|
//Drops
|
|
42
61
|
parsed.filter(value => !!value.foreign.drop.length).forEach(value => {
|
|
43
|
-
|
|
62
|
+
if (opts.mode === "migrate")
|
|
63
|
+
commands.push(...value.foreign.drop);
|
|
44
64
|
});
|
|
45
65
|
parsed.filter(value => !!value.unique.drop.length).forEach(value => {
|
|
46
|
-
|
|
66
|
+
if (opts.mode === "migrate")
|
|
67
|
+
commands.push(...value.unique.drop);
|
|
47
68
|
});
|
|
48
69
|
parsed.filter(value => !!value.primary.drop.length).forEach(value => {
|
|
49
|
-
|
|
70
|
+
if (opts.mode === "migrate")
|
|
71
|
+
commands.push(...value.primary.drop);
|
|
50
72
|
});
|
|
51
73
|
parsed.filter(value => !!value.indexes.drop.length).forEach(value => {
|
|
52
|
-
|
|
74
|
+
if (opts.mode === "migrate")
|
|
75
|
+
commands.push(...value.indexes.drop);
|
|
53
76
|
});
|
|
54
77
|
parsed.filter(value => !!value.table.drop.length).forEach(value => {
|
|
55
|
-
|
|
78
|
+
if (opts.mode === "migrate")
|
|
79
|
+
commands.push(...value.table.drop);
|
|
56
80
|
});
|
|
57
81
|
//Clean backup
|
|
58
82
|
parsed.filter(value => !!value.table.allocate.length).forEach(value => {
|
|
59
|
-
|
|
83
|
+
if (opts.mode === "migrate")
|
|
84
|
+
commands.push(...value.table.allocate);
|
|
60
85
|
});
|
|
61
86
|
parsed.filter(value => !!value.backup.clean.length).forEach(value => {
|
|
62
|
-
|
|
87
|
+
if (opts.mode === "migrate")
|
|
88
|
+
commands.push(...value.backup.clean);
|
|
63
89
|
});
|
|
64
|
-
|
|
90
|
+
if (["migrate", "check"].includes(opts.mode))
|
|
91
|
+
commands.push(...response.shadow.drop);
|
|
65
92
|
return commands.join("\n");
|
|
66
93
|
}
|
|
67
94
|
//# sourceMappingURL=sql.js.map
|
package/src/parser/sql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.js","sourceRoot":"","sources":["sql.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sql.js","sourceRoot":"","sources":["sql.ts"],"names":[],"mappings":";;AAKA,kBAgFC;AAhFD,SAAgB,GAAG,CAAE,IAAgB,EAAE,QAAsB;IACzD,IAAI,MAAM,GAAI,MAAM,CAAC,MAAM,CAAE,QAAQ,CAAC,MAAM,CAAE,CAAC;IAC/C,MAAM,QAAQ,GAAY,EAAE,CAAC;IAI7B,QAAQ,CAAC,IAAI,CAAE;;;;cAIJ,IAAI,CAAC,IAAK;cACV,IAAI,IAAI,EAAE,CAAC,WAAW,EAAG;OACjC,CAAC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E,CAAC,CAAC,CAAA;IAEF,cAAc;IACd,MAAM,CAAC,MAAM,CAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAE,CAAC,OAAO,CAAE,KAAK,CAAC,EAAE;QACrE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAI,QAAQ,CAAC,IAAI,CAAE,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAE,CAAC;IAC5E,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,CAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAE,CAAC,OAAO,CAAE,KAAK,CAAC,EAAE;QACnE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAG,QAAQ,CAAC,IAAI,CAAE,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAE,CAAC;IACzE,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,SAAS,EAAE,OAAO,CAAE,CAAC,QAAQ,CAAE,IAAI,CAAC,IAAI,CAAE;QAAE,QAAQ,CAAC,IAAI,CAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC;IAE1F,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
package/src/parser/sql.ts
CHANGED
|
@@ -1,75 +1,86 @@
|
|
|
1
1
|
import {ParserResult} from "./parser";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface SQLOptions {
|
|
4
|
+
mode: "check"|"migrate"|"core"
|
|
5
|
+
}
|
|
6
|
+
export function sql( opts: SQLOptions, response: ParserResult ) {
|
|
4
7
|
let parsed = Object.values( response.parsed );
|
|
5
8
|
const commands:string[] = [];
|
|
6
9
|
|
|
10
|
+
|
|
11
|
+
|
|
7
12
|
commands.push( `/*
|
|
8
13
|
@PSM - Prisma SAFE MIGRATE
|
|
9
14
|
@author zootakuxy
|
|
10
15
|
@automation cli psm
|
|
11
|
-
@mode ${
|
|
16
|
+
@mode ${ opts.mode }
|
|
12
17
|
@date ${ new Date().toISOString() }
|
|
13
18
|
*/`);
|
|
14
19
|
|
|
15
|
-
commands.push( ...response.core );
|
|
16
|
-
commands.push( ...response.
|
|
20
|
+
if( [ "core" ].includes(opts.mode)) commands.push( ...response.core.structure );
|
|
21
|
+
if( [ "core" ].includes(opts.mode)) commands.push( ...response.core.functions );
|
|
22
|
+
if( [ "migrate" ].includes( opts.mode)) commands.push( ...response.core.migration );
|
|
23
|
+
if( [ "migrate", "check" ].includes( opts.mode)) commands.push( ...response.shadow.create );
|
|
17
24
|
|
|
18
25
|
//Create Table
|
|
19
26
|
parsed.filter( value => !!value.table.create.length ).forEach( value => {
|
|
20
|
-
commands.push( ...value.table.create );
|
|
27
|
+
if( [ "migrate", "check" ].includes(opts.mode)) commands.push( ...value.table.create );
|
|
21
28
|
})
|
|
22
29
|
|
|
23
30
|
//Restore
|
|
24
|
-
parsed.filter( value => !!value.backup
|
|
25
|
-
commands.push( ...value.backup
|
|
31
|
+
parsed.filter( value => !!value.backup?.restore?.data?.length ).forEach( value => {
|
|
32
|
+
if( [ "migrate", "check" ].includes(opts.mode)) commands.push( ...value.backup?.restore?.data );
|
|
33
|
+
if( [ "migrate" ].includes(opts.mode)) commands.push( ...value.backup.restore.registry );
|
|
26
34
|
});
|
|
27
35
|
parsed.filter( value => !!value.backup.restore_serial.length ).forEach( value => {
|
|
28
|
-
commands.push( ...value.backup.restore_serial );
|
|
36
|
+
if( [ "migrate", "check" ].includes(opts.mode)) commands.push( ...value.backup.restore_serial );
|
|
29
37
|
});
|
|
30
38
|
|
|
31
39
|
//Create indexes
|
|
32
40
|
parsed.filter( value => !!value.indexes.create.length ).forEach( value => {
|
|
33
|
-
commands.push( ...value.indexes.create );
|
|
41
|
+
if( ["migrate", "check" ].includes(opts.mode)) commands.push( ...value.indexes.create );
|
|
34
42
|
})
|
|
35
43
|
|
|
36
44
|
//Create constraints
|
|
37
45
|
parsed.filter( value => !!value.primary.create.length ).forEach( value => {
|
|
38
|
-
commands.push( ...value.primary.create );
|
|
39
|
-
})
|
|
46
|
+
if( ["migrate", "check" ].includes(opts.mode)) commands.push( ...value.primary.create );
|
|
47
|
+
});
|
|
40
48
|
parsed.filter( value => !!value.unique.create.length ).forEach( value => {
|
|
41
|
-
commands.push( ...value.unique.create );
|
|
42
|
-
})
|
|
49
|
+
if( ["migrate", "check" ].includes(opts.mode)) commands.push( ...value.unique.create );
|
|
50
|
+
});
|
|
43
51
|
parsed.filter( value => !!value.foreign.create.length ).forEach( value => {
|
|
44
|
-
commands.push( ...value.foreign.create );
|
|
52
|
+
if( ["migrate", "check" ].includes(opts.mode)) commands.push( ...value.foreign.create );
|
|
45
53
|
});
|
|
46
54
|
|
|
55
|
+
//Schemas
|
|
56
|
+
if( opts.mode === "migrate" ) commands.push( ...response.core.schema );
|
|
57
|
+
|
|
47
58
|
//Drops
|
|
48
59
|
parsed.filter( value => !!value.foreign.drop.length ).forEach( value => {
|
|
49
|
-
commands.push( ...value.foreign.drop );
|
|
60
|
+
if( opts.mode === "migrate" ) commands.push( ...value.foreign.drop );
|
|
50
61
|
});
|
|
51
62
|
|
|
52
63
|
parsed.filter( value => !!value.unique.drop.length ).forEach( value => {
|
|
53
|
-
commands.push( ...value.unique.drop );
|
|
64
|
+
if( opts.mode === "migrate" ) commands.push( ...value.unique.drop );
|
|
54
65
|
})
|
|
55
66
|
parsed.filter( value => !!value.primary.drop.length ).forEach( value => {
|
|
56
|
-
commands.push( ...value.primary.drop );
|
|
67
|
+
if( opts.mode === "migrate" ) commands.push( ...value.primary.drop );
|
|
57
68
|
})
|
|
58
69
|
parsed.filter( value => !!value.indexes.drop.length ).forEach( value => {
|
|
59
|
-
commands.push( ...value.indexes.drop );
|
|
70
|
+
if( opts.mode === "migrate" ) commands.push( ...value.indexes.drop );
|
|
60
71
|
})
|
|
61
72
|
parsed.filter( value => !!value.table.drop.length ).forEach( value => {
|
|
62
|
-
commands.push( ...value.table.drop );
|
|
73
|
+
if( opts.mode === "migrate" ) commands.push( ...value.table.drop );
|
|
63
74
|
})
|
|
64
75
|
|
|
65
76
|
//Clean backup
|
|
66
77
|
parsed.filter( value => !!value.table.allocate.length ).forEach( value => {
|
|
67
|
-
commands.push( ...value.table.allocate );
|
|
78
|
+
if( opts.mode === "migrate" ) commands.push( ...value.table.allocate );
|
|
68
79
|
});
|
|
69
80
|
parsed.filter( value => !!value.backup.clean.length ).forEach( value => {
|
|
70
|
-
commands.push( ...value.backup.clean );
|
|
81
|
+
if( opts.mode === "migrate" ) commands.push( ...value.backup.clean );
|
|
71
82
|
});
|
|
72
|
-
commands.push( ...response.shadow.drop );
|
|
83
|
+
if( ["migrate", "check" ].includes( opts.mode )) commands.push( ...response.shadow.drop );
|
|
73
84
|
|
|
74
85
|
return commands.join("\n");
|
|
75
86
|
}
|
package/src/parser/sys.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sys.d.ts","sourceRoot":"","sources":["sys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AAK5C,wBAAgB,WAAW,CAAE,IAAI,EAAC,qBAAqB,YAkBtD;AACD,wBAAgB,eAAe,CAAE,IAAI,EAAC,qBAAqB,
|
|
1
|
+
{"version":3,"file":"sys.d.ts","sourceRoot":"","sources":["sys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AAK5C,wBAAgB,WAAW,CAAE,IAAI,EAAC,qBAAqB,YAkBtD;AACD,wBAAgB,eAAe,CAAE,IAAI,EAAC,qBAAqB,YAO1D;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAC,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB;AACD,wBAAgB,cAAc,CAAC,IAAI,EAAC,qBAAqB,EAAE,SAAS,EAAC,gBAAgB,YAcpF"}
|