forked from TanStack/db
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.ts
More file actions
29 lines (24 loc) · 761 Bytes
/
migrate.ts
File metadata and controls
29 lines (24 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { drizzle } from "drizzle-orm/node-postgres"
import { migrate } from "drizzle-orm/node-postgres/migrator"
import pkg from "pg"
import * as dotenv from "dotenv"
dotenv.config()
const { Pool } = pkg
const pool = new Pool({
host: process.env.DB_HOST || `localhost`,
port: parseInt(process.env.DB_PORT || `54322`),
user: process.env.DB_USER || `postgres`,
password: process.env.DB_PASSWORD || `postgres`,
database: process.env.DB_NAME || `todo_app`,
})
const db = drizzle(pool)
async function main() {
console.log(`Running migrations...`)
await migrate(db, { migrationsFolder: `./drizzle` })
console.log(`Migrations completed!`)
await pool.end()
}
main().catch((err) => {
console.error(`Migration failed!`, err)
process.exit(1)
})