1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import { relations } from 'drizzle-orm';
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
export const users = sqliteTable('users', {
uid: text('uid').primaryKey(),
email: text('email').notNull(),
displayName: text('display_name').notNull(),
photoURL: text('photo_url'),
});
export const offices = sqliteTable('offices', {
id: text('id').primaryKey(),
name: text('name').notNull(),
location: text('location').notNull(),
capacity: integer('capacity').notNull(),
description: text('description'),
});
export const reservations = sqliteTable('reservations', {
id: text('id').primaryKey(),
officeId: text('office_id')
.notNull()
.references(() => offices.id),
userId: text('user_id')
.notNull()
.references(() => users.uid),
officeName: text('office_name').notNull(),
userEmail: text('user_email').notNull(),
date: text('date').notNull(),
startTime: text('start_time').notNull(),
endTime: text('end_time').notNull(),
createdAt: integer('created_at'),
});
export const usersRelations = relations(users, ({ many }) => ({
reservations: many(reservations),
}));
export const officesRelations = relations(offices, ({ many }) => ({
reservations: many(reservations),
}));
export const reservationsRelations = relations(reservations, ({ one }) => ({
office: one(offices, {
fields: [reservations.officeId],
references: [offices.id],
}),
user: one(users, {
fields: [reservations.userId],
references: [users.uid],
}),
}));
|