Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated Meetings Database Setup #632

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
123 changes: 123 additions & 0 deletions src/database/prisma/migrations/20241209223044_meetings/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
Warnings:

- You are about to drop the column `date` on the `meetings` table. All the data in the column will be lost.
- You are about to drop the column `url` on the `meetings` table. All the data in the column will be lost.
- A unique constraint covering the columns `[notice_id]` on the table `meetings` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[agenda_id]` on the table `meetings` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[minutes_id]` on the table `meetings` will be added. If there are existing duplicate values, this will fail.
- Added the required column `end` to the `meetings` table without a default value. This is not possible if the table is not empty.
- Added the required column `start` to the `meetings` table without a default value. This is not possible if the table is not empty.
- Added the required column `type` to the `meetings` table without a default value. This is not possible if the table is not empty.

*/
-- DropIndex
DROP INDEX "meetings_url_key";

-- AlterTable
ALTER TABLE "meetings" DROP COLUMN "url",
ADD COLUMN "agenda_id" UUID,
ADD COLUMN "created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "description" VARCHAR(255),
ADD COLUMN "end" TIMESTAMPTZ(6) NOT NULL,
ADD COLUMN "minutes_id" UUID,
ADD COLUMN "notice_id" UUID,
ADD COLUMN "start" TIMESTAMPTZ(6) NOT NULL,
ADD COLUMN "type" VARCHAR(255) NOT NULL,
ADD COLUMN "updated_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP;

-- CreateTable
CREATE TABLE "meeting_agenda_items" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"title" VARCHAR(255) NOT NULL,
"description" VARCHAR(255),
"type" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
"start" TIMESTAMPTZ(6) NOT NULL,
"end" TIMESTAMPTZ(6) NOT NULL,
"meeting_id" UUID NOT NULL,

CONSTRAINT "meeting_agenda_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MeetingAgendaAttachment" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"file_url" VARCHAR(255) NOT NULL,
"order" INTEGER NOT NULL DEFAULT 0,
"meetingAgendaItemId" UUID NOT NULL,

CONSTRAINT "MeetingAgendaAttachment_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MeetingAttachment" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"file_url" VARCHAR(255) NOT NULL,
"order" INTEGER NOT NULL DEFAULT 0,

CONSTRAINT "MeetingAttachment_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "speakers" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"meeting_id" UUID NOT NULL,
"member_id" UUID NOT NULL,
"start" TIMESTAMPTZ(6) NOT NULL,
"end" TIMESTAMPTZ(6) NOT NULL,
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "speakers_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "meeting_logs" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"meeting_id" UUID NOT NULL,
"member_id" UUID NOT NULL,
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"comment" TEXT NOT NULL,
"happenedAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "meeting_logs_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "meetings_notice_id_key" ON "meetings"("notice_id");

-- CreateIndex
CREATE UNIQUE INDEX "meetings_agenda_id_key" ON "meetings"("agenda_id");

-- CreateIndex
CREATE UNIQUE INDEX "meetings_minutes_id_key" ON "meetings"("minutes_id");

