Adding the lab project
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { readdir, readFile } from 'node:fs/promises'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { Pool } from 'pg'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const migrationsDir = resolve(__dirname, '../src/migrations')
|
||||
const connectionString =
|
||||
process.env.DATABASE_URL ?? 'postgres://ca_studio:ca_studio@localhost:54329/ca_studio_test'
|
||||
|
||||
const pool = new Pool({ connectionString })
|
||||
|
||||
try {
|
||||
const migrationFiles = (await readdir(migrationsDir))
|
||||
.filter((file) => file.endsWith('.sql'))
|
||||
.sort()
|
||||
|
||||
for (const file of migrationFiles) {
|
||||
const migrationPath = resolve(migrationsDir, file)
|
||||
const sql = await readFile(migrationPath, 'utf8')
|
||||
await pool.query(sql)
|
||||
console.log(`Applied migration ${migrationPath}`)
|
||||
}
|
||||
} finally {
|
||||
await pool.end()
|
||||
}
|
||||
Reference in New Issue
Block a user