Patching a bug when delete an organization, add refetch.

This commit is contained in:
charlesgauthereau
2025-08-27 21:16:13 +02:00
parent dd7a65262c
commit 2f9e33f4db
16 changed files with 1842 additions and 38 deletions
+16
View File
@@ -0,0 +1,16 @@
CREATE TYPE "public"."retention_policy_type" AS ENUM('count', 'days', 'gfs');--> statement-breakpoint
CREATE TABLE "retention_policies" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"database_id" uuid NOT NULL,
"type" "retention_policy_type" NOT NULL,
"count" integer DEFAULT 7,
"days" integer DEFAULT 30,
"gfs_daily" integer DEFAULT 7,
"gfs_weekly" integer DEFAULT 4,
"gfs_monthly" integer DEFAULT 12,
"gfs_yearly" integer DEFAULT 3,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp
);
--> statement-breakpoint
ALTER TABLE "retention_policies" ADD CONSTRAINT "retention_policies_database_id_databases_id_fk" FOREIGN KEY ("database_id") REFERENCES "public"."databases"("id") ON DELETE cascade ON UPDATE no action;
File diff suppressed because it is too large Load Diff
+7
View File
@@ -22,6 +22,13 @@
"when": 1753720983182,
"tag": "0002_pink_groot",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1756321312852,
"tag": "0003_absent_maestro",
"breakpoints": true
}
]
}
+25
View File
@@ -24,6 +24,7 @@ export const database = pgTable("databases", {
projectId: uuid("project_id")
.references(() => project.id),
});
export const backup = pgTable(
@@ -41,6 +42,23 @@ export const backup = pgTable(
// (table) => [uniqueIndex("database_id_status_unique").on(table.databaseId, table.status)]
);
export const retentionPolicyType = pgEnum("retention_policy_type", ["count", "days", "gfs"]);
export const retentionPolicy = pgTable("retention_policies", {
id: uuid("id").primaryKey().defaultRandom(),
databaseId: uuid("database_id").notNull().references(() => database.id, {onDelete: "cascade"}),
type: retentionPolicyType("type").notNull(),
count: integer("count").default(7), // for "count"
days: integer("days").default(30), // for "days"
gfsDaily: integer("gfs_daily").default(7),
gfsWeekly: integer("gfs_weekly").default(4),
gfsMonthly: integer("gfs_monthly").default(12),
gfsYearly: integer("gfs_yearly").default(3),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at"),
});
export const restoration = pgTable("restorations", {
id: uuid("id").primaryKey().defaultRandom(),
status: statusEnum("status").default("waiting").notNull(),
@@ -53,6 +71,7 @@ export const restoration = pgTable("restorations", {
});
export const databaseRelations = relations(database, ({one, many}) => ({
retentionPolicy: one(retentionPolicy),
agent: one(agent, {fields: [database.agentId], references: [agent.id]}),
project: one(project, {fields: [database.projectId], references: [project.id]}),
backups: many(backup),
@@ -78,10 +97,16 @@ export type Backup = z.infer<typeof backupSchema>;
export const restorationSchema = createSelectSchema(restoration);
export type Restoration = z.infer<typeof restorationSchema>;
export const retentionPolicySchema = createSelectSchema(retentionPolicy);
export type RetentionPolicy = z.infer<typeof retentionPolicySchema>;
export type DatabaseWith = Database & {
agent?: Agent | null;
project?: Project | null;
backups?: Backup[] | null;
restorations?: Restoration[] | null;
retentionPolicy?: RetentionPolicy | null;
};