Skip to content

Commit 7dd871f

Browse files
author
HunteRoi
committed
fix: migrations runned at container mount
1 parent 0420af3 commit 7dd871f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/services/PostgresDatabaseService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@ export default class PostgresDatabaseService implements IDatabaseService {
150150
//#region private
151151
async #runMigrations(): Promise<void> {
152152
await this.#runMigration('User soft delete', async () => {
153-
await this.#database.query('ALTER TABLE Users ADD isDeleted timestamp;');
153+
await this.#database.query('ALTER TABLE Users ADD COLUMN IF NOT EXISTS isDeleted timestamp;');
154154
});
155155
}
156156

157157
async #runMigration(name: string, callback: () => Promise<void>) {
158158
const result = await this.#database.query('SELECT * FROM Migrations WHERE name = $1', [name]);
159-
const migration = [...result].pop();
160-
if (!migration) {
159+
160+
this.#logger.verbose(`Running migration "${name}" with pre-query returning ${JSON.stringify(result)}`);
161+
if (result && result.rows.length === 0) {
161162
await this.#database.query('INSERT INTO Migrations (name) VALUES($1);', [name]);
162163
await callback();
163164
}

0 commit comments

Comments
 (0)