-- AddForeignKey
ALTER TABLE "meetings" ADD CONSTRAINT "meetings_notice_id_fkey" FOREIGN KEY ("notice_id") REFERENCES "MeetingAttachment"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meetings" ADD CONSTRAINT "meetings_agenda_id_fkey" FOREIGN KEY ("agenda_id") REFERENCES "MeetingAttachment"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meetings" ADD CONSTRAINT "meetings_minutes_id_fkey" FOREIGN KEY ("minutes_id") REFERENCES "MeetingAttachment"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meeting_agenda_items" ADD CONSTRAINT "meeting_agenda_items_meeting_id_foreign" FOREIGN KEY ("meeting_id") REFERENCES "meetings"("id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "MeetingAgendaAttachment" ADD CONSTRAINT "MeetingAgendaAttachment_meetingAgendaItemId_fkey" FOREIGN KEY ("meetingAgendaItemId") REFERENCES "meeting_agenda_items"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "speakers" ADD CONSTRAINT "speakers_meeting_id_foreign" FOREIGN KEY ("meeting_id") REFERENCES "meetings"("id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "speakers" ADD CONSTRAINT "speakers_member_id_foreign" FOREIGN KEY ("member_id") REFERENCES "members"("id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "meeting_logs" ADD CONSTRAINT "meeting_logs_meeting_id_foreign" FOREIGN KEY ("meeting_id") REFERENCES "meetings"("id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "meeting_logs" ADD CONSTRAINT "meeting_logs_member_id_foreign" FOREIGN KEY ("member_id") REFERENCES "members"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
102 changes: 89 additions & 13 deletions src/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -539,19 +539,6 @@ model Markdown {
@@map("markdowns")
}

/// @@allow('create', has(auth().policies, 'fileHandler:documents:create'))
/// @@allow('read', has(auth().policies, 'fileHandler:documents:read'))
/// @@allow('update', has(auth().policies, 'fileHandler:documents:update'))
/// @@allow('delete', has(auth().policies, 'fileHandler:documents:delete'))
model Meeting {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
title String @db.VarChar(255)
date DateTime @db.Date()
url String @unique() @db.VarChar(255)

@@map("meetings")
}

/// @@allow('create', has(auth().policies, 'core:member:create'))
/// @@allow('create', auth().studentId == studentId)
/// @@allow('read', has(auth().policies, 'core:member:read'))
Expand Down Expand Up @@ -600,6 +587,8 @@ model Member {
shopReservations ConsumableReservation[]
bookingRequests BookingRequest[]
recurringEvent RecurringEvent[]
speaker Speaker[]
meetingLog MeetingLog[]

@@map("members")
}
Expand Down Expand Up @@ -1073,4 +1062,91 @@ model ShoppableAccessPolicy {
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)

@@map("shoppable_access_policies")
}

/// @@allow('create', has(auth().policies, 'fileHandler:documents:create'))
/// @@allow('read', has(auth().policies, 'fileHandler:documents:read'))
/// @@allow('update', has(auth().policies, 'fileHandler:documents:update'))
/// @@allow('delete', has(auth().policies, 'fileHandler:documents:delete'))
model Meeting {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
title String @db.VarChar(255)
description String? @db.VarChar(255)
type String @db.VarChar(255)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @default(now()) @map("updated_at") @db.Timestamptz(6) @updatedAt()
start DateTime @db.Timestamptz(6)
end DateTime @db.Timestamptz(6)
items MeetingAgendaItem[]
notice MeetingAttachment? @relation("meeting_notice", fields: [noticeId], references: [id])
noticeId String? @map("notice_id") @db.Uuid() @unique()
agenda MeetingAttachment? @relation("meeting_agenda", fields: [agendaId], references: [id])
agendaId String? @map("agenda_id") @db.Uuid() @unique()
minutes MeetingAttachment? @relation("meeting_minutes", fields: [minutesId], references: [id])
minutesId String? @map("minutes_id") @db.Uuid() @unique()
speakersList Speaker[]
meetingLog MeetingLog[]

@@map("meetings")
}

model MeetingAgendaItem {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
title String @db.VarChar(255)
description String? @db.VarChar(255)
type String @db.VarChar(255)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @default(now()) @map("updated_at") @db.Timestamptz(6) @updatedAt()
start DateTime @db.Timestamptz(6)
end DateTime @db.Timestamptz(6)
meetingId String @map("meeting_id") @db.Uuid()
meeting Meeting @relation(fields: [meetingId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "meeting_agenda_items_meeting_id_foreign")
attachments MeetingAgendaAttachment[]

@@map("meeting_agenda_items")
}

model MeetingAgendaAttachment {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
fileUrl String @map("file_url") @db.VarChar(255)
order Int @default(0)
meetingAgendaItem MeetingAgendaItem @relation(fields: [meetingAgendaItemId], references: [id])
meetingAgendaItemId String @db.Uuid()
}

model MeetingAttachment {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
fileUrl String @map("file_url") @db.VarChar(255)
order Int @default(0)
noticeFor Meeting[] @relation("meeting_notice")
minutesFor Meeting[] @relation("meeting_minutes")
agendaFor Meeting[] @relation("meeting_agenda")
}

model Speaker {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
meetingId String @map("meeting_id") @db.Uuid()
memberId String @map("member_id") @db.Uuid()
meeting Meeting @relation(fields: [meetingId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "speakers_meeting_id_foreign")
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "speakers_member_id_foreign")
start DateTime @db.Timestamptz(6)
end DateTime @db.Timestamptz(6)
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6) @updatedAt()

@@map("speakers")
}

model MeetingLog {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
meetingId String @map("meeting_id") @db.Uuid()
memberId String @map("member_id") @db.Uuid()
meeting Meeting @relation(fields: [meetingId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "meeting_logs_meeting_id_foreign")
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "meeting_logs_member_id_foreign")
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6) @updatedAt()
comment String @db.Text()
happenedAt DateTime @default(now()) @db.Timestamptz(6)

@@map("meeting_logs")
}
103 changes: 90 additions & 13 deletions src/database/schema.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -536,19 +536,6 @@ model Markdown {
@@map("markdowns")
}

