-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
826f462
commit 5d2eb17
Showing
2 changed files
with
55 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { resolve } from "node:path"; | ||
import migrationRunner from "node-pg-migrate"; | ||
import database from "infra/database.js"; | ||
|
||
const defaultMigrationsOptions = { | ||
dryRun: true, | ||
dir: resolve("infra", "migrations"), | ||
direction: "up", | ||
verbose: true, | ||
migrationsTable: "pgmigrations", | ||
}; | ||
|
||
async function listPendingMigrations() { | ||
let dbClient; | ||
|
||
try { | ||
dbClient = await database.getNewClient(); | ||
|
||
const pendingMigrations = await migrationRunner({ | ||
...defaultMigrationsOptions, | ||
dbClient, | ||
}); | ||
|
||
return pendingMigrations; | ||
} finally { | ||
await dbClient?.end(); | ||
} | ||
} | ||
|
||
async function runPendingMigrations() { | ||
let dbClient; | ||
|
||
try { | ||
dbClient = await database.getNewClient(); | ||
|
||
const migratedMigrations = await migrationRunner({ | ||
...defaultMigrationsOptions, | ||
dbClient, | ||
dryRun: false, | ||
}); | ||
|
||
return migratedMigrations; | ||
} finally { | ||
await dbClient?.end(); | ||
} | ||
} | ||
|
||
const migrator = { | ||
listPendingMigrations, | ||
runPendingMigrations, | ||
}; | ||
export default migrator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters