@schemavaults/dbh 0.7.3 → 0.7.5
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/dist/migrate.d.ts +8 -3
- package/dist/migrate.js +53 -5
- package/dist/migrate.js.map +1 -1
- package/package.json +1 -1
package/dist/migrate.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
export interface IMigrationResult {
|
|
3
|
+
migrationName: string;
|
|
4
|
+
status: "Success" | "Error" | "NotExecuted";
|
|
5
|
+
direction: "Up" | "Down";
|
|
6
|
+
}
|
|
2
7
|
export interface IMigrateOptions {
|
|
3
8
|
db: Kysely<any>;
|
|
4
9
|
migrationFolder: string;
|
|
@@ -9,6 +14,6 @@ export interface IReverseOptions {
|
|
|
9
14
|
migrationFolder: string;
|
|
10
15
|
version: string;
|
|
11
16
|
}
|
|
12
|
-
export declare function migrate({ db, migrationFolder, ...opts }: IMigrateOptions): Promise<
|
|
13
|
-
export declare function reverse({ db, migrationFolder, version, }: IReverseOptions): Promise<
|
|
17
|
+
export declare function migrate({ db, migrationFolder, ...opts }: IMigrateOptions): Promise<readonly IMigrationResult[]>;
|
|
18
|
+
export declare function reverse({ db, migrationFolder, version, }: IReverseOptions): Promise<IMigrationResult[]>;
|
|
14
19
|
export default migrate;
|
package/dist/migrate.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// migrate.ts
|
|
2
|
+
import { Migrator, FileMigrationProvider, } from "kysely";
|
|
2
3
|
import fs from "fs/promises";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { existsSync } from "fs";
|
|
@@ -12,6 +13,39 @@ function createMigrator({ db, migrationFolder }) {
|
|
|
12
13
|
}),
|
|
13
14
|
});
|
|
14
15
|
}
|
|
16
|
+
function validateMigrationResultFormat(migration_result) {
|
|
17
|
+
if (typeof migration_result !== "object" || !migration_result) {
|
|
18
|
+
throw new TypeError("Expected migration result to be an object!");
|
|
19
|
+
}
|
|
20
|
+
if (!("migrationName" in migration_result) ||
|
|
21
|
+
typeof migration_result.migrationName !== "string") {
|
|
22
|
+
throw new TypeError("Expected migration result's 'migrationName' to be a string!");
|
|
23
|
+
}
|
|
24
|
+
else if (!("direction" in migration_result) ||
|
|
25
|
+
typeof migration_result.direction !== "string") {
|
|
26
|
+
throw new TypeError("Expected migration result's 'direction' to be a string!");
|
|
27
|
+
}
|
|
28
|
+
else if (!("status" in migration_result) ||
|
|
29
|
+
typeof migration_result.status !== "string") {
|
|
30
|
+
throw new TypeError("Expected migration result's 'status' to be a string!");
|
|
31
|
+
}
|
|
32
|
+
else if (!["Up", "Down"].includes(migration_result.direction)) {
|
|
33
|
+
throw new TypeError("Expected migration result's 'direction' to be one of: 'Up' or 'Down'!");
|
|
34
|
+
}
|
|
35
|
+
else if (!["Success", "Error", "NotExecuted"].includes(migration_result.status)) {
|
|
36
|
+
throw new TypeError("Expected migration result's 'status' to be one of: 'Success', 'Error', or 'NotExecuted'!");
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
function validateMigrationResultFormats(results) {
|
|
41
|
+
if (!Array.isArray(results)) {
|
|
42
|
+
throw new TypeError("Expected 'results' to be an array!");
|
|
43
|
+
}
|
|
44
|
+
for (const migration_result of results) {
|
|
45
|
+
validateMigrationResultFormat(migration_result);
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
15
49
|
export async function migrate({ db, migrationFolder, ...opts }) {
|
|
16
50
|
if (typeof migrationFolder !== "string") {
|
|
17
51
|
throw new Error("migrationFolder must be a string");
|
|
@@ -27,11 +61,18 @@ export async function migrate({ db, migrationFolder, ...opts }) {
|
|
|
27
61
|
else {
|
|
28
62
|
result = await migrator.migrateToLatest();
|
|
29
63
|
}
|
|
30
|
-
const { error } = result;
|
|
64
|
+
const { error, results } = result;
|
|
31
65
|
if (error) {
|
|
32
66
|
console.error(error);
|
|
33
|
-
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
if (!results) {
|
|
70
|
+
return [];
|
|
34
71
|
}
|
|
72
|
+
if (!validateMigrationResultFormats(results)) {
|
|
73
|
+
throw new TypeError("Migration appears to have succeeded but failed to parse received results!");
|
|
74
|
+
}
|
|
75
|
+
return results;
|
|
35
76
|
}
|
|
36
77
|
export async function reverse({ db, migrationFolder, version, }) {
|
|
37
78
|
if (typeof migrationFolder !== "string") {
|
|
@@ -41,11 +82,18 @@ export async function reverse({ db, migrationFolder, version, }) {
|
|
|
41
82
|
throw new Error(`migrationFolder '${migrationFolder}' does not exist`);
|
|
42
83
|
}
|
|
43
84
|
const migrator = createMigrator({ db, migrationFolder });
|
|
44
|
-
const { error } = await migrator.migrateTo(version);
|
|
85
|
+
const { error, results } = await migrator.migrateTo(version);
|
|
45
86
|
if (error) {
|
|
46
87
|
console.error(error);
|
|
47
|
-
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
if (!results) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
if (!validateMigrationResultFormats(results)) {
|
|
94
|
+
throw new TypeError("Reverse migration appears to have succeeded but failed to parse received results!");
|
|
48
95
|
}
|
|
96
|
+
return results;
|
|
49
97
|
}
|
|
50
98
|
export default migrate;
|
|
51
99
|
//# sourceMappingURL=migrate.js.map
|
package/dist/migrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA,aAAa;AAEb,OAAO,EAEL,QAAQ,EACR,qBAAqB,GAEtB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,E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