WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d65289f

Browse files
authored
✨ feature: Add unique constraints and timestamps to all models (#196)
* ✨ feature: Add unique constraints and timestamps to delegation and conference models * ✨ feature: Add conferenceId argument to delegation and conference supervisor mutations * 🧼 format & lint * Sync Schema * sync schema --------- Co-authored-by: Tade Strehk <[email protected]>
1 parent a5c0ea0 commit d65289f

File tree

14 files changed

+372
-34
lines changed

14 files changed

+372
-34
lines changed

dev-restart-database.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ docker volume rm delegator_delegator-dev
2121
echo "Starting the database container..."
2222
docker compose -f dev.docker-compose.yml up -d postgres
2323

24-
# Wait for the database to start
25-
echo "Waiting for the database to start..."
26-
for i in {5..1}; do
27-
echo "Waiting... $i"
28-
sleep 1
29-
done
30-
3124
# Restore the database from the backup file
3225
echo "Restoring the database from the backup file..."
3326
docker exec -i postgres-dev-delegator psql -U postgres -d postgres <$POSTGRES_BACKUP_FILE
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[conferenceId,entryCode]` on the table `Delegation` will be added. If there are existing duplicate values, this will fail.
5+
- A unique constraint covering the columns `[conferenceId,assignedNationAlpha3Code]` on the table `Delegation` will be added. If there are existing duplicate values, this will fail.
6+
- A unique constraint covering the columns `[conferenceId,assignedNonStateActorId]` on the table `Delegation` will be added. If there are existing duplicate values, this will fail.
7+
8+
*/
9+
-- DropIndex
10+
DROP INDEX "Delegation_entryCode_key";
11+
12+
-- CreateIndex
13+
CREATE UNIQUE INDEX "Delegation_conferenceId_entryCode_key" ON "Delegation"("conferenceId", "entryCode");
14+
15+
-- CreateIndex
16+
CREATE UNIQUE INDEX "Delegation_conferenceId_assignedNationAlpha3Code_key" ON "Delegation"("conferenceId", "assignedNationAlpha3Code");
17+
18+
-- CreateIndex
19+
CREATE UNIQUE INDEX "Delegation_conferenceId_assignedNonStateActorId_key" ON "Delegation"("conferenceId", "assignedNonStateActorId");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- AlterTable
2+
ALTER TABLE "Conference" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
3+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- AlterTable
2+
ALTER TABLE "Committee" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
3+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
-- AlterTable
2+
ALTER TABLE "ConferenceParticipantStatus" ALTER COLUMN "updatedAt" SET DEFAULT CURRENT_TIMESTAMP;
3+
4+
-- AlterTable
5+
ALTER TABLE "ConferenceSupervisor" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
7+
8+
-- AlterTable
9+
ALTER TABLE "CustomConferenceRole" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
10+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
11+
12+
-- AlterTable
13+
ALTER TABLE "Delegation" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
14+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
15+
16+
-- AlterTable
17+
ALTER TABLE "DelegationMember" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
18+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
19+
20+
-- AlterTable
21+
ALTER TABLE "Nation" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
22+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
23+
24+
-- AlterTable
25+
ALTER TABLE "NonStateActor" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
26+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
27+
28+
-- AlterTable
29+
ALTER TABLE "PaymentTransaction" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
30+
31+
-- AlterTable
32+
ALTER TABLE "RoleApplication" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
33+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
34+
35+
-- AlterTable
36+
ALTER TABLE "SingleParticipant" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
37+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
38+
39+
-- AlterTable
40+
ALTER TABLE "TeamMember" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
41+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
42+
43+
-- AlterTable
44+
ALTER TABLE "User" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
45+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
46+
47+
-- AlterTable
48+
ALTER TABLE "UserReferenceInPaymentTransaction" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
49+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

prisma/schema.prisma

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ model Conference {
7272
singleParticipants SingleParticipant[]
7373
delegationMembers DelegationMember[]
7474
paymentTransactions PaymentTransaction[]
75+
76+
createdAt DateTime @default(now())
77+
updatedAt DateTime @updatedAt @default(now())
7578
}
7679

7780
model Committee {
@@ -84,6 +87,9 @@ model Committee {
8487
conferenceId String
8588
nations Nation[]
8689
delegationMembers DelegationMember[]
90+
91+
createdAt DateTime @default(now())
92+
updatedAt DateTime @updatedAt @default(now())
8793
}
8894

8995
enum FoodPreference {
@@ -131,6 +137,9 @@ model User {
131137
singleParticipant SingleParticipant[]
132138
ownPaymentTransactions PaymentTransaction[]
133139
paymentTransactionsReferences UserReferenceInPaymentTransaction[]
140+
141+
createdAt DateTime @default(now())
142+
updatedAt DateTime @updatedAt @default(now())
134143
}
135144

136145
enum AdministrativeStatus {
@@ -148,27 +157,29 @@ model ConferenceParticipantStatus {
148157
paymentStatus AdministrativeStatus @default(PENDING)
149158
didAttend Boolean @default(false)
150159
151-
createdAt DateTime @default(now())
152-
updatedAt DateTime @updatedAt
153-
154160
user User @relation(fields: [userId], references: [id])
155161
userId String
156162
conference Conference @relation(fields: [conferenceId], references: [id])
157163
conferenceId String
158164
165+
createdAt DateTime @default(now())
166+
updatedAt DateTime @updatedAt @default(now())
167+
159168
@@unique([userId, conferenceId])
160169
}
161170

162171
model PaymentTransaction {
163172
id String @id /// do not use nanoid here since we need an id that is suitable for the reason field in SEPA transaction
164173
amount Float
165-
createdAt DateTime @default(now())
166-
recievedAt DateTime?
167174
conference Conference @relation(fields: [conferenceId], references: [id])
168175
conferenceId String
169176
user User @relation(fields: [userId], references: [id])
170177
userId String
171178
paymentFor UserReferenceInPaymentTransaction[]
179+
180+
createdAt DateTime @default(now())
181+
recievedAt DateTime?
182+
updatedAt DateTime @updatedAt @default(now())
172183
}
173184

174185
model UserReferenceInPaymentTransaction {
@@ -177,6 +188,9 @@ model UserReferenceInPaymentTransaction {
177188
paymentTransactionId String
178189
user User @relation(fields: [userId], references: [id])
179190
userId String
191+
192+
createdAt DateTime @default(now())
193+
updatedAt DateTime @updatedAt @default(now())
180194
}
181195

182196
model Nation {
@@ -189,6 +203,9 @@ model Nation {
189203
committees Committee[]
190204
191205
assignedDelegations Delegation[]
206+
207+
createdAt DateTime @default(now())
208+
updatedAt DateTime @updatedAt @default(now())
192209
}
193210

194211
model NonStateActor {
@@ -205,6 +222,9 @@ model NonStateActor {
205222
206223
assignedDelegations Delegation[]
207224
225+
createdAt DateTime @default(now())
226+
updatedAt DateTime @updatedAt @default(now())
227+
208228
@@unique([conferenceId, abbreviation])
209229
@@unique([conferenceId, name])
210230
}
@@ -222,6 +242,9 @@ model CustomConferenceRole {
222242
223243
singleParticipantAssignments SingleParticipant[] @relation("assignment")
224244
245+
createdAt DateTime @default(now())
246+
updatedAt DateTime @updatedAt @default(now())
247+
225248
@@unique([conferenceId, name])
226249
}
227250

@@ -245,6 +268,9 @@ model SingleParticipant {
245268
246269
appliedForRoles CustomConferenceRole[]
247270
271+
createdAt DateTime @default(now())
272+
updatedAt DateTime @updatedAt @default(now())
273+
248274
@@unique([conferenceId, userId])
249275
}
250276

@@ -257,7 +283,7 @@ model Delegation {
257283
/// after submitting the entity should not be able to change
258284
applied Boolean @default(false)
259285
// this will always be auto generated
260-
entryCode String @unique
286+
entryCode String
261287
262288
conference Conference @relation(fields: [conferenceId], references: [id])
263289
conferenceId String
@@ -270,6 +296,13 @@ model Delegation {
270296
271297
assignedNonStateActor NonStateActor? @relation(fields: [assignedNonStateActorId], references: [id])
272298
assignedNonStateActorId String?
299+
300+
createdAt DateTime @default(now())
301+
updatedAt DateTime @updatedAt @default(now())
302+
303+
@@unique([conferenceId, entryCode])
304+
@@unique([conferenceId, assignedNationAlpha3Code])
305+
@@unique([conferenceId, assignedNonStateActorId])
273306
}
274307

275308
model RoleApplication {
@@ -285,6 +318,9 @@ model RoleApplication {
285318
nonStateActor NonStateActor? @relation(fields: [nonStateActorId], references: [id])
286319
nonStateActorId String?
287320
321+
createdAt DateTime @default(now())
322+
updatedAt DateTime @updatedAt @default(now())
323+
288324
@@unique([delegationId, nationId])
289325
@@unique([delegationId, nonStateActorId])
290326
@@unique([delegationId, rank])
@@ -304,6 +340,9 @@ model DelegationMember {
304340
305341
postAssignmentConferenceSupervisors ConferenceSupervisor[]
306342
343+
createdAt DateTime @default(now())
344+
updatedAt DateTime @updatedAt @default(now())
345+
307346
// users can only be once in this delegation
308347
@@unique([delegationId, userId])
309348
// users can only be in one delegation per conference
@@ -330,6 +369,9 @@ model ConferenceSupervisor {
330369
// which would render their data open to read for a completely unknown person
331370
postAssignmentDelegeationMembers DelegationMember[]
332371
372+
createdAt DateTime @default(now())
373+
updatedAt DateTime @updatedAt @default(now())
374+
333375
@@unique([conferenceId, userId])
334376
}
335377

@@ -347,5 +389,8 @@ model TeamMember {
347389
userId String
348390
role TeamRole @default(MEMBER)
349391
392+
createdAt DateTime @default(now())
393+
updatedAt DateTime @updatedAt @default(now())
394+
350395
@@unique([conferenceId, userId])
351396
}

0 commit comments

Comments
 (0)