whitelabel-db 1.1.93 → 1.1.94
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/libs/database.d.ts +1 -1
- package/dist/libs/database.js +10 -7
- package/dist/libs/migration.js +27 -3
- package/package.json +1 -1
package/dist/libs/database.d.ts
CHANGED
package/dist/libs/database.js
CHANGED
|
@@ -72,14 +72,17 @@ const connect = (connectionDetails) => __awaiter(void 0, void 0, void 0, functio
|
|
|
72
72
|
CollectionItemCustomField_1.CollectionItemCustomField,
|
|
73
73
|
],
|
|
74
74
|
});
|
|
75
|
-
|
|
76
|
-
.authenticate()
|
|
77
|
-
.then(() => {
|
|
75
|
+
try {
|
|
76
|
+
yield connection.authenticate();
|
|
78
77
|
console.log('Database connection has been established successfully.');
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
.
|
|
78
|
+
// Ensure sync completes and creates necessary tables including SequelizeMeta
|
|
79
|
+
yield connection.sync({ alter: false });
|
|
80
|
+
console.log('Database sync completed successfully.');
|
|
81
|
+
return connection;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
82
84
|
console.error('Unable to connect to the database:', err);
|
|
83
|
-
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
84
87
|
});
|
|
85
88
|
exports.connect = connect;
|
package/dist/libs/migration.js
CHANGED
|
@@ -44,14 +44,37 @@ const runMigrations = (sequelize) => __awaiter(void 0, void 0, void 0, function*
|
|
|
44
44
|
console.error(`Migrations directory not found at: ${migrationsPath}`);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
+
// Ensure SequelizeMeta table exists - this handles cases where sync() didn't create it
|
|
48
|
+
try {
|
|
49
|
+
yield sequelize.query(`
|
|
50
|
+
CREATE TABLE IF NOT EXISTS "SequelizeMeta" (
|
|
51
|
+
"name" VARCHAR(255) NOT NULL,
|
|
52
|
+
PRIMARY KEY ("name")
|
|
53
|
+
);
|
|
54
|
+
`);
|
|
55
|
+
console.log('SequelizeMeta table ensured to exist');
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('Error creating SequelizeMeta table:', error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
47
61
|
// Read and sort migration files
|
|
48
62
|
const migrationFiles = fs_1.default
|
|
49
63
|
.readdirSync(migrationsPath)
|
|
50
64
|
.filter((file) => file.match(/^\d{3}-.+\.ts$/) || file.match(/^\d{3}-.+\.js$/)) // Matches .ts and .js files
|
|
51
65
|
.filter((file) => !file.endsWith('.d.ts')) // Exclude .d.ts files
|
|
52
66
|
.sort(); // Sort files by name
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
// Get executed migrations - now this should always work since we ensured the table exists
|
|
68
|
+
let executedMigrations = [];
|
|
69
|
+
try {
|
|
70
|
+
const [results] = yield sequelize.query('SELECT name FROM "SequelizeMeta"');
|
|
71
|
+
executedMigrations = results.map((row) => row.name);
|
|
72
|
+
console.log(`Found ${executedMigrations.length} previously executed migrations`);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error('Unexpected error fetching executed migrations:', error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
55
78
|
for (const file of migrationFiles) {
|
|
56
79
|
if (!executedMigrations.includes(file)) {
|
|
57
80
|
const migration = yield Promise.resolve(`${path_1.default.join(migrationsPath, file)}`).then(s => __importStar(require(s)));
|
|
@@ -59,10 +82,11 @@ const runMigrations = (sequelize) => __awaiter(void 0, void 0, void 0, function*
|
|
|
59
82
|
console.log(`Running migration: ${file}`);
|
|
60
83
|
yield migration.up(sequelize.getQueryInterface());
|
|
61
84
|
yield sequelize.query(`INSERT INTO "SequelizeMeta" (name) VALUES ('${file}')`);
|
|
85
|
+
console.log(`Completed migration: ${file}`);
|
|
62
86
|
}
|
|
63
87
|
}
|
|
64
88
|
else {
|
|
65
|
-
console.log(`Skipping migration: ${file}`);
|
|
89
|
+
console.log(`Skipping migration: ${file} (already executed)`);
|
|
66
90
|
}
|
|
67
91
|
}
|
|
68
92
|
console.log('Migrations completed.');
|