Skip to content

Commit 4915b2d

Browse files
authored
Merge pull request #204 from zainfathoni/chore/remove-mysql-schema
chore: remove legacy MySQL schema and simplify Prisma setup
2 parents d77a96d + 0f55bb6 commit 4915b2d

6 files changed

Lines changed: 47 additions & 149 deletions

File tree

CLAUDE.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,21 @@ npm run type-check # TypeScript type checking
5252

5353
### Database Operations
5454

55-
The project uses **two Prisma schemas**:
56-
57-
- `prisma/schema.prisma` - MySQL schema (original)
58-
- `prisma/schema.sqlite.prisma` - SQLite schema (current)
59-
60-
**Always specify `--schema=./prisma/schema.sqlite.prisma`** for local
61-
development.
55+
The project uses SQLite with Prisma. The schema is at `prisma/schema.prisma`.
6256

6357
```bash
6458
# Development database (dev.db)
65-
npm run dev # Auto-generates Prisma client for dev.db
59+
npm run dev # Auto-generates Prisma client for dev.db
6660

6761
# Production database (prod.db) - from MySQL dumps
68-
npm run prod # Auto-generates Prisma client for prod.db
62+
npm run prod # Auto-generates Prisma client for prod.db
6963

7064
# Database management
71-
npx prisma studio --schema=./prisma/schema.sqlite.prisma # Open Prisma Studio
72-
npx prisma db push --schema=./prisma/schema.sqlite.prisma # Push schema changes
73-
npx prisma migrate dev --name <name> --schema=./prisma/schema.sqlite.prisma # Create migration
74-
npx prisma migrate reset --force --schema=./prisma/schema.sqlite.prisma # Reset DB and run seed
75-
npx prisma generate --schema=./prisma/schema.sqlite.prisma # Generate Prisma Client
65+
npx prisma studio # Open Prisma Studio
66+
npx prisma db push # Push schema changes
67+
npx prisma migrate dev --name <name> # Create migration
68+
npx prisma migrate reset --force # Reset DB and run seed
69+
npx prisma generate # Generate Prisma Client
7670
```
7771

7872
**Three SQLite databases**:
@@ -88,6 +82,23 @@ npm run setup # Install deps, reset DB, run E2E tests
8882
npm run presetup # Install Playwright browser dependencies
8983
```
9084

85+
### Database Inspection
86+
87+
```bash
88+
# Inspect dev.db with Prisma Studio
89+
npx prisma studio
90+
91+
# Inspect prod.db with Prisma Studio
92+
DATABASE_URL="file:./prod.db" npx prisma studio
93+
94+
# Direct SQLite queries
95+
sqlite3 prisma/dev.db
96+
sqlite3 prisma/prod.db
97+
98+
# Browse prod data via UI (starts dev server with prod.db)
99+
npm run prod
100+
```
101+
91102
## Architecture
92103

93104
### Tech Stack
@@ -147,8 +158,7 @@ app/
147158
└── root.tsx # Root layout
148159
149160
prisma/
150-
├── schema.prisma # MySQL schema (original)
151-
├── schema.sqlite.prisma # SQLite schema (current)
161+
├── schema.prisma # Prisma schema (SQLite)
152162
├── migrations/ # Migration files
153163
├── seed.ts # Seed data script
154164
├── dumps/ # Database dumps (gitignored)
@@ -268,8 +278,7 @@ Pre-commit hooks run:
268278

269279
## Important Notes
270280

271-
- **Database schema**: Always use `schema.sqlite.prisma` with `--schema` flag
272-
for local work
281+
- **Database schema**: Schema is at `prisma/schema.prisma`
273282
- **Environment**: Copy `.env.example` to `.env` before starting
274283
- **Node version**: Requires Node.js >= 14
275284
- **Git hooks**: Husky manages pre-commit hooks for linting and testing

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ COPY package.json package-lock.json ./
1717
RUN npm ci
1818

1919
# Copy Prisma schema and generate client
20-
COPY prisma/schema.sqlite.prisma ./prisma/
21-
RUN npx prisma generate --schema=./prisma/schema.sqlite.prisma
20+
COPY prisma/schema.prisma ./prisma/
21+
RUN npx prisma generate
2222

2323
# Copy application source
2424
COPY . .
@@ -51,8 +51,8 @@ COPY package.json ./
5151
COPY --from=build /app/node_modules ./node_modules
5252

5353
# Copy Prisma schema and regenerate client for Alpine's OpenSSL version
54-
COPY --from=build /app/prisma/schema.sqlite.prisma ./prisma/
55-
RUN npx prisma generate --schema=./prisma/schema.sqlite.prisma
54+
COPY --from=build /app/prisma/schema.prisma ./prisma/
55+
RUN npx prisma generate
5656

5757
# Copy built application
5858
COPY --from=build /app/build ./build

docs/database-migration.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ prisma/
4141
│ │ └── kelas.Transaction.00001.sql
4242
│ └── prod/ # Converted SQLite dumps (generated, not committed)
4343
│ └── [same files as main, converted to SQLite]
44-
├── schema.prisma # Prisma schema for MySQL (original)
45-
└── schema.sqlite.prisma # Prisma schema for SQLite
44+
└── schema.prisma # Prisma schema for SQLite
4645
```
4746

4847
## Migration Process
@@ -54,11 +53,10 @@ converted to SQLite-compatible format using the `convert-dumps.js` script.
5453

5554
### Step 2: Create Database Schema
5655

