Skip to content

Commit 70af5ab

Browse files
committed
make development mode work without docker. docker doesnt work in dev
1 parent 11f358d commit 70af5ab

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ NPM Scripts appended with `:prod` are production scripts and those without anyth
1010

1111
### TODOS
1212

13-
- [x] Use just 1 `run.sh` file with a bunch of if-else scripts
14-
- [ ] Get `development/Dockerfile` to support HMR
13+
- [ ] Get `development/Dockerfile` to support HMR (Currently, Dockerfile in development does not work)
1514

1615
### Development Side
1716

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@ngneat/falso": "^7.2.0",
2424
"@t3-oss/env-nextjs": "^0.9.2",
2525
"better-sqlite3": "^9.4.3",
26-
"drizzle-orm": "^0.30.1",
26+
"drizzle-orm": "^0.30.2",
2727
"jiti": "^1.21.0",
2828
"next": "14.1.3",
2929
"react": "^18.2.0",
@@ -34,11 +34,11 @@
3434
"devDependencies": {
3535
"@types/better-sqlite3": "^7.6.9",
3636
"@types/node": "^20.11.27",
37-
"@types/react": "^18.2.65",
37+
"@types/react": "^18.2.66",
3838
"@types/react-dom": "^18.2.22",
3939
"dotenv": "^16.4.5",
4040
"drizzle-kit": "^0.20.14",
41-
"knip": "^5.0.4",
41+
"knip": "^5.1.0",
4242
"rimraf": "^5.0.5",
4343
"tsx": "^4.7.1",
4444
"typescript": "^5.4.2"

pnpm-lock.yaml

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/drizzle-migrate.mjs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
import sqlite from 'better-sqlite3'
22
import { drizzle } from 'drizzle-orm/better-sqlite3'
33
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
4+
import { fileURLToPath } from 'node:url'
45
import path from 'node:path'
56

6-
const __dirname = import.meta.dirname
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
79

810
// DO NOT IMPORT THE SAME CODE FROM `db` otherwise it fails on production
9-
const url = `/data/${process.env.SQLITE_DATABASE_NAME}`
11+
const url =
12+
process.env.MODE === 'development'
13+
? path.join(__dirname, '../', './data', process.env.SQLITE_DATABASE_NAME)
14+
: `/data/${process.env.SQLITE_DATABASE_NAME}`
1015
console.log({ url })
1116
const client = sqlite(url, { verbose: console.log })
1217
// use sqlite pragma. recommended from https://cj.rs/blog/sqlite-pragma-cheatsheet-for-performance-and-consistency/
1318
client.pragma('journal_mode=WAL') // see https://github.com/WiseLibs/better-sqlite3/blob/master/docs/performance.md
1419
client.pragma('synchronous=normal')
1520
client.pragma('foreign_keys=on')
1621
const db = drizzle(client)
17-
1822
async function main() {
1923
console.info(`Running migrations...`)
2024
const migrationsFolder =
2125
process.env.MODE === 'development'
22-
? path.join(__dirname, '..', 'src/app/db/migrations')
26+
? path.join(__dirname, '../', './src/app/db/migrations')
2327
: './migrations' // for next.js standalone mode
2428
migrate(db, { migrationsFolder })
2529
console.info('Migrated successfully')

src/app/db/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import sqlite from 'better-sqlite3'
22
import { drizzle } from 'drizzle-orm/better-sqlite3'
3+
import { fileURLToPath } from 'node:url'
4+
import path from 'node:path'
5+
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = path.dirname(__filename)
38

49
import { env } from '@app/lib/env'
510

6-
const url = `/data/${env.SQLITE_DATABASE_NAME}`
11+
const url =
12+
env.MODE === 'development'
13+
? path.join(__dirname, '../../../', './data', env.SQLITE_DATABASE_NAME)
14+
: `/data/${env.SQLITE_DATABASE_NAME}`
715

816
console.log(`ahoy!! using ${url}`)
917

src/app/lib/env.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from 'zod'
44

55
export const env = createEnv({
66
server: {
7+
MODE: z.enum(['development', 'production']),
78
SQLITE_DATABASE_NAME: z.string(),
89
},
910
experimental__runtimeEnv: {},

0 commit comments

Comments
 (0)