2024-11-14 03:51:08 +00:00
|
|
|
import {
|
|
|
|
boolean,
|
|
|
|
integer,
|
|
|
|
pgTable,
|
|
|
|
primaryKey,
|
|
|
|
timestamp,
|
|
|
|
varchar
|
|
|
|
} from "drizzle-orm/pg-core";
|
|
|
|
|
|
|
|
export const users = pgTable("users", {
|
|
|
|
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
2025-01-29 03:52:18 +00:00
|
|
|
email: varchar().unique().notNull(),
|
2024-11-14 03:51:08 +00:00
|
|
|
name: varchar({ length: 26 }).unique().notNull(),
|
|
|
|
pass: varchar({ length: 255 }).notNull(),
|
|
|
|
registered: timestamp().notNull(),
|
2024-12-25 23:44:29 +00:00
|
|
|
status: integer().default(0).notNull() // 000 |> verified / banned / moderator
|
2024-11-14 03:51:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export const updates = pgTable("updates", {
|
|
|
|
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
|
|
|
user: integer()
|
|
|
|
.references(() => users.id, { onDelete: "cascade" })
|
|
|
|
.notNull(),
|
|
|
|
mood: integer().default(0).notNull(),
|
|
|
|
description: varchar({ length: 512 }).default("").notNull(),
|
|
|
|
date: timestamp().notNull()
|
|
|
|
});
|
|
|
|
|
2024-11-17 19:16:27 +00:00
|
|
|
export const journalEntries = pgTable("journal_entries", {
|
|
|
|
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
2024-12-11 03:27:43 +00:00
|
|
|
user: integer()
|
|
|
|
.references(() => users.id, { onDelete: "cascade" })
|
|
|
|
.notNull(),
|
2024-11-17 19:16:27 +00:00
|
|
|
moodChange: integer("mood-change").default(0).notNull(),
|
2024-12-26 21:24:04 +00:00
|
|
|
title: varchar({ length: 64 }).default("").notNull(),
|
2024-11-17 19:16:27 +00:00
|
|
|
entry: varchar({ length: 4096 }).default("").notNull(),
|
|
|
|
visibility: integer().default(1).notNull(),
|
|
|
|
date: timestamp().notNull()
|
|
|
|
});
|
|
|
|
|
2025-01-23 01:34:25 +00:00
|
|
|
export const journalComments = pgTable("journal_comments", {
|
|
|
|
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
|
|
|
user: integer()
|
|
|
|
.references(() => users.id, { onDelete: "cascade" })
|
|
|
|
.notNull(),
|
|
|
|
entry: integer()
|
|
|
|
.references(() => journalEntries.id, { onDelete: "cascade" })
|
|
|
|
.notNull(),
|
|
|
|
content: varchar({ length: 512 }).notNull(),
|
|
|
|
date: timestamp().notNull()
|
|
|
|
});
|
|
|
|
|
2024-11-14 03:51:08 +00:00
|
|
|
export const profiles = pgTable("profiles", {
|
|
|
|
user: integer()
|
|
|
|
.references(() => users.id, { onDelete: "cascade" })
|
|
|
|
.primaryKey()
|
|
|
|
.notNull(),
|
|
|
|
bio: varchar({ length: 1024 }).default("").notNull(),
|
|
|
|
website: varchar().default("").notNull()
|
|
|
|
});
|
|
|
|
|
|
|
|
export const follows = pgTable(
|
|
|
|
"follows",
|
|
|
|
{
|
|
|
|
userId: integer("user_id").references(() => users.id, {
|
|
|
|
onDelete: "cascade"
|
|
|
|
}),
|
|
|
|
followerId: integer("follower_id").references(() => users.id, {
|
|
|
|
onDelete: "cascade"
|
|
|
|
})
|
|
|
|
},
|
|
|
|
(table) => {
|
|
|
|
return {
|
|
|
|
pk: primaryKey({ columns: [table.userId, table.followerId] })
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2024-12-11 03:27:43 +00:00
|
|
|
|
|
|
|
export const inviteCodes = pgTable("invite_codes", {
|
|
|
|
token: varchar({ length: 22 }).primaryKey(),
|
|
|
|
user: integer("user_id").references(() => users.id, { onDelete: "cascade" }),
|
|
|
|
granted: timestamp().notNull(),
|
|
|
|
expires: timestamp().default(new Date(0)),
|
2024-12-25 23:44:29 +00:00
|
|
|
confers: integer().default(0)
|
2024-12-11 03:27:43 +00:00
|
|
|
});
|