From d7d4a95b81383cee9fd6ac061a152414cc8f52e3 Mon Sep 17 00:00:00 2001 From: KambojRajan Date: Fri, 30 Aug 2024 18:43:58 +0530 Subject: [PATCH 1/3] init: club events schema --- server/db/schema/clubs.schema.ts | 18 +++++++++++++++- server/db/schema/events.schema.ts | 34 +++++++++++++++++++++++++++++++ server/db/schema/index.ts | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 server/db/schema/events.schema.ts diff --git a/server/db/schema/clubs.schema.ts b/server/db/schema/clubs.schema.ts index 910b4eb7..c000d10f 100644 --- a/server/db/schema/clubs.schema.ts +++ b/server/db/schema/clubs.schema.ts @@ -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(), @@ -30,6 +37,9 @@ export const clubs = pgTable('clubs', { facultyInchargeId2: integer('faculty_incharge_id2').references( () => faculty.id ), + facultyInchargeId3: integer('faculty_incharge_id3').references( + () => faculty.id + ), isActive: boolean('is_active').default(true).notNull(), createdOn: date('created_on', { mode: 'date' }).defaultNow().notNull(), updatedAt: timestamp('updated_at') @@ -43,6 +53,7 @@ export const clubs = pgTable('clubs', { export const clubsRelations = relations(clubs, ({ many, one }) => ({ clubMembers: many(clubMembers), clubSocials: many(clubSocials), + clubEvents: many(events), department: one(departments, { fields: [clubs.departmentId], references: [departments.id], @@ -57,4 +68,9 @@ export const clubsRelations = relations(clubs, ({ many, one }) => ({ fields: [clubs.facultyInchargeId2], references: [faculty.id], }), + facultyIncharge3: one(faculty, { + relationName: 'facultyIncharge3', + fields: [clubs.facultyInchargeId3], + references: [faculty.id], + }), })); diff --git a/server/db/schema/events.schema.ts b/server/db/schema/events.schema.ts new file mode 100644 index 00000000..cee0c152 --- /dev/null +++ b/server/db/schema/events.schema.ts @@ -0,0 +1,34 @@ +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', { length: 512 }), + startDate: timestamp('date').notNull(), + endDate: timestamp('date').notNull(), + clubId: integer('club_id') + .references(() => clubs.id) + .notNull(), + 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], + }), +})); diff --git a/server/db/schema/index.ts b/server/db/schema/index.ts index 3124a222..773c0750 100644 --- a/server/db/schema/index.ts +++ b/server/db/schema/index.ts @@ -20,3 +20,4 @@ export * from './sponsored-research-projects.schema'; export * from './staff.schema'; export * from './student-academic-details.schema'; export * from './students.schema'; +export * from './events.schema'; From 3c2c3cc90da0f60d593408106e495baba085afdf Mon Sep 17 00:00:00 2001 From: KambojRajan Date: Sat, 31 Aug 2024 13:57:26 +0530 Subject: [PATCH 2/3] fix: ordering of imports and columns --- server/db/schema/clubs.schema.ts | 9 +++++++-- server/db/schema/events.schema.ts | 6 ++---- server/db/schema/index.ts | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/db/schema/clubs.schema.ts b/server/db/schema/clubs.schema.ts index c000d10f..79e4f29e 100644 --- a/server/db/schema/clubs.schema.ts +++ b/server/db/schema/clubs.schema.ts @@ -1,4 +1,4 @@ -import { relations } from 'drizzle-orm'; +import { relations, sql } from 'drizzle-orm'; import { boolean, date, @@ -27,6 +27,11 @@ export const clubs = pgTable('clubs', { tagline: varchar('tagline', { length: 256 }).notNull(), email: varchar('email', { length: 256 }).notNull(), aboutUs: varchar('about_us').notNull(), + howToJoinUs: varchar('how_to_join_us').notNull(), + whyToJoinUs: varchar('why_to_join_us').notNull(), + notifications: varchar('notifications') + .array() + .default(sql`'{}'`), category: varchar('category', { enum: ['committee', 'cultural', 'crew', 'technical'], }).notNull(), @@ -51,9 +56,9 @@ export const clubs = pgTable('clubs', { }); export const clubsRelations = relations(clubs, ({ many, one }) => ({ + clubEvents: many(events), clubMembers: many(clubMembers), clubSocials: many(clubSocials), - clubEvents: many(events), department: one(departments, { fields: [clubs.departmentId], references: [departments.id], diff --git a/server/db/schema/events.schema.ts b/server/db/schema/events.schema.ts index cee0c152..67fc7f53 100644 --- a/server/db/schema/events.schema.ts +++ b/server/db/schema/events.schema.ts @@ -12,12 +12,10 @@ import { clubs, persons } from '.'; export const events = pgTable('events', { id: serial('id').primaryKey(), name: varchar('name', { length: 128 }).notNull(), - description: varchar('description', { length: 512 }), + description: varchar('description'), startDate: timestamp('date').notNull(), endDate: timestamp('date').notNull(), - clubId: integer('club_id') - .references(() => clubs.id) - .notNull(), + clubId: integer('club_id').references(() => clubs.id), updatedAt: timestamp('updated_at') .$onUpdate(() => new Date()) .notNull(), diff --git a/server/db/schema/index.ts b/server/db/schema/index.ts index 773c0750..50d3a45a 100644 --- a/server/db/schema/index.ts +++ b/server/db/schema/index.ts @@ -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'; @@ -20,4 +21,3 @@ export * from './sponsored-research-projects.schema'; export * from './staff.schema'; export * from './student-academic-details.schema'; export * from './students.schema'; -export * from './events.schema'; From 15e8b2030193c56173e09bbb1909ddc4e4b8d82c Mon Sep 17 00:00:00 2001 From: KambojRajan Date: Fri, 6 Sep 2024 10:43:31 +0530 Subject: [PATCH 3/3] fix: remove unrelated changes --- server/db/schema/clubs.schema.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/server/db/schema/clubs.schema.ts b/server/db/schema/clubs.schema.ts index 79e4f29e..3dffbc90 100644 --- a/server/db/schema/clubs.schema.ts +++ b/server/db/schema/clubs.schema.ts @@ -27,11 +27,6 @@ export const clubs = pgTable('clubs', { tagline: varchar('tagline', { length: 256 }).notNull(), email: varchar('email', { length: 256 }).notNull(), aboutUs: varchar('about_us').notNull(), - howToJoinUs: varchar('how_to_join_us').notNull(), - whyToJoinUs: varchar('why_to_join_us').notNull(), - notifications: varchar('notifications') - .array() - .default(sql`'{}'`), category: varchar('category', { enum: ['committee', 'cultural', 'crew', 'technical'], }).notNull(), @@ -42,9 +37,6 @@ export const clubs = pgTable('clubs', { facultyInchargeId2: integer('faculty_incharge_id2').references( () => faculty.id ), - facultyInchargeId3: integer('faculty_incharge_id3').references( - () => faculty.id - ), isActive: boolean('is_active').default(true).notNull(), createdOn: date('created_on', { mode: 'date' }).defaultNow().notNull(), updatedAt: timestamp('updated_at') @@ -73,9 +65,4 @@ export const clubsRelations = relations(clubs, ({ many, one }) => ({ fields: [clubs.facultyInchargeId2], references: [faculty.id], }), - facultyIncharge3: one(faculty, { - relationName: 'facultyIncharge3', - fields: [clubs.facultyInchargeId3], - references: [faculty.id], - }), }));