@prisma-psm/pg 1.0.26 → 1.0.28
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/index.js +39 -3
- package/src/index.ts +39 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -16,6 +16,24 @@ function prepare(model) {
|
|
|
16
16
|
if (!model.schema)
|
|
17
17
|
model.schema = "public";
|
|
18
18
|
}
|
|
19
|
+
function executeRaw(scripts) {
|
|
20
|
+
const sql = [];
|
|
21
|
+
if (!!scripts && !Array.isArray(scripts))
|
|
22
|
+
throw new Error(`dsds ds dsdsdsds ${typeof scripts}`);
|
|
23
|
+
if (!scripts || !Array.isArray(scripts) || !scripts.length)
|
|
24
|
+
return null;
|
|
25
|
+
scripts.forEach(value => {
|
|
26
|
+
const filename = value.filename;
|
|
27
|
+
sql.push(`-- =============================== ${value.filename} ========================================`);
|
|
28
|
+
sql.push(`do $$ begin raise notice '%', format( 'Iniciando a execução do script ${filename}...'); end; $$;`);
|
|
29
|
+
sql.push(value.raw.endsWith(";") ? value.raw : `${value.raw};`);
|
|
30
|
+
sql.push(`do $$ begin raise notice '%', format( 'Iniciando a execução do script ${filename}... [OK]'); end; $$;`);
|
|
31
|
+
sql.push("");
|
|
32
|
+
sql.push("");
|
|
33
|
+
sql.push("");
|
|
34
|
+
});
|
|
35
|
+
return sql.join("\n");
|
|
36
|
+
}
|
|
19
37
|
const driver = {
|
|
20
38
|
migrated: (opts) => {
|
|
21
39
|
return (0, migration_1.migrated)(opts);
|
|
@@ -25,17 +43,35 @@ const driver = {
|
|
|
25
43
|
const sql = [];
|
|
26
44
|
sql.push(opts.migrate);
|
|
27
45
|
["functions", "triggers", "views"].forEach(group => {
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
var _a;
|
|
47
|
+
const raw = executeRaw((_a = custom === null || custom === void 0 ? void 0 : custom.resources) === null || _a === void 0 ? void 0 : _a[group]);
|
|
48
|
+
if (!!raw)
|
|
49
|
+
sql.push(raw);
|
|
30
50
|
});
|
|
31
51
|
return (0, migration_1.migrate)({ sql: sql.join(";\n"), url: opts.url, label: "NEXT" });
|
|
32
52
|
},
|
|
53
|
+
migrateRaw: (custom) => {
|
|
54
|
+
const sql = [];
|
|
55
|
+
sql.push(opts.migrate);
|
|
56
|
+
["functions", "triggers", "views"].forEach(group => {
|
|
57
|
+
var _a;
|
|
58
|
+
const raw = executeRaw((_a = custom === null || custom === void 0 ? void 0 : custom.resources) === null || _a === void 0 ? void 0 : _a[group]);
|
|
59
|
+
if (!!raw)
|
|
60
|
+
sql.push(raw);
|
|
61
|
+
});
|
|
62
|
+
return sql.join(";\n");
|
|
63
|
+
},
|
|
33
64
|
test: () => (0, migration_1.migrate)({ sql: opts.check, url: opts.url, label: "TEST" }),
|
|
34
65
|
core: () => (0, migration_1.migrate)({ sql: opts.core, url: opts.url, label: "CORE" }),
|
|
35
66
|
dump: () => (0, dump_1.dump)(opts),
|
|
67
|
+
executeRaw,
|
|
36
68
|
execute(str) {
|
|
37
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const execute = yield (0, migration_1.migrate)({
|
|
70
|
+
const execute = yield (0, migration_1.migrate)({
|
|
71
|
+
sql: executeRaw(str),
|
|
72
|
+
url: opts.url,
|
|
73
|
+
label: "EXECUTE"
|
|
74
|
+
});
|
|
39
75
|
return {
|
|
40
76
|
error: execute.error,
|
|
41
77
|
messages: execute.messages,
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {PSMDriver, ModelOptions, PSMGenerator, PSMMigrationResult, PSMExecute} from "@prisma-psm/core";
|
|
1
|
+
import {PSMDriver, ModelOptions, PSMGenerator, PSMMigrationResult, PSMExecute, CustomScript} from "@prisma-psm/core";
|
|
2
2
|
import {parser} from "./parser/parser";
|
|
3
3
|
import {migrate,migrated} from "./migration";
|
|
4
4
|
import {sql} from "./parser/sql";
|
|
5
5
|
import {dump} from "./dump";
|
|
6
|
+
import fs from "fs";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
@@ -10,24 +11,57 @@ function prepare( model:ModelOptions ){
|
|
|
10
11
|
if( !model.schema ) model.schema = "public";
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
function executeRaw( scripts: CustomScript[] ): string{
|
|
15
|
+
const sql:string[] = [];
|
|
16
|
+
if( !!scripts && !Array.isArray( scripts ) ) throw new Error(`dsds ds dsdsdsds ${typeof scripts}`);
|
|
17
|
+
if( !scripts || !Array.isArray(scripts) || !scripts.length ) return null;
|
|
18
|
+
scripts.forEach(value => {
|
|
19
|
+
const filename:string = value.filename;
|
|
20
|
+
sql.push(`-- =============================== ${value.filename } ========================================` );
|
|
21
|
+
sql.push(`do $$ begin raise notice '%', format( 'Iniciando a execução do script ${filename}...'); end; $$;`);
|
|
22
|
+
sql.push( value.raw.endsWith(";")? value.raw: `${value.raw};`)
|
|
23
|
+
sql.push(`do $$ begin raise notice '%', format( 'Iniciando a execução do script ${filename}... [OK]'); end; $$;`);
|
|
24
|
+
sql.push("" );
|
|
25
|
+
sql.push("" );
|
|
26
|
+
sql.push("" );
|
|
27
|
+
});
|
|
28
|
+
return sql.join("\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
const driver :PSMDriver = {
|
|
14
32
|
migrated:( opts )=>{
|
|
15
33
|
return migrated( opts );
|
|
16
34
|
},
|
|
17
|
-
migrator: opts =>
|
|
35
|
+
migrator: opts =>({
|
|
18
36
|
migrate:( custom ) => {
|
|
19
37
|
const sql = [];
|
|
20
38
|
sql.push( opts.migrate );
|
|
21
39
|
[ "functions", "triggers", "views" ].forEach( group => {
|
|
22
|
-
|
|
40
|
+
const raw = executeRaw( custom?.resources?.[group])
|
|
41
|
+
if( !!raw ) sql.push( raw );
|
|
23
42
|
});
|
|
43
|
+
|
|
24
44
|
return migrate({ sql: sql.join(";\n"), url: opts.url, label: "NEXT" });
|
|
25
45
|
},
|
|
46
|
+
migrateRaw:( custom ) => {
|
|
47
|
+
const sql = [];
|
|
48
|
+
sql.push( opts.migrate );
|
|
49
|
+
[ "functions", "triggers", "views" ].forEach( group => {
|
|
50
|
+
const raw = executeRaw( custom?.resources?.[group])
|
|
51
|
+
if( !!raw ) sql.push( raw );
|
|
52
|
+
});
|
|
53
|
+
return sql.join(";\n");
|
|
54
|
+
},
|
|
26
55
|
test:() => migrate({ sql: opts.check, url: opts.url, label: "TEST" }),
|
|
27
56
|
core:() => migrate({ sql: opts.core, url: opts.url, label: "CORE" }),
|
|
28
57
|
dump:() => dump( opts ),
|
|
29
|
-
|
|
30
|
-
|
|
58
|
+
executeRaw,
|
|
59
|
+
async execute(str: CustomScript[]): Promise<PSMExecute> {
|
|
60
|
+
const execute = await migrate({
|
|
61
|
+
sql: executeRaw(str),
|
|
62
|
+
url: opts.url,
|
|
63
|
+
label: "EXECUTE"
|
|
64
|
+
});
|
|
31
65
|
return {
|
|
32
66
|
error: execute.error,
|
|
33
67
|
messages: execute.messages,
|