-
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.
🔨 chore (finance): Updated migration script to use
dotenv-cli
- Loading branch information
1 parent
ca7bab8
commit c9371e1
Showing
2 changed files
with
18 additions
and
8 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
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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { config } from "dotenv"; | ||
import { drizzle } from "drizzle-orm/postgres-js"; | ||
import { migrate } from "drizzle-orm/postgres-js/migrator"; | ||
import postgres from "postgres"; | ||
|
||
import { env } from "~/env"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const sql = postgres(env.DATABASE_URL, { max: 1, onnotice: () => {} }); | ||
const db = drizzle(sql); | ||
config(); | ||
|
||
await migrate(db, { migrationsFolder: "./src/server/db/migrations" }); | ||
const migrateDb = async () => { | ||
if (!env.DATABASE_URL) { | ||
throw new Error("DATABASE_URL environment variable is not set"); | ||
} | ||
|
||
await sql.end(); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const sql = postgres(env.DATABASE_URL, { max: 1, onnotice: () => {} }); | ||
const db = drizzle(sql); | ||
|
||
console.log("💦 Database migrated successfully"); | ||
await migrate(db, { migrationsFolder: "./src/server/db/migrations" }); | ||
await sql.end(); | ||
|
||
console.info("💦 Database migrated successfully"); | ||
}; | ||
|
||
void migrateDb(); |