mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-15 23:30:17 +02:00
🗃️ create DB models
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
aiProviders,
|
||||
clients,
|
||||
db,
|
||||
redirects,
|
||||
resourcePolicies,
|
||||
resources,
|
||||
siteResources
|
||||
@@ -140,6 +141,30 @@ export async function getUniqueProviderName(orgId: string): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUniqueRedirectName(orgId: string): Promise<string> {
|
||||
let loops = 0;
|
||||
while (true) {
|
||||
if (loops > 100) {
|
||||
throw new Error("Could not generate a unique name");
|
||||
}
|
||||
|
||||
const name = generateName();
|
||||
|
||||
const redirectCount = await db
|
||||
.select({
|
||||
niceId: redirects.niceId,
|
||||
orgId: redirects.orgId
|
||||
})
|
||||
.from(redirects)
|
||||
.where(and(eq(redirects.niceId, name), eq(redirects.orgId, orgId)));
|
||||
|
||||
if (redirectCount.length === 0) {
|
||||
return name;
|
||||
}
|
||||
loops++;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUniqueResourcePolicyName(
|
||||
orgId: string
|
||||
): Promise<string> {
|
||||
|
||||
@@ -237,7 +237,7 @@ export const redirects = pgTable("redirects", {
|
||||
resourceId: integer("resourceId").references(() => resources.resourceId, {
|
||||
onDelete: "cascade"
|
||||
}),
|
||||
domainId: integer("domainId").references(() => domains.domainId, {
|
||||
domainId: varchar("domainId").references(() => domains.domainId, {
|
||||
onDelete: "cascade"
|
||||
}),
|
||||
niceId: text("niceId").notNull(),
|
||||
@@ -2086,6 +2086,7 @@ export type ResourcePolicy = InferSelectModel<typeof resourcePolicies>;
|
||||
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
||||
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
||||
export type ResourcePolicyRule = InferSelectModel<typeof resourcePolicyRules>;
|
||||
export type Redirect = InferSelectModel<typeof redirects>;
|
||||
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
||||
export type AiModel = InferSelectModel<typeof aiModels>;
|
||||
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
||||
|
||||
@@ -253,7 +253,7 @@ export const redirects = sqliteTable("redirects", {
|
||||
resourceId: integer("resourceId").references(() => resources.resourceId, {
|
||||
onDelete: "cascade"
|
||||
}),
|
||||
domainId: integer("domainId").references(() => domains.domainId, {
|
||||
domainId: text("domainId").references(() => domains.domainId, {
|
||||
onDelete: "cascade"
|
||||
}),
|
||||
niceId: text("niceId").notNull(),
|
||||
@@ -2127,6 +2127,7 @@ export type ResourcePolicyHeaderAuth = InferSelectModel<
|
||||
>;
|
||||
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
||||
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
||||
export type Redirect = InferSelectModel<typeof redirects>;
|
||||
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
||||
export type AiModel = InferSelectModel<typeof aiModels>;
|
||||
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
||||
|
||||
Reference in New Issue
Block a user