-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathschema.ts
More file actions
108 lines (98 loc) · 3.75 KB
/
Copy pathschema.ts
File metadata and controls
108 lines (98 loc) · 3.75 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { relations } from "drizzle-orm";
import {
integer,
pgEnum,
pgTable,
real,
timestamp,
uuid,
varchar,
} from "drizzle-orm/pg-core";
export const invitationStatuses = pgEnum("invitation_status", [
"pending",
"accepted",
"declined",
]);
export const roleEnum = pgEnum("role", ["manager", "worker"]);
export const users = pgTable("users", {
id: uuid("id").primaryKey().defaultRandom(),
name: varchar("name", { length: 255 }).notNull(),
email: varchar("email", { length: 255 }).notNull().unique(),
password: varchar("password", { length: 255 }).notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const organizations = pgTable("organizations", {
id: uuid("id").primaryKey().defaultRandom(),
name: varchar("name", { length: 255 }).notNull(),
ownerId: uuid("owner_id").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const memberships = pgTable("memberships", {
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id").notNull(),
organizationId: uuid("organization_id").notNull(),
role: roleEnum("role").notNull(),
joinedAt: timestamp("joined_at").notNull().defaultNow(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const invitations = pgTable("invitations", {
id: uuid("id").primaryKey().defaultRandom(),
organizationId: uuid("organization_id").notNull(),
email: varchar("email", { length: 255 }).notNull(),
token: varchar("token", { length: 255 }).notNull(),
role: roleEnum("role").notNull(),
status: invitationStatuses("status").notNull().default("pending"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const tasks = pgTable("tasks", {
id: uuid("id").primaryKey().defaultRandom(),
organizationId: uuid("organization_id").notNull(),
title: varchar("title", { length: 255 }).notNull(),
description: varchar("description", { length: 1000 }).notNull(),
creatorId: uuid("creator_id").notNull(),
assignedTo: uuid("assigned_to"),
status: varchar("status", { length: 50 }).notNull(),
latitude: real("latitude"),
longitude: real("longitude"),
deadline: timestamp("deadline"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const locations = pgTable("locations", {
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id").notNull(),
organizationId: uuid("organization_id").notNull(),
latitude: integer("latitude").notNull(),
longitude: integer("longitude").notNull(),
recordedAt: timestamp("recorded_at").notNull().defaultNow(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const messages = pgTable("messages", {
id: uuid("id").primaryKey().defaultRandom(),
organizationId: uuid("organization_id").notNull(),
senderId: uuid("sender_id").notNull(),
receiverId: uuid("receiver_id").notNull(),
content: varchar("content", { length: 1000 }).notNull(),
readAt: timestamp("read_at"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const tasksRelations = relations(tasks, ({ one }) => ({
assignedWorker: one(users, {
fields: [tasks.assignedTo],
references: [users.id],
}),
creator: one(users, {
fields: [tasks.creatorId],
references: [users.id],
}),
organization: one(organizations, {
fields: [tasks.organizationId],
references: [organizations.id],
}),
}));