Skip to content

Commit

Permalink
feat: hostels schema
Browse files Browse the repository at this point in the history
  • Loading branch information
heydoyouknowme0 committed Aug 31, 2024
1 parent e290e01 commit 002cc2a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/db/schema/faculty.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
courses,
departments,
doctorates,
hostels,
persons,
sections,
sponsoredResearchProjects,
Expand Down Expand Up @@ -135,4 +136,14 @@ export const facultyRelations = relations(faculty, ({ many, one }) => ({
fields: [faculty.id],
references: [persons.id],
}),
wardensHostel: one(hostels, {
fields: [faculty.id],
references: [hostels.id],
relationName: 'wardens',
}),
deputyWardensHostel: one(hostels, {
fields: [faculty.employeeId],
references: [hostels.id],
relationName: 'deputy_wardens',
}),
}));
51 changes: 51 additions & 0 deletions server/db/schema/hostels.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { relations } from 'drizzle-orm';
import { pgTable, serial, text, timestamp, varchar } from 'drizzle-orm/pg-core';

import { faculty, staff } from '.';

export const hostels = pgTable('hostels', {
id: serial('id').primaryKey(),
address: text('address').notNull(),
name: varchar('name', { length: 256 }).notNull(),
urlName: varchar('url_name', { length: 128 }).notNull(),
email: varchar('email', { length: 256 }).notNull(),
telephone: varchar('telephone', { length: 13 }).notNull(),
alternateTelephone: varchar('alternate_telephone', { length: 13 }),
type: varchar('type', {
enum: ['boys', 'girls'],
}).notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at')
.$onUpdate(() => new Date())
.notNull(),
overview: text('overview').array().notNull(),
staffOverview: text('staff_overview').array().notNull(),
facilities: text('facilities').array().notNull(),
});

export const hostelsRelations = relations(hostels, ({ many }) => ({
hostelStaff: many(hostelStaff),
wardens: many(faculty, { relationName: 'wardens' }),
deputyWardens: many(faculty, { relationName: 'deputy_wardens' }),
}));

export const hostelStaff = pgTable('hostel_staff', {
hostelId: serial('hostel_id')
.references(() => hostels.id)
.notNull(),
staffId: serial('staff_id')
.references(() => staff.id)
.notNull(),
post: varchar('post', { enum: ['supervisor'] }).notNull(),
});

export const hostelStaffRelations = relations(hostelStaff, ({ one }) => ({
hostel: one(hostels, {
fields: [hostelStaff.hostelId],
references: [hostels.id],
}),
staff: one(staff, {
fields: [hostelStaff.staffId],
references: [staff.id],
}),
}));
1 change: 1 addition & 0 deletions server/db/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './departments.schema';
export * from './doctorates.schema';
export * from './faculty.schema';
export * from './faq.schema';
export * from './hostels.schema';
export * from './majors.schema';
export * from './notifications.schema';
export * from './persons.schema';
Expand Down

0 comments on commit 002cc2a

Please sign in to comment.