Skip to content
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
10 changes: 3 additions & 7 deletions server/db/schema/deans.schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { relations, sql } from 'drizzle-orm';
import { pgTable } from 'drizzle-orm/pg-core';

import { faculty } from '.';
import { faculty, staff } from '.';

export const deans = pgTable('deans', (t) => ({
id: t.smallserial().primaryKey(),
Expand All @@ -24,19 +24,14 @@ export const deans = pgTable('deans', (t) => ({
.references(() => faculty.id)
.notNull(),
associateFacultyId: t.integer().references(() => faculty.id),
staffIds: t
.integer()
.array()
.default(sql`'{}'`)
.notNull(),
activityLogs: t
.text()
.array()
.default(sql`'{}'`)
.notNull(),
}));

export const deansRelations = relations(deans, ({ one }) => ({
export const deansRelations = relations(deans, ({ one, many }) => ({
faculty: one(faculty, {
fields: [deans.facultyId],
references: [faculty.id],
Expand All @@ -45,4 +40,5 @@ export const deansRelations = relations(deans, ({ one }) => ({
fields: [deans.associateFacultyId],
references: [faculty.id],
}),
staff: many(staff),
}));
12 changes: 10 additions & 2 deletions server/db/schema/staff.schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { relations } from 'drizzle-orm';
import { pgTable, uniqueIndex } from 'drizzle-orm/pg-core';

import { departments, persons, sections } from '.';
import { deans, departments, persons, sections } from '.';

export const staff = pgTable(
'staff',
Expand All @@ -12,9 +12,13 @@ export const staff = pgTable(
.references(() => persons.id),
employeeId: t.varchar({ length: 8 }).notNull(),
personalEmail: t.varchar({ length: 256 }),
workingSectionId: t.smallint().references(() => sections.id),
designation: t.varchar({ length: 64 }).notNull(),
workingOfficeType: t.varchar({
enum: ['department', 'section', 'deans'],
}),
workingDepartmentId: t.smallint().references(() => departments.id),
workingSectionId: t.smallint().references(() => sections.id),
workingDeanOfficeId: t.smallint().references(() => deans.id),
}),
(table) => [uniqueIndex('staff_employee_id_idx').on(table.employeeId)]
);
Expand All @@ -32,4 +36,8 @@ export const staffRelations = relations(staff, ({ one }) => ({
fields: [staff.workingSectionId],
references: [sections.id],
}),
deans: one(deans, {
fields: [staff.workingDeanOfficeId],
references: [deans.id],
}),
}));