model Meeting {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
title String @db.VarChar(255)
date DateTime @db.Date
url String @unique @db.VarChar(255)

@@allow("create", has(auth().policies, "fileHandler:documents:create"))
@@allow("read", has(auth().policies, "fileHandler:documents:read"))
@@allow("update", has(auth().policies, "fileHandler:documents:update"))
@@allow("delete", has(auth().policies, "fileHandler:documents:delete"))
@@map("meetings")
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-commentsmodel Members{
model Member {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
Expand Down Expand Up @@ -599,6 +586,10 @@ model Member {
@@allow('update', has(auth().policies, "core:member:update"))
@@allow('delete', has(auth().policies, "core:member:delete"))
@@map("members")

speaker Speaker[]

meetingLog MeetingLog[]
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-commentsmodel Notifications{
Expand Down Expand Up @@ -1152,4 +1143,90 @@ model ShoppableAccessPolicy {
// only managers can delete (should very rarely be done)
@@allow("delete", auth().memberId == shoppable.authorId || has(auth().policies, "webshop:manage"))
@@map("shoppable_access_policies")
}

abstract model MeetingBase {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
title String @db.VarChar(255)
description String? @db.VarChar(255)
type String @db.VarChar(255)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @default(now()) @map("updated_at") @db.Timestamptz(6) @updatedAt()
start DateTime @db.Timestamptz(6)
end DateTime @db.Timestamptz(6)
}

model Meeting extends MeetingBase {

items MeetingAgendaItem[]
// Remove the "notice" field from the "Meeting" model
notice MeetingAttachment? @relation("meeting_notice", fields: [noticeId], references: [id])
noticeId String? @map("notice_id") @db.Uuid @unique
agenda MeetingAttachment? @relation("meeting_agenda", fields: [agendaId], references: [id])
agendaId String? @map("agenda_id") @db.Uuid @unique
minutes MeetingAttachment? @relation("meeting_minutes", fields: [minutesId], references: [id])
minutesId String? @map("minutes_id") @db.Uuid @unique
date DateTime @db.Date

@@allow("create", has(auth().policies, "fileHandler:documents:create"))
@@allow("read", has(auth().policies, "fileHandler:documents:read"))
@@allow("update", has(auth().policies, "fileHandler:documents:update"))
@@allow("delete", has(auth().policies, "fileHandler:documents:delete"))
@@map("meetings")

speakersList Speaker[]

meetingLog MeetingLog[]
}

// These are the bullet points of a meeting, equal to the ones in the meeting agenda document
model MeetingAgendaItem extends MeetingBase {
meetingId String @map("meeting_id") @db.Uuid
meeting Meeting @relation(fields: [meetingId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "meeting_agenda_items_meeting_id_foreign")
attachments MeetingAgendaAttachment[]
@@map("meeting_agenda_items")
}

// An attachment to either an item or a meeting
abstract model MeetingAttachmentBase {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
fileUrl String @map("file_url") @db.VarChar(255)
order Int @default(0)
}

model MeetingAgendaAttachment extends MeetingAttachmentBase {
meetingAgendaItem MeetingAgendaItem @relation(fields: [meetingAgendaItemId], references: [id])
meetingAgendaItemId String @db.Uuid
}

model MeetingAttachment extends MeetingAttachmentBase {
noticeFor Meeting[] @relation("meeting_notice")
minutesFor Meeting[] @relation("meeting_minutes")
agendaFor Meeting[] @relation("meeting_agenda")
}

model Speaker {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
meetingId String @map("meeting_id") @db.Uuid
memberId String @map("member_id") @db.Uuid
meeting Meeting @relation(fields: [meetingId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "speakers_meeting_id_foreign")
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "speakers_member_id_foreign")
start DateTime @db.Timestamptz(6)
end DateTime @db.Timestamptz(6)
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6) @updatedAt()
@@map("speakers")
}

model MeetingLog {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
meetingId String @map("meeting_id") @db.Uuid
memberId String @map("member_id") @db.Uuid
meeting Meeting @relation(fields: [meetingId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "meeting_logs_meeting_id_foreign")
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "meeting_logs_member_id_foreign")
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6) @updatedAt()
comment String @db.Text
happenedAt DateTime @default(now()) @db.Timestamptz(6)
@@map("meeting_logs")
}
Loading
Loading