57-
The SQLite database is created using Prisma with the `schema.sqlite.prisma`
58-
schema file:
56+
The SQLite database is created using Prisma:
5957

6058
```bash
61-
DATABASE_URL="file:./prod.db" npx prisma db push --schema=prisma/schema.sqlite.prisma --skip-generate
59+
DATABASE_URL="file:./prod.db" npx prisma db push --skip-generate
6260
```
6361

6462
### Step 3: Import Data
@@ -164,7 +162,7 @@ This script:
164162
### 4. Create the database schema
165163

166164
```bash
167-
DATABASE_URL="file:./prod.db" npx prisma db push --schema=prisma/schema.sqlite.prisma --skip-generate
165+
DATABASE_URL="file:./prod.db" npx prisma db push --skip-generate
168166
```
169167

170168
### 5. Import the data
@@ -265,8 +263,8 @@ If you encounter foreign key constraint errors during data import:
265263

266264
### Missing Tables
267265

268-
If tables are not created, verify the `schema.sqlite.prisma` file exists and the
269-
Prisma command was executed correctly.
266+
If tables are not created, verify `prisma/schema.prisma` exists and the Prisma
267+
command was executed correctly.
270268

271269
## Environment Variables
272270

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
"seed": "node --require esbuild-register prisma/seed.ts"
88
},
99
"scripts": {
10-
"build": "prisma generate --schema=./prisma/schema.sqlite.prisma && cross-env NODE_ENV=production npm run build:css && remix build",
10+
"build": "prisma generate && cross-env NODE_ENV=production npm run build:css && remix build",
1111
"build:css": "tailwindcss --minify -o ./app/tailwind.css",
1212
"build:remix": "cross-env NODE_ENV=production remix build --sourcemap",
13-
"dev": "cross-env DATABASE_URL=file:./dev.db NODE_ENV=development prisma generate --schema=./prisma/schema.sqlite.prisma && concurrently -k \"npm run dev:css\" \"remix dev\"",
13+
"dev": "cross-env DATABASE_URL=file:./dev.db NODE_ENV=development prisma generate && concurrently -k \"npm run dev:css\" \"remix dev\"",
1414
"dev:css": "tailwindcss -o ./app/tailwind.css --watch",
15-
"prod": "cross-env DATABASE_URL=file:./prod.db NODE_ENV=development prisma generate --schema=./prisma/schema.sqlite.prisma && concurrently -k \"npm run prod:css\" \"remix dev\"",
15+
"prod": "cross-env DATABASE_URL=file:./prod.db NODE_ENV=development prisma generate && concurrently -k \"npm run prod:css\" \"remix dev\"",
1616
"prod:css": "tailwindcss -o ./app/tailwind.css --watch",
1717
"format": "prettier --write \"./**/*.{ts,tsx,js,jsx,yml,yaml,md}\"",
1818
"lint": "eslint \"**/*.{js,jsx,ts,tsx,yml,yaml}\"",
1919
"lint:fix": "eslint --fix \"**/*.{js,jsx,ts,tsx,yml,yaml}\"",
2020
"prepare": "husky install",
2121
"start": "remix-serve build",
22-
"prestart:e2e": "DATABASE_URL=file:./test.db prisma migrate reset --force --schema=./prisma/schema.sqlite.prisma && npm run build:css",
22+
"prestart:e2e": "DATABASE_URL=file:./test.db prisma migrate reset --force && npm run build:css",
2323
"start:e2e": "cross-env RUNNING_E2E=true DATABASE_URL=file:./test.db remix dev",
2424
"test": "vitest run",
2525
"test:coverage": "vitest run --coverage",
@@ -30,7 +30,7 @@
3030
"test:e2e:docker": "playwright test --config=playwright.docker.config.ts",
3131
"test:e2e:production": "cross-env BASE_URL=https://kelas.rumahberbagi.com playwright test --config=playwright.docker.config.ts",
3232
"type-check": "tsc --noEmit",
33-
"setup": "npm install && prisma migrate reset --force --schema=./prisma/schema.sqlite.prisma && npm run test:e2e:run",
33+
"setup": "npm install && prisma migrate reset --force && npm run test:e2e:run",
3434
"presetup": "npx playwright install-deps"
3535
},
3636
"dependencies": {

prisma/schema.prisma

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
generator client {
2-
provider = "prisma-client-js"
3-
previewFeatures = ["referentialIntegrity"]
2+
provider = "prisma-client-js"
43
}
54

65
datasource db {
7-
provider = "mysql"
8-
url = env("DATABASE_URL")
9-
referentialIntegrity = "prisma"
6+
provider = "sqlite"
7+
url = env("DATABASE_URL")
108
}
119

1210
model User {
@@ -68,7 +66,7 @@ model Transaction {
6866
amount Int
6967
datetime DateTime?
7068
status String
71-
notes String? @db.Text
69+
notes String?
7270
user User @relation("UserTransactions", fields: [userId], references: [id], onDelete: Cascade)
7371
author User @relation("UserSales", fields: [authorId], references: [id], onDelete: Cascade)
7472
course Course @relation(fields: [courseId], references: [id], onDelete: Cascade)
@@ -91,7 +89,7 @@ model Lesson {
9189
updatedAt DateTime @updatedAt
9290
chapterId String
9391
name String
94-
description String? @db.Text
92+
description String?
9593
videoId String
9694
order Int
9795
chapter Chapter @relation(fields: [chapterId], references: [id], onDelete: Cascade)

prisma/schema.sqlite.prisma

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)