drizzle-orm 0.10.33 → 0.10.36
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/migrator/migrator.js +12 -9
- package/package.json +3 -3
package/migrator/migrator.js
CHANGED
|
@@ -31,11 +31,13 @@ const crypto = __importStar(require("crypto"));
|
|
|
31
31
|
const builders_1 = require("../builders");
|
|
32
32
|
const transaction_1 = __importDefault(require("../builders/transaction/transaction"));
|
|
33
33
|
const tables_1 = require("../tables");
|
|
34
|
+
const order_1 = __importDefault(require("../builders/highLvlBuilders/order"));
|
|
34
35
|
class Migrator {
|
|
35
36
|
constructor(db) {
|
|
36
37
|
this.db = db;
|
|
37
38
|
}
|
|
38
39
|
async migrate(configPath) {
|
|
40
|
+
var _a;
|
|
39
41
|
let migrationFolderTo;
|
|
40
42
|
if (typeof configPath === 'string') {
|
|
41
43
|
const configAsString = fs.readFileSync(path.resolve('.', configPath), 'utf8');
|
|
@@ -59,10 +61,12 @@ class Migrator {
|
|
|
59
61
|
}
|
|
60
62
|
const migrationTable = new tables_1.MigrationsTable(this.db);
|
|
61
63
|
await this.db.session().execute(builders_1.Create.table(migrationTable).build());
|
|
62
|
-
const dbMigrations = await migrationTable.select()
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const dbMigrations = await migrationTable.select()
|
|
65
|
+
.limit(1)
|
|
66
|
+
.orderBy((table) => table.createdAt, order_1.default.DESC)
|
|
67
|
+
.all();
|
|
68
|
+
const lastDbMigration = (_a = dbMigrations[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
69
|
+
console.log('last migration: ', lastDbMigration === null || lastDbMigration === void 0 ? void 0 : lastDbMigration.hash);
|
|
66
70
|
const files = fs.readdirSync(migrationFolderTo);
|
|
67
71
|
const transaction = new transaction_1.default(this.db.session());
|
|
68
72
|
await transaction.begin();
|
|
@@ -79,8 +83,10 @@ class Migrator {
|
|
|
79
83
|
const hour = Number(migrationFolder.slice(8, 10));
|
|
80
84
|
const min = Number(migrationFolder.slice(10, 12));
|
|
81
85
|
const sec = Number(migrationFolder.slice(12, 14));
|
|
82
|
-
const folderAsMillis =
|
|
86
|
+
const folderAsMillis = Date.UTC(year, month, day, hour, min, sec);
|
|
87
|
+
console.log(`check migration ${migrationFolder} {folderAsMillis}`);
|
|
83
88
|
if (!lastDbMigration || lastDbMigration.createdAt < folderAsMillis) {
|
|
89
|
+
console.log(`executing ${migrationFolder}`);
|
|
84
90
|
await this.db.session().execute(query);
|
|
85
91
|
await migrationTable.insert({
|
|
86
92
|
hash: this.generateHash(query),
|
|
@@ -91,10 +97,7 @@ class Migrator {
|
|
|
91
97
|
await transaction.commit();
|
|
92
98
|
}
|
|
93
99
|
catch (e) {
|
|
94
|
-
|
|
95
|
-
// this.db.logger()!.error(e);
|
|
96
|
-
// }
|
|
97
|
-
transaction.rollback();
|
|
100
|
+
await transaction.rollback();
|
|
98
101
|
throw e;
|
|
99
102
|
}
|
|
100
103
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-orm",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.36",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/lambda-direct/drizzle-orm.git",
|