Skip to content

Commit 0c17989

Browse files
HunteRoiTinaël Devresse
authored andcommitted
fix: migrations runned at container mount
1 parent 92d617f commit 0c17989

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/services/PostgresDatabaseService.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export default class PostgresDatabaseService implements IDatabaseService {
206206
async #runMigrations(): Promise<void> {
207207
await this.#runMigration("User soft delete", async () => {
208208
await this.#database.query(
209-
"ALTER TABLE Users ADD IF NOT EXISTS isDeleted timestamp;",
209+
"ALTER TABLE Users ADD COLUMN IF NOT EXISTS isDeleted timestamp;",
210210
);
211211
});
212212
}
@@ -216,12 +216,9 @@ export default class PostgresDatabaseService implements IDatabaseService {
216216
"SELECT * FROM Migrations WHERE name = $1",
217217
[name],
218218
);
219-
const migration = [...result].pop();
220-
if (!migration) {
221-
await this.#database.query(
222-
"INSERT INTO Migrations (name) VALUES($1);",
223-
[name],
224-
);
219+
this.#logger.verbose(`Running migration "${name}" with pre-query returning ${JSON.stringify(result)}`);
220+
if (result && result.rows.length === 0) {
221+
await this.#database.query('INSERT INTO Migrations (name) VALUES($1);', [name]);
225222
await callback();
226223
}
227224
}

0 commit comments

Comments
 (0)