-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathramadhan_campaigns.ts
More file actions
46 lines (43 loc) · 1.15 KB
/
ramadhan_campaigns.ts
File metadata and controls
46 lines (43 loc) · 1.15 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
import { relations } from "drizzle-orm";
import {
date,
integer,
pgTable,
serial,
text,
unique,
} from "drizzle-orm/pg-core";
import { timestamps } from "./helpers";
import { institutions } from "./institutions";
import { users } from "./users";
export const ramadhanCampaigns = pgTable(
"ramadhan_campaigns",
{
id: serial("id").primaryKey(),
year: integer("year").notNull(),
dayNumber: integer("day_number").notNull(),
featuredDate: date("featured_date", { mode: "date" }).notNull(),
institutionId: integer("institution_id")
.notNull()
.references(() => institutions.id),
caption: text("caption"),
curatedBy: text("curated_by").references(() => users.id),
...timestamps,
},
(t) => [
unique().on(t.year, t.dayNumber),
unique().on(t.year, t.institutionId),
],
);
export const ramadhanCampaignsRelations = relations(
ramadhanCampaigns,
({ one }) => ({
institution: one(institutions),
curator: one(users, {
fields: [ramadhanCampaigns.curatedBy],
references: [users.id],
}),
}),
);
export type RamadhanCampaign = typeof ramadhanCampaigns.$inferSelect;
export type NewRamadhanCampaign = typeof ramadhanCampaigns.$inferInsert;