@prisma-psm/pg 1.0.12 → 1.0.14

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-psm/pg",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Prisma Safe Migration Postgres Driver",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,6 @@
1
+ import { PSMDumpResponse } from "@prisma-psm/core";
2
+ export interface DumpOptions {
3
+ url: string;
4
+ }
5
+ export declare function dump(opts: DumpOptions): Promise<PSMDumpResponse>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAkChE"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.dump = dump;
27
+ const cp = __importStar(require("child_process"));
28
+ function dump(opts) {
29
+ return new Promise((resolve) => {
30
+ const progress = cp.spawn("pg_dump", ["-cOv", "--if-exists", opts.url]);
31
+ const chunks = []; // guarda chunks de stdout
32
+ let errorOutput = "";
33
+ let error = null;
34
+ // Captura stdout em chunks de Buffer
35
+ progress.stdout.on("data", (chunk) => {
36
+ chunks.push(chunk);
37
+ });
38
+ // Captura stderr
39
+ progress.stderr.on("data", (chunk) => {
40
+ errorOutput += chunk.toString();
41
+ console.error(chunk.toString());
42
+ });
43
+ progress.on("error", (err) => {
44
+ error = err;
45
+ });
46
+ progress.on("exit", (code) => {
47
+ if (error) {
48
+ resolve({ error });
49
+ }
50
+ else if (code !== 0) {
51
+ resolve({ error: new Error(`pg_dump failed with code ${code}\n${errorOutput}`) });
52
+ }
53
+ else {
54
+ const output = Buffer.concat(chunks).toString("utf-8");
55
+ resolve({ output: output });
56
+ }
57
+ });
58
+ });
59
+ }
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOA,oBAkCC;AAxCD,kDAAoC;AAMpC,SAAgB,IAAI,CAAC,IAAiB;IAClC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAExE,MAAM,MAAM,GAAa,EAAE,CAAC,CAAC,0BAA0B;QACvD,IAA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+
4
+ export interface DumpOptions {
5
+ url: string;
6
+ }
7
+
8
+ export function dump(opts: DumpOptions): Promise<PSMDumpResponse> {
9
+ return new Promise((resolve) => {
10
+ const progress = cp.spawn("pg_dump", ["-cOv", "--if-exists", opts.url]);
11
+
12
+ const chunks: Buffer[] = []; // guarda chunks de stdout
13
+ let errorOutput = "";
14
+ let error: Error | null = null;
15
+
16
+ // Captura stdout em chunks de Buffer
17
+ progress.stdout.on("data", (chunk: Buffer) => {
18
+ chunks.push(chunk);
19
+ });
20
+
21
+ // Captura stderr
22
+ progress.stderr.on("data", (chunk) => {
23
+ errorOutput += chunk.toString();
24
+ console.error(chunk.toString());
25
+ });
26
+
27
+ progress.on("error", (err) => {
28
+ error = err;
29
+ });
30
+
31
+ progress.on("exit", (code) => {
32
+ if (error) {
33
+ resolve({ error });
34
+ } else if (code !== 0) {
35
+ resolve({ error: new Error(`pg_dump failed with code ${code}\n${errorOutput}`) });
36
+ } else {
37
+ const output = Buffer.concat(chunks).toString("utf-8");
38
+ resolve({ output: output });
39
+ }
40
+ });
41
+ });
42
+ }
package/src/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  const parser_1 = require("./parser/parser");
3
3
  const migration_1 = require("./migration");
4
4
  const sql_1 = require("./parser/sql");
5
+ const dump_1 = require("./dump");
5
6
  function prepare(model) {
6
7
  if (!model.schema)
7
8
  model.schema = "public";
@@ -14,6 +15,7 @@ const driver = {
14
15
  migrate: () => (0, migration_1.migrate)({ sql: opts.migrate, url: opts.url, label: "NEXT" }),
15
16
  test: () => (0, migration_1.migrate)({ sql: opts.check, url: opts.url, label: "TEST" }),
16
17
  core: () => (0, migration_1.migrate)({ sql: opts.core, url: opts.url, label: "CORE" }),
18
+ dump: () => (0, dump_1.dump)(opts)
17
19
  }),
18
20
  generator: (opts) => {
19
21
  let response = (0, parser_1.parser)(opts);
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
- import {PSMDriver, ModelOptions, PSMGenerator} from "@prisma-psm/core";
1
+ import {PSMDriver, ModelOptions, PSMGenerator, PSMMigrationResult} 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
+ import {dump} from "./dump";
5
6
 
6
7
 
7
8
 
@@ -15,9 +16,10 @@ const driver :PSMDriver = {
15
16
  return migrated( opts );
16
17
  },
17
18
  migrator: opts => ({
18
- migrate: () => migrate({ sql: opts.migrate, url: opts.url, label: "NEXT" }),
19
- test: () => migrate({ sql: opts.check, url: opts.url, label: "TEST" }),
20
- core: () => migrate({ sql: opts.core, url: opts.url, label: "CORE" }),
19
+ migrate:() => migrate({ sql: opts.migrate, url: opts.url, label: "NEXT" }),
20
+ test:() => migrate({ sql: opts.check, url: opts.url, label: "TEST" }),
21
+ core:() => migrate({ sql: opts.core, url: opts.url, label: "CORE" }),
22
+ dump:() => dump( opts )
21
23
  }),
22
24
 
23
25
  generator:(opts) => {
@@ -31,5 +33,5 @@ const driver :PSMDriver = {
31
33
  return generator;
32
34
  },
33
35
  prepare,
34
- } as PSMDriver
36
+ }
35
37
  export = driver