Speilegg
Speilegg
DTDrizzle Team
Created by Speilegg on 5/1/2024 in #help
Enum as primary key for roles (sqlite)
I guess rubber ducking this helped me with the inferring as I can specify the enum on the organizationUsers table:
export const userOrganizationTable = sqliteTable("user_organizations", {
id: text("id").primaryKey(),
roleId: text("role_id", { enum: ROLES })
.notNull()
.references(() => roleTable.id, { onDelete: "restrict" }), // Using restrict to prevent deletion of roles that are in use
userId: text("user_id")
.notNull()
.references(() => userTable.id, { onDelete: "cascade" }),
organizationId: text("organization_id")
.notNull()
.references(() => organizationTable.id, { onDelete: "cascade" }),
});
export const userOrganizationTable = sqliteTable("user_organizations", {
id: text("id").primaryKey(),
roleId: text("role_id", { enum: ROLES })
.notNull()
.references(() => roleTable.id, { onDelete: "restrict" }), // Using restrict to prevent deletion of roles that are in use
userId: text("user_id")
.notNull()
.references(() => userTable.id, { onDelete: "cascade" }),
organizationId: text("organization_id")
.notNull()
.references(() => organizationTable.id, { onDelete: "cascade" }),
});
Still would love to hear any thoughts on this pattern in general 🙂
2 replies