@riao/dbal 3.7.1 → 3.8.1
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/CHANGELOG.md +3 -3
- package/LICENSE.md +20 -20
- package/README.md +148 -148
- package/builder/builder.d.ts +7 -7
- package/builder/builder.js +19 -19
- package/builder/index.d.ts +2 -2
- package/builder/index.js +7 -7
- package/builder/sql-builder.d.ts +53 -53
- package/builder/sql-builder.js +157 -157
- package/builder/statement-builder.d.ts +12 -12
- package/builder/statement-builder.js +32 -32
- package/column/column-options.d.ts +156 -156
- package/column/column-options.js +2 -2
- package/column/column-type.d.ts +18 -18
- package/column/column-type.js +27 -27
- package/column/column-values.d.ts +34 -34
- package/column/column-values.js +2 -2
- package/column/index.d.ts +3 -3
- package/column/index.js +19 -19
- package/column-pack/date-time/create-timestamp-column.d.ts +2 -2
- package/column-pack/date-time/create-timestamp-column.js +10 -10
- package/column-pack/date-time/index.d.ts +2 -2
- package/column-pack/date-time/index.js +7 -7
- package/column-pack/date-time/update-timestamp-column.d.ts +2 -2
- package/column-pack/date-time/update-timestamp-column.js +14 -14
- package/column-pack/index.d.ts +6 -6
- package/column-pack/index.js +22 -22
- package/column-pack/keys/big-int-key-column.d.ts +2 -2
- package/column-pack/keys/big-int-key-column.js +10 -10
- package/column-pack/keys/index.d.ts +3 -3
- package/column-pack/keys/index.js +9 -9
- package/column-pack/keys/int-key-column.d.ts +2 -2
- package/column-pack/keys/int-key-column.js +10 -10
- package/column-pack/keys/uuid-key-column.d.ts +2 -2
- package/column-pack/keys/uuid-key-column.js +11 -11
- package/column-pack/person/date-of-birth-column.d.ts +2 -2
- package/column-pack/person/date-of-birth-column.js +8 -8
- package/column-pack/person/first-name-column.d.ts +2 -2
- package/column-pack/person/first-name-column.js +9 -9
- package/column-pack/person/index.d.ts +3 -3
- package/column-pack/person/index.js +9 -9
- package/column-pack/person/last-name-column.d.ts +2 -2
- package/column-pack/person/last-name-column.js +9 -9
- package/column-pack/resource/content-column.d.ts +2 -2
- package/column-pack/resource/content-column.js +9 -9
- package/column-pack/resource/description-column.d.ts +2 -2
- package/column-pack/resource/description-column.js +9 -9
- package/column-pack/resource/index.d.ts +6 -6
- package/column-pack/resource/index.js +15 -15
- package/column-pack/resource/is-active-column.d.ts +2 -2
- package/column-pack/resource/is-active-column.js +9 -9
- package/column-pack/resource/name-column.d.ts +2 -2
- package/column-pack/resource/name-column.js +10 -10
- package/column-pack/resource/path-column.d.ts +2 -2
- package/column-pack/resource/path-column.js +11 -11
- package/column-pack/resource/title-column.d.ts +2 -2
- package/column-pack/resource/title-column.js +10 -10
- package/column-pack/system/filename-column.d.ts +2 -2
- package/column-pack/system/filename-column.js +9 -9
- package/column-pack/system/filepath-column.d.ts +2 -2
- package/column-pack/system/filepath-column.js +9 -9
- package/column-pack/system/index.d.ts +4 -4
- package/column-pack/system/index.js +11 -11
- package/column-pack/system/ip-address-column.d.ts +2 -2
- package/column-pack/system/ip-address-column.js +9 -9
- package/column-pack/system/url-column.d.ts +3 -3
- package/column-pack/system/url-column.js +13 -13
- package/column-pack/user/email-column.d.ts +2 -2
- package/column-pack/user/email-column.js +11 -11
- package/column-pack/user/index.d.ts +4 -4
- package/column-pack/user/index.js +11 -11
- package/column-pack/user/password-column.d.ts +2 -2
- package/column-pack/user/password-column.js +10 -10
- package/column-pack/user/temp-email-column.d.ts +2 -2
- package/column-pack/user/temp-email-column.js +5 -5
- package/column-pack/user/username-column.d.ts +2 -2
- package/column-pack/user/username-column.js +11 -11
- package/comparison/comparison-aliases.d.ts +10 -10
- package/comparison/comparison-aliases.js +40 -40
- package/comparison/comparison-token.d.ts +17 -17
- package/comparison/comparison-token.js +15 -15
- package/comparison/comparison.d.ts +13 -13
- package/comparison/comparison.js +71 -71
- package/comparison/index.d.ts +4 -4
- package/comparison/index.js +24 -24
- package/comparison/is-comparison-token.d.ts +2 -2
- package/comparison/is-comparison-token.js +8 -8
- package/config/configure-db.d.ts +14 -14
- package/config/configure-db.js +18 -18
- package/config/database-env.d.ts +16 -16
- package/config/database-env.js +14 -14
- package/config/index.d.ts +2 -2
- package/config/index.js +7 -7
- package/database/connection-options.d.ts +7 -7
- package/database/connection-options.js +2 -2
- package/database/database.d.ts +204 -204
- package/database/database.js +330 -330
- package/database/driver-query.d.ts +10 -10
- package/database/driver-query.js +2 -2
- package/database/driver.d.ts +12 -12
- package/database/driver.js +47 -47
- package/database/get-database-path.d.ts +6 -6
- package/database/get-database-path.js +12 -12
- package/database/index.d.ts +7 -7
- package/database/index.js +26 -26
- package/database/load-database.d.ts +9 -9
- package/database/load-database.js +36 -36
- package/database/transaction.d.ts +8 -8
- package/database/transaction.js +2 -2
- package/ddl/alter-table.d.ts +26 -26
- package/ddl/alter-table.js +2 -2
- package/ddl/create-database.d.ts +3 -3
- package/ddl/create-database.js +2 -2
- package/ddl/create-index.d.ts +5 -5
- package/ddl/create-index.js +2 -2
- package/ddl/create-table.d.ts +8 -8
- package/ddl/create-table.js +2 -2
- package/ddl/create-user.d.ts +4 -4
- package/ddl/create-user.js +2 -2
- package/ddl/ddl-builder.d.ts +96 -96
- package/ddl/ddl-builder.js +565 -565
- package/ddl/ddl-repository.d.ts +135 -135
- package/ddl/ddl-repository.js +228 -228
- package/ddl/drop-database.d.ts +4 -4
- package/ddl/drop-database.js +2 -2
- package/ddl/drop-table.d.ts +4 -4
- package/ddl/drop-table.js +2 -2
- package/ddl/drop-user.d.ts +4 -4
- package/ddl/drop-user.js +2 -2
- package/ddl/foreign-key-constraint.d.ts +19 -19
- package/ddl/foreign-key-constraint.js +2 -2
- package/ddl/grant.d.ts +12 -12
- package/ddl/grant.js +2 -2
- package/ddl/index.d.ts +13 -13
- package/ddl/index.js +23 -23
- package/ddl/truncate.d.ts +3 -3
- package/ddl/truncate.js +2 -2
- package/dml/case-expression.d.ts +16 -16
- package/dml/case-expression.js +11 -11
- package/dml/delete.d.ts +8 -8
- package/dml/delete.js +2 -2
- package/dml/from.d.ts +4 -4
- package/dml/from.js +2 -2
- package/dml/group-by.d.ts +4 -4
- package/dml/group-by.js +2 -2
- package/dml/index.d.ts +11 -11
- package/dml/index.js +30 -30
- package/dml/insert.d.ts +14 -14
- package/dml/insert.js +2 -2
- package/dml/join.d.ts +7 -7
- package/dml/join.js +2 -2
- package/dml/order-by.d.ts +2 -2
- package/dml/order-by.js +2 -2
- package/dml/query-builder.d.ts +106 -106
- package/dml/query-builder.js +797 -793
- package/dml/query-builder.js.map +1 -1
- package/dml/query-repository.d.ts +84 -84
- package/dml/query-repository.js +239 -225
- package/dml/query-repository.js.map +1 -1
- package/dml/select.d.ts +29 -29
- package/dml/select.js +2 -2
- package/dml/set-options.d.ts +5 -5
- package/dml/set-options.js +2 -2
- package/dml/subquery.d.ts +5 -5
- package/dml/subquery.js +10 -10
- package/dml/update.d.ts +11 -11
- package/dml/update.js +2 -2
- package/expression/expression-token.d.ts +11 -11
- package/expression/expression-token.js +12 -12
- package/expression/expression.d.ts +6 -6
- package/expression/expression.js +2 -2
- package/expression/identifier.d.ts +7 -7
- package/expression/identifier.js +15 -15
- package/expression/index.d.ts +7 -7
- package/expression/index.js +25 -25
- package/expression/is-expression-token.d.ts +2 -2
- package/expression/is-expression-token.js +7 -7
- package/expression/key-val-expression.d.ts +7 -7
- package/expression/key-val-expression.js +2 -2
- package/expression/literal.d.ts +3 -3
- package/expression/literal.js +2 -2
- package/expression/logical.d.ts +18 -18
- package/expression/logical.js +30 -30
- package/expression/math.d.ts +17 -17
- package/expression/math.js +36 -36
- package/expression/raw.d.ts +8 -8
- package/expression/raw.js +16 -16
- package/expression/simple-expression.d.ts +8 -8
- package/expression/simple-expression.js +2 -2
- package/functions/function-aliases.d.ts +4 -4
- package/functions/function-aliases.js +12 -12
- package/functions/function-token.d.ts +29 -29
- package/functions/function-token.js +15 -15
- package/functions/functions.d.ts +19 -19
- package/functions/functions.js +94 -94
- package/functions/index.d.ts +4 -4
- package/functions/index.js +22 -22
- package/functions/is-database-function.d.ts +8 -8
- package/functions/is-database-function.js +14 -14
- package/functions/signatures/count.d.ts +14 -11
- package/functions/signatures/count.js +2 -2
- package/index.d.ts +16 -16
- package/index.js +32 -32
- package/migration/index.d.ts +3 -2
- package/migration/index.js +9 -7
- package/migration/index.js.map +1 -1
- package/migration/migration-package.d.ts +14 -0
- package/migration/migration-package.js +11 -0
- package/migration/migration-package.js.map +1 -0
- package/migration/migration-record.d.ts +10 -9
- package/migration/migration-record.js +2 -2
- package/migration/migration-runner.d.ts +33 -22
- package/migration/migration-runner.js +180 -131
- package/migration/migration-runner.js.map +1 -1
- package/migration/migration.d.ts +12 -12
- package/migration/migration.js +27 -27
- package/migration/{create-migration-table.d.ts → migrations/001-create-migration-table.d.ts} +8 -8
- package/migration/{create-migration-table.js → migrations/001-create-migration-table.js} +55 -55
- package/migration/migrations/001-create-migration-table.js.map +1 -0
- package/migration/migrations/002-add-migration-package-column.d.ts +9 -0
- package/migration/migrations/002-add-migration-package-column.js +45 -0
- package/migration/migrations/002-add-migration-package-column.js.map +1 -0
- package/package.json +1 -1
- package/record/index.d.ts +1 -1
- package/record/index.js +17 -17
- package/record/record.d.ts +2 -2
- package/record/record.js +2 -2
- package/repository/index.d.ts +2 -2
- package/repository/index.js +5 -5
- package/repository/repository-options.d.ts +6 -6
- package/repository/repository-options.js +2 -2
- package/repository/repository.d.ts +29 -29
- package/repository/repository.js +68 -68
- package/schema/index.d.ts +3 -3
- package/schema/index.js +5 -5
- package/schema/schema-query-repository.d.ts +54 -54
- package/schema/schema-query-repository.js +159 -159
- package/schema/schema-table.d.ts +9 -9
- package/schema/schema-table.js +2 -2
- package/schema/schema.d.ts +4 -4
- package/schema/schema.js +2 -2
- package/seed/auto-seed.d.ts +9 -9
- package/seed/auto-seed.js +61 -61
- package/seed/create-seed-table.d.ts +8 -8
- package/seed/create-seed-table.js +64 -64
- package/seed/index.d.ts +4 -4
- package/seed/index.js +9 -9
- package/seed/seed-record.d.ts +11 -11
- package/seed/seed-record.js +2 -2
- package/seed/seed-runner.d.ts +20 -20
- package/seed/seed-runner.js +91 -91
- package/seed/seed.d.ts +12 -12
- package/seed/seed.js +27 -27
- package/tokens/index.d.ts +1 -1
- package/tokens/index.js +5 -5
- package/triggers/index.d.ts +2 -2
- package/triggers/index.js +18 -18
- package/triggers/prebuilt/index.d.ts +1 -1
- package/triggers/prebuilt/index.js +5 -5
- package/triggers/prebuilt/update-timestamp-trigger.d.ts +16 -16
- package/triggers/prebuilt/update-timestamp-trigger.js +24 -24
- package/triggers/trigger-options.d.ts +22 -22
- package/triggers/trigger-options.js +2 -2
- package/triggers/trigger.d.ts +19 -19
- package/triggers/trigger.js +23 -23
- package/column-pack/user/login-column.d.ts +0 -2
- package/column-pack/user/login-column.js +0 -12
- package/column-pack/user/login-column.js.map +0 -1
- package/migration/create-migration-table.js.map +0 -1
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
import { Database } from '../database';
|
|
2
|
-
import { Migration } from './migration';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @param
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { Database } from '../database';
|
|
2
|
+
import { Migration } from './migration';
|
|
3
|
+
import { MigrationPackage } from './migration-package';
|
|
4
|
+
/**
|
|
5
|
+
* Runs migrations
|
|
6
|
+
*/
|
|
7
|
+
export declare class MigrationRunner {
|
|
8
|
+
protected db: Database;
|
|
9
|
+
constructor(db: Database);
|
|
10
|
+
/**
|
|
11
|
+
* Run migrations
|
|
12
|
+
* @deprecated This method will change parameters in a future release.
|
|
13
|
+
* Switch to runWithOptions() to prepare for this change.
|
|
14
|
+
*
|
|
15
|
+
* @param migrations (Optional) Folder to find migrations in. Default is
|
|
16
|
+
* db.getMigraitonDirectory()
|
|
17
|
+
* @param log (Optional) Log function. Defaults to console.log
|
|
18
|
+
* @param direction (Optional) Run migrations up or down?
|
|
19
|
+
* @param steps (Optional) Run a certain number of steps?
|
|
20
|
+
*/
|
|
21
|
+
run(migrations?: string | Record<string, Migration | MigrationPackage>, log?: (...args: any[]) => void, direction?: 'up' | 'down', steps?: number): Promise<void>;
|
|
22
|
+
runWithOptions(options: {
|
|
23
|
+
migrations?: string | Record<string, Migration | MigrationPackage>;
|
|
24
|
+
log?: (...args: any[]) => void;
|
|
25
|
+
direction?: 'up' | 'down';
|
|
26
|
+
steps?: number;
|
|
27
|
+
package?: string;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
protected getMigrationName(filename: string): string;
|
|
30
|
+
protected loadMigration(dir: string, filename: string): Migration;
|
|
31
|
+
protected loadMigrationsFromDirectory(dir: string): Record<string, Migration>;
|
|
32
|
+
protected runRiaoDbalMigrations(): Promise<void>;
|
|
33
|
+
}
|
|
@@ -1,132 +1,181 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.MigrationRunner = void 0;
|
|
13
|
-
const fs = require("fs");
|
|
14
|
-
const path_1 = require("path");
|
|
15
|
-
const ts_import_ts_1 = require("ts-import-ts");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @param
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
log(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MigrationRunner = void 0;
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const ts_import_ts_1 = require("ts-import-ts");
|
|
16
|
+
const _001_create_migration_table_1 = require("./migrations/001-create-migration-table");
|
|
17
|
+
const migration_package_1 = require("./migration-package");
|
|
18
|
+
const _002_add_migration_package_column_1 = require("./migrations/002-add-migration-package-column");
|
|
19
|
+
/**
|
|
20
|
+
* Runs migrations
|
|
21
|
+
*/
|
|
22
|
+
class MigrationRunner {
|
|
23
|
+
constructor(db) {
|
|
24
|
+
this.db = db;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Run migrations
|
|
28
|
+
* @deprecated This method will change parameters in a future release.
|
|
29
|
+
* Switch to runWithOptions() to prepare for this change.
|
|
30
|
+
*
|
|
31
|
+
* @param migrations (Optional) Folder to find migrations in. Default is
|
|
32
|
+
* db.getMigraitonDirectory()
|
|
33
|
+
* @param log (Optional) Log function. Defaults to console.log
|
|
34
|
+
* @param direction (Optional) Run migrations up or down?
|
|
35
|
+
* @param steps (Optional) Run a certain number of steps?
|
|
36
|
+
*/
|
|
37
|
+
run(migrations,
|
|
38
|
+
/* eslint-disable-next-line no-console */
|
|
39
|
+
log = console.log, direction = 'up', steps) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return yield this.runWithOptions({
|
|
42
|
+
migrations,
|
|
43
|
+
log,
|
|
44
|
+
direction,
|
|
45
|
+
steps,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
runWithOptions(options) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const name = options.package || this.db.name || 'database';
|
|
52
|
+
let migrations = options.migrations || this.db.getMigrationsDirectory();
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
const optionsLog = options.log || console.log;
|
|
55
|
+
const log = (...args) => {
|
|
56
|
+
optionsLog(`[${name}]\t`, ...args);
|
|
57
|
+
};
|
|
58
|
+
const direction = options.direction || 'up';
|
|
59
|
+
let steps = options.steps;
|
|
60
|
+
const pkg = options.package || null;
|
|
61
|
+
if (steps === -1) {
|
|
62
|
+
steps = undefined;
|
|
63
|
+
}
|
|
64
|
+
if (steps !== undefined && steps < 0) {
|
|
65
|
+
throw new Error('Steps must be a positive integer, or -1 for all.');
|
|
66
|
+
}
|
|
67
|
+
// Create migration table, if not existing
|
|
68
|
+
yield this.runRiaoDbalMigrations();
|
|
69
|
+
// Query migrations that have already run
|
|
70
|
+
const repo = this.db.getQueryRepository();
|
|
71
|
+
const alreadyRanMigrations = yield repo.find({
|
|
72
|
+
columns: ['name'],
|
|
73
|
+
table: 'riao_migration',
|
|
74
|
+
where: { package: pkg ? pkg : null },
|
|
75
|
+
});
|
|
76
|
+
const alreadyRanNames = alreadyRanMigrations.map((migration) => migration.name);
|
|
77
|
+
if (typeof migrations === 'string') {
|
|
78
|
+
// Get migration files in folder
|
|
79
|
+
migrations = this.loadMigrationsFromDirectory(migrations);
|
|
80
|
+
}
|
|
81
|
+
const migrationNames = Object.keys(migrations);
|
|
82
|
+
if (!migrationNames.length) {
|
|
83
|
+
log('No migrations found!');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// Check which migrations need to run
|
|
87
|
+
let migrationsToRun;
|
|
88
|
+
if (direction === 'up') {
|
|
89
|
+
migrationsToRun = migrationNames.filter((file) => !alreadyRanNames.includes(file));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
migrationsToRun = alreadyRanNames.reverse();
|
|
93
|
+
}
|
|
94
|
+
if (!migrationsToRun.length) {
|
|
95
|
+
log('All migrations have already run');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
log(`Discovered ${migrationsToRun.length} ` +
|
|
99
|
+
'pending migrations in this direction.');
|
|
100
|
+
if (steps !== undefined) {
|
|
101
|
+
migrationsToRun = migrationsToRun.slice(0, steps);
|
|
102
|
+
}
|
|
103
|
+
log(`Running ${migrationsToRun.length} migrations...`);
|
|
104
|
+
// Run each migration
|
|
105
|
+
for (const name of migrationsToRun) {
|
|
106
|
+
// Run the migration
|
|
107
|
+
log(direction.toLocaleUpperCase() + ' | ', name);
|
|
108
|
+
const migration = migrations[name];
|
|
109
|
+
if (migration instanceof migration_package_1.MigrationPackage) {
|
|
110
|
+
log('Importing packaged migrations for ' +
|
|
111
|
+
migration.name +
|
|
112
|
+
'...');
|
|
113
|
+
const importedMigrationTypes = yield migration.getMigrations();
|
|
114
|
+
const PackagedMigrations = Object.keys(importedMigrationTypes).reduce((obj, key) => {
|
|
115
|
+
const migrationType = importedMigrationTypes[key];
|
|
116
|
+
obj[key] = new migrationType(this.db);
|
|
117
|
+
return obj;
|
|
118
|
+
}, {});
|
|
119
|
+
yield this.runWithOptions(Object.assign(Object.assign({}, options), { steps: undefined, migrations: PackagedMigrations, package: migration.package }));
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
yield migration[direction]();
|
|
123
|
+
// Save the migration record
|
|
124
|
+
if (direction === 'up') {
|
|
125
|
+
yield repo.insert({
|
|
126
|
+
table: 'riao_migration',
|
|
127
|
+
records: { name, package: pkg ? pkg : null },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
yield repo.delete({
|
|
132
|
+
table: 'riao_migration',
|
|
133
|
+
where: { name, package: pkg ? pkg : null },
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
log('Rebuilding Schema...');
|
|
138
|
+
yield this.db.buildSchema();
|
|
139
|
+
log('Migrations Complete!');
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
getMigrationName(filename) {
|
|
143
|
+
return (0, path_1.basename)(filename.toLowerCase(), (0, path_1.extname)(filename));
|
|
144
|
+
}
|
|
145
|
+
loadMigration(dir, filename) {
|
|
146
|
+
const path = (0, path_1.join)(dir, filename);
|
|
147
|
+
const migrationType = (0, ts_import_ts_1.tsimport)(path);
|
|
148
|
+
const migration = new migrationType(this.db);
|
|
149
|
+
return migration;
|
|
150
|
+
}
|
|
151
|
+
loadMigrationsFromDirectory(dir) {
|
|
152
|
+
return fs
|
|
153
|
+
.readdirSync(dir)
|
|
154
|
+
.filter((filename) => /\.ts$/.test(filename))
|
|
155
|
+
.map((filename) => ({
|
|
156
|
+
name: this.getMigrationName(filename),
|
|
157
|
+
migration: this.loadMigration(dir, filename),
|
|
158
|
+
}))
|
|
159
|
+
.reduce((obj, item) => {
|
|
160
|
+
obj[item.name] = item.migration;
|
|
161
|
+
return obj;
|
|
162
|
+
}, {});
|
|
163
|
+
}
|
|
164
|
+
runRiaoDbalMigrations() {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
// Create table, if not existing
|
|
167
|
+
const createMigrationTable = new _001_create_migration_table_1.CreateMigrationTable(this.db);
|
|
168
|
+
yield createMigrationTable.up();
|
|
169
|
+
// Check if `package` column exists, and if not, add it
|
|
170
|
+
const columns = yield this.db
|
|
171
|
+
.getSchemaQueryRepository()
|
|
172
|
+
.getColumns({ table: 'riao_migration' });
|
|
173
|
+
if (!columns.find((col) => col.name === 'package')) {
|
|
174
|
+
const addMigrationPackageColumn = new _002_add_migration_package_column_1.AddMigrationPackageColumn(this.db);
|
|
175
|
+
yield addMigrationPackageColumn.up();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.MigrationRunner = MigrationRunner;
|
|
132
181
|
//# sourceMappingURL=migration-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-runner.js","sourceRoot":"","sources":["../../../src/migration/migration-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yBAAyB;AACzB,+BAA2D;AAC3D,+CAAwC;AAGxC,
|
|
1
|
+
{"version":3,"file":"migration-runner.js","sourceRoot":"","sources":["../../../src/migration/migration-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yBAAyB;AACzB,+BAA2D;AAC3D,+CAAwC;AAGxC,yFAA+E;AAG/E,2DAAuD;AACvD,qGAA0F;AAE1F;;GAEG;AACH,MAAa,eAAe;IAG3B,YAAmB,EAAY;QAC9B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,CAAC;IAED;;;;;;;;;;OAUG;IACU,GAAG,CACf,UAAkE;IAClE,yCAAyC;IACzC,MAAgC,OAAO,CAAC,GAAG,EAC3C,YAA2B,IAAI,EAC/B,KAAc;;YAEd,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC;gBAChC,UAAU;gBACV,GAAG;gBACH,SAAS;gBACT,KAAK;aACL,CAAC,CAAC;QACJ,CAAC;KAAA;IAEY,cAAc,CAAC,OAM3B;;YACA,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,UAAU,CAAC;YAC3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gBAAgB,EAAE,CAAC,CAAC;YAE1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE;gBACnD,MAAM,yBAAyB,GAAG,IAAI,6DAAyB,CAC9D,IAAI,CAAC,EAAE,CACP,CAAC;gBAEF,MAAM,yBAAyB,CAAC,EAAE,EAAE,CAAC;aACrC;QACF,CAAC;KAAA;CACD;AA9ND,0CA8NC"}
|
package/migration/migration.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { QueryRepository } from '../dml/query-repository';
|
|
2
|
-
import { DataDefinitionRepository } from '../ddl/ddl-repository';
|
|
3
|
-
import { Database } from '../database';
|
|
4
|
-
export declare class Migration<TOptions = Record<string, any>> {
|
|
5
|
-
protected db: Database;
|
|
6
|
-
protected ddl: DataDefinitionRepository;
|
|
7
|
-
protected query: QueryRepository;
|
|
8
|
-
protected options?: TOptions;
|
|
9
|
-
constructor(db: Database, options?: TOptions);
|
|
10
|
-
up(): Promise<void>;
|
|
11
|
-
down(): Promise<void>;
|
|
12
|
-
}
|
|
1
|
+
import { QueryRepository } from '../dml/query-repository';
|
|
2
|
+
import { DataDefinitionRepository } from '../ddl/ddl-repository';
|
|
3
|
+
import { Database } from '../database';
|
|
4
|
+
export declare class Migration<TOptions = Record<string, any>> {
|
|
5
|
+
protected db: Database;
|
|
6
|
+
protected ddl: DataDefinitionRepository;
|
|
7
|
+
protected query: QueryRepository;
|
|
8
|
+
protected options?: TOptions;
|
|
9
|
+
constructor(db: Database, options?: TOptions);
|
|
10
|
+
up(): Promise<void>;
|
|
11
|
+
down(): Promise<void>;
|
|
12
|
+
}
|
package/migration/migration.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Migration = void 0;
|
|
13
|
-
class Migration {
|
|
14
|
-
constructor(db, options) {
|
|
15
|
-
this.db = db;
|
|
16
|
-
this.ddl = db.ddl;
|
|
17
|
-
this.query = db.query;
|
|
18
|
-
this.options = options;
|
|
19
|
-
}
|
|
20
|
-
up() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
22
|
-
}
|
|
23
|
-
down() {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.Migration = Migration;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Migration = void 0;
|
|
13
|
+
class Migration {
|
|
14
|
+
constructor(db, options) {
|
|
15
|
+
this.db = db;
|
|
16
|
+
this.ddl = db.ddl;
|
|
17
|
+
this.query = db.query;
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
up() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
22
|
+
}
|
|
23
|
+
down() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.Migration = Migration;
|
|
28
28
|
//# sourceMappingURL=migration.js.map
|
package/migration/{create-migration-table.d.ts → migrations/001-create-migration-table.d.ts}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Migration } from '
|
|
2
|
-
/**
|
|
3
|
-
* Create a migration table to track current-state
|
|
4
|
-
*/
|
|
5
|
-
export declare class CreateMigrationTable extends Migration {
|
|
6
|
-
up(): Promise<void>;
|
|
7
|
-
down(): Promise<void>;
|
|
8
|
-
}
|
|
1
|
+
import { Migration } from './../migration';
|
|
2
|
+
/**
|
|
3
|
+
* Create a migration table to track current-state
|
|
4
|
+
*/
|
|
5
|
+
export declare class CreateMigrationTable extends Migration {
|
|
6
|
+
up(): Promise<void>;
|
|
7
|
+
down(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CreateMigrationTable = void 0;
|
|
13
|
-
const column_1 = require("
|
|
14
|
-
const functions_1 = require("
|
|
15
|
-
const migration_1 = require("
|
|
16
|
-
/**
|
|
17
|
-
* Create a migration table to track current-state
|
|
18
|
-
*/
|
|
19
|
-
class CreateMigrationTable extends migration_1.Migration {
|
|
20
|
-
up() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
yield this.ddl.createTable({
|
|
23
|
-
name: 'riao_migration',
|
|
24
|
-
ifNotExists: true,
|
|
25
|
-
columns: [
|
|
26
|
-
{
|
|
27
|
-
name: 'id',
|
|
28
|
-
type: column_1.ColumnType.INT,
|
|
29
|
-
autoIncrement: true,
|
|
30
|
-
primaryKey: true,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: 'name',
|
|
34
|
-
type: column_1.ColumnType.VARCHAR,
|
|
35
|
-
length: 255,
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'timestamp',
|
|
39
|
-
type: column_1.ColumnType.TIMESTAMP,
|
|
40
|
-
default: functions_1.DatabaseFunctions.currentTimestamp(),
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
down() {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
yield this.ddl.dropTable({
|
|
49
|
-
tables: 'riao_migration',
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.CreateMigrationTable = CreateMigrationTable;
|
|
55
|
-
//# sourceMappingURL=create-migration-table.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CreateMigrationTable = void 0;
|
|
13
|
+
const column_1 = require("../../column");
|
|
14
|
+
const functions_1 = require("../../functions");
|
|
15
|
+
const migration_1 = require("./../migration");
|
|
16
|
+
/**
|
|
17
|
+
* Create a migration table to track current-state
|
|
18
|
+
*/
|
|
19
|
+
class CreateMigrationTable extends migration_1.Migration {
|
|
20
|
+
up() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
yield this.ddl.createTable({
|
|
23
|
+
name: 'riao_migration',
|
|
24
|
+
ifNotExists: true,
|
|
25
|
+
columns: [
|
|
26
|
+
{
|
|
27
|
+
name: 'id',
|
|
28
|
+
type: column_1.ColumnType.INT,
|
|
29
|
+
autoIncrement: true,
|
|
30
|
+
primaryKey: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'name',
|
|
34
|
+
type: column_1.ColumnType.VARCHAR,
|
|
35
|
+
length: 255,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'timestamp',
|
|
39
|
+
type: column_1.ColumnType.TIMESTAMP,
|
|
40
|
+
default: functions_1.DatabaseFunctions.currentTimestamp(),
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
down() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
yield this.ddl.dropTable({
|
|
49
|
+
tables: 'riao_migration',
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.CreateMigrationTable = CreateMigrationTable;
|
|
55
|
+
//# sourceMappingURL=001-create-migration-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"001-create-migration-table.js","sourceRoot":"","sources":["../../../../src/migration/migrations/001-create-migration-table.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAA0C;AAC1C,+CAAoD;AACpD,8CAA2C;AAE3C;;GAEG;AACH,MAAa,oBAAqB,SAAQ,qBAAS;IAC5B,EAAE;;YACvB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;gBAC1B,IAAI,EAAE,gBAAgB;gBACtB,WAAW,EAAE,IAAI;gBACjB,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,IAAI;wBACV,IAAI,EAAE,mBAAU,CAAC,GAAG;wBACpB,aAAa,EAAE,IAAI;wBACnB,UAAU,EAAE,IAAI;qBAChB;oBACD;wBACC,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,mBAAU,CAAC,OAAO;wBACxB,MAAM,EAAE,GAAG;qBACX;oBACD;wBACC,IAAI,EAAE,WAAW;wBACjB,IAAI,EAAE,mBAAU,CAAC,SAAS;wBAC1B,OAAO,EAAE,6BAAiB,CAAC,gBAAgB,EAAE;qBAC7C;iBACD;aACD,CAAC,CAAC;QACJ,CAAC;KAAA;IAEqB,IAAI;;YACzB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;gBACxB,MAAM,EAAE,gBAAgB;aACxB,CAAC,CAAC;QACJ,CAAC;KAAA;CACD;AA/BD,oDA+BC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Migration } from './../migration';
|
|
2
|
+
/**
|
|
3
|
+
* Add a migration package column to the migration table so that
|
|
4
|
+
* migrations can be scoped by package
|
|
5
|
+
*/
|
|
6
|
+
export declare class AddMigrationPackageColumn extends Migration {
|
|
7
|
+
up(): Promise<void>;
|
|
8
|
+
down(): Promise<void>;
|
|
9
|
+
}
|