diff --git a/server/db/schema.ts b/server/db/schema.ts index f60e1d68..896b6d84 100644 --- a/server/db/schema.ts +++ b/server/db/schema.ts @@ -129,6 +129,73 @@ export const passwordResetTokens = sqliteTable("passwordResetTokens", { expiresAt: integer("expiresAt").notNull(), }); +export const actions = sqliteTable("actions", { + actionId: integer("actionId").primaryKey({ autoIncrement: true }), + name: text("name").notNull(), + description: text("description"), +}); + +export const roles = sqliteTable("roles", { + roleId: integer("roleId").primaryKey({ autoIncrement: true }), + orgId: integer("orgId").references(() => orgs.orgId, { onDelete: "cascade" }), + name: text("name").notNull(), + description: text("description"), +}); + +export const roleActions = sqliteTable("roleActions", { + roleId: integer("roleId") + .notNull() + .references(() => roles.roleId, { onDelete: "cascade" }), + actionId: integer("actionId") + .notNull() + .references(() => actions.actionId, { onDelete: "cascade" }), +}); + +export const userActions = sqliteTable("userActions", { + userId: text("userId") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + actionId: integer("actionId") + .notNull() + .references(() => actions.actionId, { onDelete: "cascade" }), +}); + +export const roleSites = sqliteTable("roleActions", { + roleId: integer("role]Id") + .notNull() + .references(() => roles.roleId, { onDelete: "cascade" }), + siteId: integer("siteId") + .notNull() + .references(() => sites.siteId, { onDelete: "cascade" }), +}); + +export const userSites = sqliteTable("userActions", { + userId: text("user]Id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + siteId: integer("siteId") + .notNull() + .references(() => sites.siteId, { onDelete: "cascade" }), +}); + +export const roleResources = sqliteTable("roleActions", { + roleId: integer("role]Id") + .notNull() + .references(() => roles.roleId, { onDelete: "cascade" }), + resourceId: integer("resourceId") + .notNull() + .references(() => resources.resourceId, { onDelete: "cascade" }), +}); + +export const userResources = sqliteTable("userActions", { + userId: text("user]Id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + resourceId: integer("resourceId") + .notNull() + .references(() => resources.resourceId, { onDelete: "cascade" }), +}); + // Define the model types for type inference export type Org = InferSelectModel; export type User = InferSelectModel; @@ -143,3 +210,11 @@ export type EmailVerificationCode = InferSelectModel< >; export type TwoFactorBackupCode = InferSelectModel; export type PasswordResetToken = InferSelectModel; +export type Role = InferSelectModel; +export type Action = InferSelectModel; +export type RoleAction = InferSelectModel; +export type UserAction = InferSelectModel; +export type RoleSite = InferSelectModel; +export type UserSite = InferSelectModel; +export type RoleResource = InferSelectModel; +export type UserResource = InferSelectModel; \ No newline at end of file