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 20, 2024
1 parent e290e01 commit c389818
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions server/db/schema/hostels.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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(),
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(),
});

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

export const hostelStaff = pgTable('hostel_posts', {
hostelId: serial('hostel_id')
.references(() => hostels.id)
.notNull(),
staffId: serial('staff_id')
.references(() => staff.id)
.notNull(),
post: varchar('post', { enum: ['warden', 'deputy-warden'] }).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],
}),
}));

0 comments on commit c389818

Please sign in to comment.