Skip to content

Commit 9dd1a59

Browse files
authored
✨ feat: add committee topic tracker (#266)
1 parent ba12e27 commit 9dd1a59

File tree

7 files changed

+120
-14
lines changed

7 files changed

+120
-14
lines changed

drizzle/0002_ambiguous_felicia_hardy.sql

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE "committee_topic_changed_timestamp" (
2+
"id" text PRIMARY KEY NOT NULL,
3+
"created_at" timestamp DEFAULT now() NOT NULL,
4+
"updated_at" timestamp DEFAULT now(),
5+
"committee_id" text,
6+
"agenda_item_id" text,
7+
"timestamp" timestamp NOT NULL
8+
);
9+
--> statement-breakpoint
10+
CREATE TABLE "presence_changed_timestamp" (
11+
"id" text PRIMARY KEY NOT NULL,
12+
"created_at" timestamp DEFAULT now() NOT NULL,
13+
"updated_at" timestamp DEFAULT now(),
14+
"committee_member_id" text NOT NULL,
15+
"timestamp" timestamp NOT NULL,
16+
"present_set_to" boolean NOT NULL
17+
);
18+
--> statement-breakpoint
19+
ALTER TABLE "committee_topic_changed_timestamp" ADD CONSTRAINT "committee_topic_changed_timestamp_committee_id_committee_id_fk" FOREIGN KEY ("committee_id") REFERENCES "public"."committee"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
20+
ALTER TABLE "committee_topic_changed_timestamp" ADD CONSTRAINT "committee_topic_changed_timestamp_agenda_item_id_agenda_item_id_fk" FOREIGN KEY ("agenda_item_id") REFERENCES "public"."agenda_item"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
21+
ALTER TABLE "presence_changed_timestamp" ADD CONSTRAINT "presence_changed_timestamp_committee_member_id_committee_member_id_fk" FOREIGN KEY ("committee_member_id") REFERENCES "public"."committee_member"("id") ON DELETE cascade ON UPDATE no action;

drizzle/meta/0002_snapshot.json

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "488890cb-c751-4334-8571-8f1c487047ad",
2+
"id": "b0919364-785b-4d58-be70-b04de2cf729c",
33
"prevId": "eeaee9c9-bc33-4428-bc2b-6479d37af3df",
44
"version": "7",
55
"dialect": "postgresql",
@@ -290,6 +290,76 @@
290290
"checkConstraints": {},
291291
"isRLSEnabled": false
292292
},
293+
"public.committee_topic_changed_timestamp": {
294+
"name": "committee_topic_changed_timestamp",
295+
"schema": "",
296+
"columns": {
297+
"id": {
298+
"name": "id",
299+
"type": "text",
300+
"primaryKey": true,
301+
"notNull": true
302+
},
303+
"created_at": {
304+
"name": "created_at",
305+
"type": "timestamp",
306+
"primaryKey": false,
307+
"notNull": true,
308+
"default": "now()"
309+
},
310+
"updated_at": {
311+
"name": "updated_at",
312+
"type": "timestamp",
313+
"primaryKey": false,
314+
"notNull": false,
315+
"default": "now()"
316+
},
317+
"committee_id": {
318+
"name": "committee_id",
319+
"type": "text",
320+
"primaryKey": false,
321+
"notNull": false
322+
},
323+
"agenda_item_id": {
324+
"name": "agenda_item_id",
325+
"type": "text",
326+
"primaryKey": false,
327+
"notNull": false
328+
},
329+
"timestamp": {
330+
"name": "timestamp",
331+
"type": "timestamp",
332+
"primaryKey": false,
333+
"notNull": true
334+
}
335+
},
336+
"indexes": {},
337+
"foreignKeys": {
338+
"committee_topic_changed_timestamp_committee_id_committee_id_fk": {
339+
"name": "committee_topic_changed_timestamp_committee_id_committee_id_fk",
340+
"tableFrom": "committee_topic_changed_timestamp",
341+
"tableTo": "committee",
342+
"columnsFrom": ["committee_id"],
343+
"columnsTo": ["id"],
344+
"onDelete": "cascade",
345+
"onUpdate": "no action"
346+
},
347+
"committee_topic_changed_timestamp_agenda_item_id_agenda_item_id_fk": {
348+
"name": "committee_topic_changed_timestamp_agenda_item_id_agenda_item_id_fk",
349+
"tableFrom": "committee_topic_changed_timestamp",
350+
"tableTo": "agenda_item",
351+
"columnsFrom": ["agenda_item_id"],
352+
"columnsTo": ["id"],
353+
"onDelete": "cascade",
354+
"onUpdate": "no action"
355+
}
356+
},
357+
"compositePrimaryKeys": {},
358+
"uniqueConstraints": {},
359+
"policies": {},
360+
"checkConstraints": {},
361+
"isRLSEnabled": false
362+
},
293363
"public.conference": {
294364
"name": "conference",
295365
"schema": "",

drizzle/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
{
2020
"idx": 2,
2121
"version": "7",
22-
"when": 1748427319948,
23-
"tag": "0002_ambiguous_felicia_hardy",
22+
"when": 1748455384043,
23+
"tag": "0002_panoramic_agent_brand",
2424
"breakpoints": true
2525
}
2626
]

src/api/db/relations.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ export const relations = defineRelations(schema, (r) => ({
149149
to: r.speakersList.id
150150
})
151151
},
152+
committeeTopicChangedTimestamp: {
153+
agendaItem: r.one.agendaItem({
154+
from: r.committeeTopicChangedTimestamp.agendaItemId,
155+
to: r.agendaItem.id
156+
}),
157+
committee: r.one.committee({
158+
from: r.committeeTopicChangedTimestamp.committeeId,
159+
to: r.committee.id
160+
})
161+
},
152162
presenceChangedTimestamp: {
153163
committeeMember: r.one.committeeMember({
154164
from: r.presenceChangedTimestamp.committeeMemberId,

src/api/db/schema.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { nanoid } from '$lib/helpers/nanoid';
1+
import { nanoid } from '../../lib/helpers/nanoid';
22
import {
33
pgTable,
44
text,
@@ -207,6 +207,13 @@ export const spokenTimePeriod = pgTable('spoken_time_period', {
207207
endTimestamp: timestamp().notNull()
208208
});
209209

210+
export const committeeTopicChangedTimestamp = pgTable('committee_topic_changed_timestamp', {
211+
...defaultIdAndTimestamps,
212+
committeeId: text().references(() => committee.id, { onDelete: 'cascade' }),
213+
agendaItemId: text().references(() => agendaItem.id, { onDelete: 'cascade' }),
214+
timestamp: timestamp().notNull()
215+
});
216+
210217
export const presenceChangedTimestamp = pgTable('presence_changed_timestamp', {
211218
...defaultIdAndTimestamps,
212219
committeeMemberId: text()

src/api/handlers/committee.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ schemaBuilder.mutationFields((t) => {
151151
)
152152
);
153153

154+
if (args.activeAgendaItemId) {
155+
await db.insert(schema.committeeTopicChangedTimestamp).values({
156+
committeeId: args.id,
157+
agendaItemId: args.activeAgendaItemId,
158+
timestamp: new Date()
159+
});
160+
}
161+
154162
pubsub.updated(args.id);
155163

156164
return db.query.committee.findFirst(

0 commit comments

Comments
 (0)