-
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
1cad5ac
commit 0c17b11
Showing
7 changed files
with
39 additions
and
9 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
File renamed without changes.
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,22 @@ | ||
const env = process.env.NODE_ENV; | ||
|
||
export const getConfig = () => { | ||
let migrationDir = ""; | ||
let dataDir = ""; | ||
let databasePath = ""; | ||
let ncHost = ""; | ||
|
||
if (env == "development") { | ||
migrationDir = "migrations"; | ||
dataDir = "data"; | ||
databasePath = "data/sqlite.db"; | ||
ncHost = "127.0.0.1"; | ||
} else if (env == "production") { | ||
migrationDir = "/app/migrations"; | ||
dataDir = "/app/data"; | ||
databasePath = "/app/data/sqlite.db"; | ||
ncHost = "host.docker.internal"; | ||
} | ||
|
||
return { migrationDir, dataDir, databasePath, ncHost }; | ||
}; |
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,12 +1,15 @@ | ||
import { drizzle } from "drizzle-orm/better-sqlite3"; | ||
import { migrate } from "drizzle-orm/better-sqlite3/migrator"; | ||
import Database from "better-sqlite3"; | ||
import { getConfig } from "../config/config"; | ||
|
||
export const migrateDb = () => { | ||
const betterSqlite = new Database("/app/data/sqlite.db"); | ||
const { databasePath, migrationDir } = getConfig(); | ||
|
||
const betterSqlite = new Database(databasePath); | ||
const db = drizzle(betterSqlite); | ||
|
||
migrate(db, { migrationsFolder: "/app/migrations" }); | ||
migrate(db, { migrationsFolder: migrationDir }); | ||
|
||
betterSqlite.close(); | ||
}; |
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