Skip to content

Commit

Permalink
Make migration happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mbthiery committed Jul 28, 2023
1 parent 86b3c0f commit c150d0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 11 additions & 1 deletion knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import type { Knex } from "knex"
require("dotenv").config()

const config: Knex.Config = {
// used for preview / if DATABASE_URL not set
const SQLITE_CONFIG: Knex.Config = {
client: "sqlite3",
connection: {
filename: ":memory:",
},
}

const PG_CONFIG = {
client: "postgresql",
connection: process.env.DATABASE_URL,
migrations: {
extension: "ts",
},
}

const config: Knex.Config = process.env.DATABASE_URL ? PG_CONFIG : SQLITE_CONFIG

export default config
12 changes: 1 addition & 11 deletions src/knex/db.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import type { Knex } from "knex"
import knex from "knex"
import config from "../../knexfile"

// used for preview / if DATABASE_URL not set
const DEFAULT_CONFIG: Knex.Config = {
client: "sqlite3",
connection: {
filename: ":memory:",
},
}

const newDb = () => {
const cfg = process.env.DATABASE_URL ? config : DEFAULT_CONFIG
return knex(cfg)
return knex(config)
}

export const db = newDb()

0 comments on commit c150d0b

Please sign in to comment.