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

feat/club events' schema #213

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 10 additions & 2 deletions server/db/schema/clubs.schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { relations } from 'drizzle-orm';
import { relations, sql } from 'drizzle-orm';
import {
boolean,
date,
Expand All @@ -10,7 +10,14 @@ import {
varchar,
} from 'drizzle-orm/pg-core';

import { clubMembers, clubSocials, departments, faculty, persons } from '.';
import {
clubMembers,
clubSocials,
departments,
faculty,
persons,
events,
} from '.';

export const clubs = pgTable('clubs', {
id: smallserial('id').primaryKey(),
Expand Down Expand Up @@ -41,6 +48,7 @@ export const clubs = pgTable('clubs', {
});

export const clubsRelations = relations(clubs, ({ many, one }) => ({
clubEvents: many(events),
clubMembers: many(clubMembers),
clubSocials: many(clubSocials),
department: one(departments, {
Expand Down
32 changes: 32 additions & 0 deletions server/db/schema/events.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { relations } from 'drizzle-orm';
import {
pgTable,
serial,
varchar,
timestamp,
integer,
} from 'drizzle-orm/pg-core';

import { clubs, persons } from '.';

export const events = pgTable('events', {
id: serial('id').primaryKey(),
name: varchar('name', { length: 128 }).notNull(),
description: varchar('description'),
startDate: timestamp('date').notNull(),
endDate: timestamp('date').notNull(),
clubId: integer('club_id').references(() => clubs.id),
updatedAt: timestamp('updated_at')
.$onUpdate(() => new Date())
.notNull(),
updatedBy: integer('updated_by')
.references(() => persons.id)
.notNull(),
});

export const eventsRelations = relations(events, ({ one }) => ({
club: one(clubs, {
fields: [events.clubId],
references: [clubs.id],
}),
}));
1 change: 1 addition & 0 deletions server/db/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './deans.schema';
export * from './department-heads.schema';
export * from './departments.schema';
export * from './doctorates.schema';
export * from './events.schema';
export * from './faculty.schema';
export * from './faq.schema';
export * from './majors.schema';
Expand Down