fix(db): remove stale init.sql, make Prisma migrations the schema SSOT

init.sql predated Prisma and had drifted out of sync with schema.prisma
(snake_case columns vs. the app's camelCase models, a manual
trigger_set_timestamp() trigger that Prisma's @updatedAt already
handles at the ORM level). docker-compose still mounted it into the
postgres container, so any fresh dev DB got seeded from the wrong
schema. Drop the file and the mount, and point the setup docs at
`npm run docker:migrate` / `prisma migrate dev` instead.
This commit is contained in:
Mao Nakamoto committed 2026-08-04 04:01:56 +00:00
1 parent 4dbe5220f0
commit 94497195b4
3 files changed
+9 -62

No files matched your search

-50
View File
@@ -1,50 +0,0 @@
-- Users table
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
-- Optional: Function to update the updated_at timestamp automatically
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW."updatedAt" = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Optional: Trigger to automatically update updated_at on user update
CREATE TRIGGER set_timestamp
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE PROCEDURE trigger_set_timestamp();
-- You can add more tables here as the application grows.
-- For example, a table for forms:
CREATE TABLE forms (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title VARCHAR(255) NOT NULL,
description TEXT,
structure JSONB NOT NULL,
status VARCHAR(50) DEFAULT 'draft',
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE TRIGGER set_timestamp_forms
BEFORE UPDATE ON forms
FOR EACH ROW
EXECUTE PROCEDURE trigger_set_timestamp();
-- Submissions table
CREATE TABLE submissions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
form_id UUID NOT NULL REFERENCES forms(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, -- The user who OWNS the form
data JSONB NOT NULL,
submitted_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
-1
View File
@@ -14,7 +14,6 @@ services:
- "5433:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./backend/db/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
networks:
- formular-network
healthcheck:
+9 -11
View File
@@ -58,19 +58,17 @@ cd ..
### 3. Database Setup
#### Option A: Docker (Recommended)
Prisma migrations (`backend/prisma/migrations/`) are the single source of truth for
the schema — there is no standalone SQL script to load.
#### Option A: Docker Compose (Recommended)
```bash
# Start PostgreSQL container
docker run --name formular-postgres \
-e POSTGRES_DB=formbuilder \
-e POSTGRES_USER=formbuilder \
-e POSTGRES_PASSWORD=devpassword \
-p 5432:5432 \
-d postgres:14
# Start PostgreSQL, Redis, backend, frontend
npm run docker:dev
# Initialize database schema
docker exec -i formular-postgres psql -U formbuilder -d formbuilder < backend/db/init.sql
# In a separate terminal, once postgres is healthy: apply Prisma migrations
npm run docker:migrate
```
#### Option B: Local PostgreSQL
@@ -82,7 +80,7 @@ docker exec -i formular-postgres psql -U formbuilder -d formbuilder < backend/db
CREATE USER formbuilder WITH PASSWORD 'devpassword';
GRANT ALL PRIVILEGES ON DATABASE formbuilder TO formbuilder;
```
3. Run schema: `psql -U formbuilder -d formbuilder -f backend/db/init.sql`
3. Apply the schema: `cd backend && npm run migrate` (runs `prisma migrate dev`)
### 4. Environment Configuration