Skip to content

Commit

Permalink
add db migratation script
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Oct 17, 2023
1 parent b3fe85a commit c60e617
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
.wrangler
.dev.vars

# temp
scripts/

# Logs

logs
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"prettier:check": "prettier --check .",
"typecheck": "tsc --noEmit",
"drizzle:generate": "drizzle-kit generate:sqlite",
"drizzle:migrate": "ts-node ./src/scripts/migrate/migrate",
"drizzle:push": "drizzle-kit push:sqlite"
},
"devDependencies": {
Expand Down
23 changes: 23 additions & 0 deletions src/scripts/migrate/migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { drizzle as drizzleORM } from "drizzle-orm/libsql"
import { migrate } from "drizzle-orm/libsql/migrator"
import { createClient } from "@libsql/client/web"
import "dotenv/config"

const { TURSO_DATABASE_AUTH_TOKEN, TURSO_DATABASE_URL } = process.env

const client = createClient({
url: TURSO_DATABASE_URL as string,
authToken: TURSO_DATABASE_AUTH_TOKEN as string,
})

const db = drizzleORM(client)

migrate(db, { migrationsFolder: "./src/v2/db/migrations" })
.then(() => {
console.log("migrations complete")
process.exit(0)
})
.catch((err) => {
console.error(`migrations failed: ${err}`)
process.exit(1)
})
8 changes: 4 additions & 4 deletions src/v2/lib/auth/lucia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export function auth(env: Bindings) {
session: unstorage(storage),
},
middleware: hono(),
sessionExpiresIn: {
idlePeriod: 0,
activePeriod: 30 * 24 * 60 * 60 * 1000, // 30 days
},
// sessionExpiresIn: {
// idlePeriod: 0,
// activePeriod: 30 * 24 * 60 * 60 * 1000, // 30 days
// },
env: env.ENVIRONMENT === "DEV" ? "DEV" : "PROD",
experimental: {
debugMode: env.ENVIRONMENT === "DEV" ? true : false,
Expand Down

0 comments on commit c60e617

Please sign in to comment.