-
-
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
36cba17
commit d70ea3d
Showing
6 changed files
with
26 additions
and
12 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
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,3 @@ | ||
import migrateAppDatabase from "~/database/migrate"; | ||
|
||
migrateAppDatabase(); |
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,16 @@ | ||
import path from "node:path"; | ||
import Database from "better-sqlite3"; | ||
import { drizzle } from "drizzle-orm/better-sqlite3"; | ||
import { migrate } from "drizzle-orm/better-sqlite3/migrator"; | ||
|
||
function migrateAppDatabase() { | ||
const cwd = process.env.CURRENT_WORKING_DIRECTORY || process.cwd(); | ||
const migrationsFolder = process.env.DRIZZLE_DIR || path.resolve(cwd, "drizzle"); | ||
const sqlite = new Database(path.resolve(cwd, "buttler.db")); | ||
const db = drizzle(sqlite); | ||
|
||
migrate(db, { migrationsFolder }); | ||
sqlite.close(); | ||
} | ||
|
||
export default migrateAppDatabase; |
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,17 +1,7 @@ | ||
export async function register() { | ||
if (process.env.NEXT_RUNTIME === "nodejs") { | ||
process.title = "buttler"; | ||
const path = await import("node:path"); | ||
const { default: Database } = await import("better-sqlite3"); | ||
const { drizzle } = await import("drizzle-orm/better-sqlite3"); | ||
const { migrate } = await import("drizzle-orm/better-sqlite3/migrator"); | ||
|
||
const cwd = process.env.CURRENT_WORKING_DIRECTORY || process.cwd(); | ||
const migrationsFolder = process.env.DRIZZLE_DIR || path.resolve(cwd, "drizzle"); | ||
const sqlite = new Database(path.resolve(cwd, "buttler.db")); | ||
const db = drizzle(sqlite); | ||
|
||
migrate(db, { migrationsFolder }); | ||
sqlite.close(); | ||
const { default: migrate } = await import("./database/migrate"); | ||
migrate(); | ||
} | ||
} |
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