Spaces:
Sleeping
Sleeping
File size: 1,266 Bytes
7f81110 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import { pgTable, uuid, text, timestamp, uniqueIndex, index } from "drizzle-orm/pg-core";
import { users } from "./users";
import { organizations } from "./organizations";
import { stores } from "../../../../../modules/shopify/infrastructure/postgres/schema/stores";
export const userWorkspaces = pgTable("user_workspaces", {
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }),
storeId: uuid("store_id").references(() => stores.id, { onDelete: "set null" }),
role: text("role").default("admin").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
}, (table) => ({
userOrgStoreIdx: uniqueIndex("user_org_store_unique_idx").on(table.userId, table.organizationId, table.storeId),
userIdx: index("user_workspaces_user_id_idx").on(table.userId),
orgIdx: index("user_workspaces_organization_id_idx").on(table.organizationId),
}));
export type UserWorkspace = typeof userWorkspaces.$inferSelect;
export type NewUserWorkspace = typeof userWorkspaces.$inferInsert;
|