-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(backend): migrate to psql (#10)
* sqlite to pg * tried generating schema * fix schema generation * initialize db in docker * added seed file * fixed seed file --------- Co-authored-by: Dropheart <jay@abussaud.dev>
- Loading branch information
1 parent
ea35eb3
commit 4897c2d
Showing
19 changed files
with
296 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
services: | ||
postgres: | ||
image: postgres:16 | ||
container_name: mad3_postgres | ||
environment: | ||
POSTGRES_USER: admin | ||
POSTGRES_PASSWORD: rootpasswd | ||
POSTGRES_DB: postgres | ||
ports: | ||
- '5432:5432' | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
- ./drizzle:/docker-entrypoint-initdb.d | ||
|
||
web: | ||
build: . | ||
container_name: web | ||
depends_on: | ||
- postgres | ||
ports: | ||
- '3000:3000' | ||
env_file: | ||
- .env | ||
environment: | ||
- PGHOST=postgres | ||
|
||
volumes: | ||
postgres_data: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'drizzle-kit'; | ||
|
||
export default defineConfig({ | ||
schema: './hono/**/schema.ts', | ||
dialect: 'postgresql', | ||
verbose: true | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
DO $$ BEGIN | ||
CREATE TYPE "public"."app_state" AS ENUM('parents_open', 'parents_close', 'freshers_open', 'closed'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
CREATE TYPE "public"."gender" AS ENUM('male', 'female', 'other', 'n/a'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
CREATE TYPE "public"."student_role" AS ENUM('fresher', 'parent'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "meta" ( | ||
"id" integer PRIMARY KEY DEFAULT 1 CHECK (id = 1) NOT NULL, | ||
"state" "app_state" NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "family" ( | ||
"kid" text PRIMARY KEY NOT NULL, | ||
"id" integer NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "marriage" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"parent1" text NOT NULL, | ||
"parent2" text NOT NULL, | ||
CONSTRAINT "marriage_parent1_unique" UNIQUE("parent1"), | ||
CONSTRAINT "marriage_parent2_unique" UNIQUE("parent2") | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "proposals" ( | ||
"proposer" text NOT NULL, | ||
"proposee" text NOT NULL, | ||
CONSTRAINT "proposals_proposer_proposee_pk" PRIMARY KEY("proposer","proposee") | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "student" ( | ||
"shortcode" text PRIMARY KEY NOT NULL, | ||
"role" "student_role" NOT NULL, | ||
"completed_survey" boolean NOT NULL, | ||
"jmc" boolean, | ||
"name" text, | ||
"gender" "gender", | ||
"interests" json, | ||
"socials" text[], | ||
"about_me" text | ||
); | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "family" ADD CONSTRAINT "family_kid_student_shortcode_fk" FOREIGN KEY ("kid") REFERENCES "public"."student"("shortcode") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "family" ADD CONSTRAINT "family_id_marriage_id_fk" FOREIGN KEY ("id") REFERENCES "public"."marriage"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "marriage" ADD CONSTRAINT "marriage_parent1_student_shortcode_fk" FOREIGN KEY ("parent1") REFERENCES "public"."student"("shortcode") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "marriage" ADD CONSTRAINT "marriage_parent2_student_shortcode_fk" FOREIGN KEY ("parent2") REFERENCES "public"."student"("shortcode") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "proposals" ADD CONSTRAINT "proposals_proposer_student_shortcode_fk" FOREIGN KEY ("proposer") REFERENCES "public"."student"("shortcode") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "proposals" ADD CONSTRAINT "proposals_proposee_student_shortcode_fk" FOREIGN KEY ("proposee") REFERENCES "public"."student"("shortcode") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; |
Oops, something went wrong.