Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions apps/server/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { defineConfig } from "drizzle-kit";

export default defineConfig({
schema: "./src/db/schema",
out: "./src/db/migrations",
dialect: "turso",
schema: './src/db/schema',
out: './src/db/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL || "",
authToken: process.env.DATABASE_AUTH_TOKEN,
},
url: process.env.DATABASE_URL as string
}
});
24 changes: 13 additions & 11 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@
"compile": "bun build --compile --minify --sourcemap --bytecode ./src/index.ts --outfile server",
"dev": "bun run --hot src/index.ts",
"start": "bun run dist/src/index.js",
"db:local": "turso dev --db-file local.db",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio"
"db:generate": "drizzle-kit generate --name=migration --config=drizzle.config.ts",
"db:studio": "drizzle-kit studio",
"db:push": "drizzle-kit push"
},
"dependencies": {
"dotenv": "^16.4.7",
"dotenv": "^16.5.0",
"zod": "^3.24.2",
"hono": "^4.7.6",
"hono": "^4.7.7",
"@hono/trpc-server": "^0.3.4",
"drizzle-orm": "^0.38.4",
"drizzle-orm": "^0.43.1",
"@libsql/client": "^0.14.0",
"better-auth": "^1.2.6",
"@trpc/server": "^11.0.0",
"@trpc/client": "^11.0.0"
"@trpc/client": "^11.0.0",
"pg": "^8.15.6",
"postgres": "^3.4.5"
},
"devDependencies": {
"tsc-alias": "^1.8.11",
"typescript": "^5.8.2",
"@types/bun": "^1.2.6",
"drizzle-kit": "^0.30.5"
"@types/bun": "latest",
"@types/pg": "^8.11.14",
"drizzle-kit": "^0.31.0",
"tsx": "^4.19.3"
}
}
101 changes: 101 additions & 0 deletions apps/server/src/db/migrations/0000_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
CREATE TYPE "public"."day_of_week" AS ENUM('saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday');--> statement-breakpoint
CREATE TYPE "public"."role" AS ENUM('super_admin', 'chairman', 'admin', 'teacher', 'cr_student', 'student');--> statement-breakpoint
CREATE TYPE "public"."session_status" AS ENUM('scheduled', 'completed', 'canceled', 're_scheduled');--> statement-breakpoint
CREATE TABLE "batch_students" (
"id" serial PRIMARY KEY NOT NULL,
"batch_id" integer,
"section_id" integer,
"student_id" integer,
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "batch" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(255),
"created_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "class_session" (
"id" serial PRIMARY KEY NOT NULL,
"routine_id" integer,
"batch_id" integer,
"section_id" integer,
"course_id" integer,
"teacher_id" integer,
"room_id" integer,
"original_schedule_at" timestamp with time zone,
"actual_scheduled_at" timestamp with time zone,
"session_status" "session_status",
"reschedule_or_cancel_reason" varchar(2047),
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now(),
"updated_by" integer
);
--> statement-breakpoint
CREATE TABLE "course" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(255),
"course_code" varchar(63),
"creadit_hours" real,
"created_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "room" (
"id" serial PRIMARY KEY NOT NULL,
"room_number" varchar(31),
"location" varchar(63),
"created_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "routine" (
"id" serial PRIMARY KEY NOT NULL,
"batch_id" integer,
"section_id" integer,
"course_id" integer,
"teacher_id" integer,
"room_id" integer,
"day_of_week" "day_of_week",
"start_time" time,
"end_time" time,
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now(),
"updated_by" integer
);
--> statement-breakpoint
CREATE TABLE "section" (
"id" serial PRIMARY KEY NOT NULL,
"batch_id" integer,
"name" varchar(255),
"created_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "user" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(255),
"email" varchar(255),
"password_hash" varchar(255),
"phone" varchar(15),
"role" "role",
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now(),
CONSTRAINT "user_email_unique" UNIQUE("email")
);
--> statement-breakpoint
ALTER TABLE "batch_students" ADD CONSTRAINT "batch_students_batch_id_batch_id_fk" FOREIGN KEY ("batch_id") REFERENCES "public"."batch"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "batch_students" ADD CONSTRAINT "batch_students_section_id_section_id_fk" FOREIGN KEY ("section_id") REFERENCES "public"."section"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "batch_students" ADD CONSTRAINT "batch_students_student_id_user_id_fk" FOREIGN KEY ("student_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "class_session" ADD CONSTRAINT "class_session_routine_id_routine_id_fk" FOREIGN KEY ("routine_id") REFERENCES "public"."routine"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "class_session" ADD CONSTRAINT "class_session_batch_id_batch_id_fk" FOREIGN KEY ("batch_id") REFERENCES "public"."batch"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "class_session" ADD CONSTRAINT "class_session_section_id_section_id_fk" FOREIGN KEY ("section_id") REFERENCES "public"."section"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "class_session" ADD CONSTRAINT "class_session_course_id_course_id_fk" FOREIGN KEY ("course_id") REFERENCES "public"."course"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "class_session" ADD CONSTRAINT "class_session_teacher_id_user_id_fk" FOREIGN KEY ("teacher_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "class_session" ADD CONSTRAINT "class_session_room_id_room_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."room"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "class_session" ADD CONSTRAINT "class_session_updated_by_user_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "routine" ADD CONSTRAINT "routine_batch_id_batch_id_fk" FOREIGN KEY ("batch_id") REFERENCES "public"."batch"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "routine" ADD CONSTRAINT "routine_section_id_section_id_fk" FOREIGN KEY ("section_id") REFERENCES "public"."section"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "routine" ADD CONSTRAINT "routine_course_id_course_id_fk" FOREIGN KEY ("course_id") REFERENCES "public"."course"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "routine" ADD CONSTRAINT "routine_teacher_id_user_id_fk" FOREIGN KEY ("teacher_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "routine" ADD CONSTRAINT "routine_room_id_room_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."room"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "routine" ADD CONSTRAINT "routine_updated_by_user_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "section" ADD CONSTRAINT "section_batch_id_batch_id_fk" FOREIGN KEY ("batch_id") REFERENCES "public"."batch"("id") ON DELETE no action ON UPDATE no action;
Loading