This commit is contained in:
phaichayon
2026-06-11 12:46:57 +07:00
parent 1993d88306
commit 7a390cf0df
720 changed files with 100919 additions and 0 deletions

84
src/db/schema.ts Normal file
View File

@@ -0,0 +1,84 @@
import {
doublePrecision,
integer,
jsonb,
numeric,
pgTable,
text,
timestamp,
uniqueIndex,
} from "drizzle-orm/pg-core";
export const users = pgTable(
"users",
{
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull(),
passwordHash: text("password_hash").notNull(),
systemRole: text("system_role").default("user").notNull(),
image: text("image"),
activeOrganizationId: text("active_organization_id"),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => ({
emailIdx: uniqueIndex("users_email_idx").on(table.email),
}),
);
export const organizations = pgTable(
"organizations",
{
id: text("id").primaryKey(),
name: text("name").notNull(),
slug: text("slug").notNull(),
imageUrl: text("image_url"),
plan: text("plan").default("free").notNull(),
createdBy: text("created_by").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => ({
slugIdx: uniqueIndex("organizations_slug_idx").on(table.slug),
}),
);
export const memberships = pgTable("memberships", {
id: text("id").primaryKey(),
userId: text("user_id").notNull(),
organizationId: text("organization_id").notNull(),
role: text("role").default("user").notNull(),
businessRole: text("business_role").default("viewer").notNull(),
permissions: text("permissions").array().default([]).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.defaultNow()
.notNull(),
});
export const products = pgTable("products", {
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
organizationId: text("organization_id").notNull(),
name: text("name").notNull(),
category: text("category").notNull(),
description: text("description").notNull(),
photoUrl: text("photo_url").notNull(),
price: doublePrecision("price").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.defaultNow()
.notNull(),
});