From 55a7103aa0128ac587141485f9414aad446b6342 Mon Sep 17 00:00:00 2001 From: Minh Nguyen <64875104+MinhxNguyen7@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:31:47 -0700 Subject: [PATCH] Fix migrations (#116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ✨ don't ignore migrations * feat: ✨ auto generate migration on commit * chore: 🔧 empty commit test * fix: 🐛 add hook to remove public from generated sql files * chore: 🔧 add comments to pre-commit hooks * feat: ✨ throw sveltekit errors --------- Co-authored-by: Eddy Chen <89349085+ecxyzzy@users.noreply.github.com> --- .gitignore | 3 - .husky/pre-commit | 9 + package.json | 2 +- src/lib/db/migrations/0000_loving_prowler.sql | 175 +++++ src/lib/db/migrations/meta/0000_snapshot.json | 664 ++++++++++++++++++ src/lib/db/migrations/meta/_journal.json | 13 + src/routes/api/create/+server.ts | 11 +- 7 files changed, 868 insertions(+), 9 deletions(-) create mode 100644 src/lib/db/migrations/0000_loving_prowler.sql create mode 100644 src/lib/db/migrations/meta/0000_snapshot.json create mode 100644 src/lib/db/migrations/meta/_journal.json diff --git a/.gitignore b/.gitignore index 04019b97..94f9ba2a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,3 @@ vite.config.ts.timestamp-* # sst .sst cdk.context.json - -# db, temporary until first release -/src/lib/db/migrations/ diff --git a/.husky/pre-commit b/.husky/pre-commit index f5b03ff2..efe28c51 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,3 +2,12 @@ . "$(dirname -- "$0")/_/husky.sh" npx --no -- lint-staged + +# Generate migration files +pnpm generate + +# Remove references to the schema "public" from migration SQL files +sed -i "s/\"public\"\.//g" src/lib/db/migrations/*.sql + +# Add the changed migration files +git add src/lib/db/migrations/ diff --git a/package.json b/package.json index 3861f6fc..52a4d640 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zotmeet", - "version": "0.0.0", + "version": "0.0.1", "private": true, "type": "module", "scripts": { diff --git a/src/lib/db/migrations/0000_loving_prowler.sql b/src/lib/db/migrations/0000_loving_prowler.sql new file mode 100644 index 00000000..4920abb5 --- /dev/null +++ b/src/lib/db/migrations/0000_loving_prowler.sql @@ -0,0 +1,175 @@ +DO $$ BEGIN + CREATE TYPE "attendance" AS ENUM('accepted', 'maybe', 'declined'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "availabilities" ( + "member_id" text NOT NULL, + "meeting_day" uuid NOT NULL, + "block_length" smallint DEFAULT 15 NOT NULL, + "availability_string" text NOT NULL, + CONSTRAINT "availabilities_member_id_meeting_day_pk" PRIMARY KEY("member_id","meeting_day") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "groups" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "name" text NOT NULL, + "description" text, + "created_at" timestamp, + "user_id" text +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "guests" ( + "id" text NOT NULL, + "username" text NOT NULL, + "meeting_id" uuid, + CONSTRAINT "guests_username_meeting_id_pk" PRIMARY KEY("username","meeting_id"), + CONSTRAINT "guests_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "meeting_dates" ( + "id" uuid DEFAULT gen_random_uuid(), + "meeting_id" uuid, + "date" timestamp NOT NULL, + CONSTRAINT "meeting_dates_id_date_pk" PRIMARY KEY("id","date"), + CONSTRAINT "meeting_dates_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "meetings" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "title" text NOT NULL, + "description" text, + "location" text, + "scheduled" boolean, + "from_time" char(5) NOT NULL, + "to_time" char(5) NOT NULL, + "group_id" uuid, + "host_id" text +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "members" ( + "id" text PRIMARY KEY NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "members_in_meeting" ( + "member_id" text NOT NULL, + "meeting_id" uuid NOT NULL, + "availability" "attendance", + CONSTRAINT "members_in_meeting_member_id_meeting_id_pk" PRIMARY KEY("member_id","meeting_id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "oauth_accounts" ( + "user_id" text NOT NULL, + "provider_id" text NOT NULL, + "provider_user_id" text NOT NULL, + CONSTRAINT "oauth_accounts_provider_id_provider_user_id_pk" PRIMARY KEY("provider_id","provider_user_id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "sessions" ( + "id" text PRIMARY KEY NOT NULL, + "expires_at" timestamp with time zone NOT NULL, + "user_id" text NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "users" ( + "id" text PRIMARY KEY NOT NULL, + "displayName" text NOT NULL, + "email" text NOT NULL, + "password" text, + "created_at" timestamp, + "auth_methods" json NOT NULL, + CONSTRAINT "users_email_unique" UNIQUE("email") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "users_in_group" ( + "user_id" text NOT NULL, + "group_id" uuid NOT NULL, + CONSTRAINT "users_in_group_group_id_user_id_pk" PRIMARY KEY("group_id","user_id") +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "availabilities" ADD CONSTRAINT "availabilities_member_id_members_id_fk" FOREIGN KEY ("member_id") REFERENCES "members"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "availabilities" ADD CONSTRAINT "availabilities_meeting_day_meeting_dates_id_fk" FOREIGN KEY ("meeting_day") REFERENCES "meeting_dates"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "groups" ADD CONSTRAINT "groups_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "guests" ADD CONSTRAINT "guests_meeting_id_meetings_id_fk" FOREIGN KEY ("meeting_id") REFERENCES "meetings"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "meeting_dates" ADD CONSTRAINT "meeting_dates_meeting_id_meetings_id_fk" FOREIGN KEY ("meeting_id") REFERENCES "meetings"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "meetings" ADD CONSTRAINT "meetings_group_id_groups_id_fk" FOREIGN KEY ("group_id") REFERENCES "groups"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "meetings" ADD CONSTRAINT "meetings_host_id_members_id_fk" FOREIGN KEY ("host_id") REFERENCES "members"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "members_in_meeting" ADD CONSTRAINT "members_in_meeting_member_id_members_id_fk" FOREIGN KEY ("member_id") REFERENCES "members"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "members_in_meeting" ADD CONSTRAINT "members_in_meeting_meeting_id_meetings_id_fk" FOREIGN KEY ("meeting_id") REFERENCES "meetings"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "oauth_accounts" ADD CONSTRAINT "oauth_accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "users" ADD CONSTRAINT "users_id_members_id_fk" FOREIGN KEY ("id") REFERENCES "members"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "users_in_group" ADD CONSTRAINT "users_in_group_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "users_in_group" ADD CONSTRAINT "users_in_group_group_id_groups_id_fk" FOREIGN KEY ("group_id") REFERENCES "groups"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE INDEX IF NOT EXISTS "user_idx_sessions" ON "sessions" ("user_id"); \ No newline at end of file diff --git a/src/lib/db/migrations/meta/0000_snapshot.json b/src/lib/db/migrations/meta/0000_snapshot.json new file mode 100644 index 00000000..6a9a3ae2 --- /dev/null +++ b/src/lib/db/migrations/meta/0000_snapshot.json @@ -0,0 +1,664 @@ +{ + "id": "aa6b74d5-d44d-4e2f-8727-1a08faa312e6", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "6", + "dialect": "postgresql", + "tables": { + "public.availabilities": { + "name": "availabilities", + "schema": "", + "columns": { + "member_id": { + "name": "member_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "meeting_day": { + "name": "meeting_day", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "block_length": { + "name": "block_length", + "type": "smallint", + "primaryKey": false, + "notNull": true, + "default": 15 + }, + "availability_string": { + "name": "availability_string", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "availabilities_member_id_members_id_fk": { + "name": "availabilities_member_id_members_id_fk", + "tableFrom": "availabilities", + "tableTo": "members", + "columnsFrom": [ + "member_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "availabilities_meeting_day_meeting_dates_id_fk": { + "name": "availabilities_meeting_day_meeting_dates_id_fk", + "tableFrom": "availabilities", + "tableTo": "meeting_dates", + "columnsFrom": [ + "meeting_day" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "availabilities_member_id_meeting_day_pk": { + "name": "availabilities_member_id_meeting_day_pk", + "columns": [ + "member_id", + "meeting_day" + ] + } + }, + "uniqueConstraints": {} + }, + "public.groups": { + "name": "groups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "groups_user_id_users_id_fk": { + "name": "groups_user_id_users_id_fk", + "tableFrom": "groups", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.guests": { + "name": "guests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "meeting_id": { + "name": "meeting_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "guests_meeting_id_meetings_id_fk": { + "name": "guests_meeting_id_meetings_id_fk", + "tableFrom": "guests", + "tableTo": "meetings", + "columnsFrom": [ + "meeting_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "guests_username_meeting_id_pk": { + "name": "guests_username_meeting_id_pk", + "columns": [ + "username", + "meeting_id" + ] + } + }, + "uniqueConstraints": { + "guests_id_unique": { + "name": "guests_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.meeting_dates": { + "name": "meeting_dates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": false, + "notNull": false, + "default": "gen_random_uuid()" + }, + "meeting_id": { + "name": "meeting_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "date": { + "name": "date", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "meeting_dates_meeting_id_meetings_id_fk": { + "name": "meeting_dates_meeting_id_meetings_id_fk", + "tableFrom": "meeting_dates", + "tableTo": "meetings", + "columnsFrom": [ + "meeting_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "meeting_dates_id_date_pk": { + "name": "meeting_dates_id_date_pk", + "columns": [ + "id", + "date" + ] + } + }, + "uniqueConstraints": { + "meeting_dates_id_unique": { + "name": "meeting_dates_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.meetings": { + "name": "meetings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scheduled": { + "name": "scheduled", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "from_time": { + "name": "from_time", + "type": "char(5)", + "primaryKey": false, + "notNull": true + }, + "to_time": { + "name": "to_time", + "type": "char(5)", + "primaryKey": false, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "host_id": { + "name": "host_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "meetings_group_id_groups_id_fk": { + "name": "meetings_group_id_groups_id_fk", + "tableFrom": "meetings", + "tableTo": "groups", + "columnsFrom": [ + "group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "meetings_host_id_members_id_fk": { + "name": "meetings_host_id_members_id_fk", + "tableFrom": "meetings", + "tableTo": "members", + "columnsFrom": [ + "host_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.members": { + "name": "members", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.members_in_meeting": { + "name": "members_in_meeting", + "schema": "", + "columns": { + "member_id": { + "name": "member_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "meeting_id": { + "name": "meeting_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "availability": { + "name": "availability", + "type": "attendance", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "members_in_meeting_member_id_members_id_fk": { + "name": "members_in_meeting_member_id_members_id_fk", + "tableFrom": "members_in_meeting", + "tableTo": "members", + "columnsFrom": [ + "member_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "members_in_meeting_meeting_id_meetings_id_fk": { + "name": "members_in_meeting_meeting_id_meetings_id_fk", + "tableFrom": "members_in_meeting", + "tableTo": "meetings", + "columnsFrom": [ + "meeting_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "members_in_meeting_member_id_meeting_id_pk": { + "name": "members_in_meeting_member_id_meeting_id_pk", + "columns": [ + "member_id", + "meeting_id" + ] + } + }, + "uniqueConstraints": {} + }, + "public.oauth_accounts": { + "name": "oauth_accounts", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_user_id": { + "name": "provider_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "oauth_accounts_user_id_users_id_fk": { + "name": "oauth_accounts_user_id_users_id_fk", + "tableFrom": "oauth_accounts", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "oauth_accounts_provider_id_provider_user_id_pk": { + "name": "oauth_accounts_provider_id_provider_user_id_pk", + "columns": [ + "provider_id", + "provider_user_id" + ] + } + }, + "uniqueConstraints": {} + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "user_idx_sessions": { + "name": "user_idx_sessions", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "displayName": { + "name": "displayName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "auth_methods": { + "name": "auth_methods", + "type": "json", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "users_id_members_id_fk": { + "name": "users_id_members_id_fk", + "tableFrom": "users", + "tableTo": "members", + "columnsFrom": [ + "id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + } + }, + "public.users_in_group": { + "name": "users_in_group", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "users_in_group_user_id_users_id_fk": { + "name": "users_in_group_user_id_users_id_fk", + "tableFrom": "users_in_group", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "users_in_group_group_id_groups_id_fk": { + "name": "users_in_group_group_id_groups_id_fk", + "tableFrom": "users_in_group", + "tableTo": "groups", + "columnsFrom": [ + "group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "users_in_group_group_id_user_id_pk": { + "name": "users_in_group_group_id_user_id_pk", + "columns": [ + "group_id", + "user_id" + ] + } + }, + "uniqueConstraints": {} + } + }, + "enums": { + "public.attendance": { + "name": "attendance", + "schema": "public", + "values": [ + "accepted", + "maybe", + "declined" + ] + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/lib/db/migrations/meta/_journal.json b/src/lib/db/migrations/meta/_journal.json new file mode 100644 index 00000000..3fc5af63 --- /dev/null +++ b/src/lib/db/migrations/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "6", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "6", + "when": 1717452136623, + "tag": "0000_loving_prowler", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/src/routes/api/create/+server.ts b/src/routes/api/create/+server.ts index 2aceb842..7af4563e 100644 --- a/src/routes/api/create/+server.ts +++ b/src/routes/api/create/+server.ts @@ -11,16 +11,16 @@ export async function POST({ request }) { console.log("Creating meeting:", title, description, fromTime, toTime, meetingDates); if (fromTime >= toTime) { - error(400, "From time must be before to time"); + throw error(400, "From time must be before to time"); } if (meetingDates.length === 0) { - error(400, "At least one date must be provided"); + throw error(400, "At least one date must be provided"); } // Just so we don't get flooded too easily if (meetingDates.length > 100) { - error(400, "Too many dates provided"); + throw error(400, "Too many dates provided"); } const sortedDates = meetingDates @@ -41,7 +41,8 @@ export async function POST({ request }) { const meetingId = await insertMeeting(meeting, sortedDates); return json({ meetingId }); } catch (err) { - console.log("Error creating meeting:", err); - error(500, "Error creating meeting"); + console.error("Error creating meeting:", err.message); + // TODO: This is unsafe + throw error(500, `Error creating meeting: ${err.message}`); } }