Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: added missing partition creation step

=b23402fc15e9
diff --git a/backend/src/db/migrations/20260105152608_scim-events.ts b/backend/src/db/migrations/20260105152608_scim-events.ts
index 8d59c23371..e9ce5a58db 100644
--- a/backend/src/db/migrations/20260105152608_scim-events.ts
+++ b/backend/src/db/migrations/20260105152608_scim-events.ts
@@ -3,6 +3,25 @@ import { Knex } from "knex";
import { TableName } from "../schemas";
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";
+const formatPartitionDate = (date: Date) => {
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, "0");
+ const day = String(date.getDate()).padStart(2, "0");
+
+ return `${year}-${month}-${day}`;
+};
+
+const createScimEventsPartition = async (knex: Knex, startDate: Date, endDate: Date) => {
+ const startDateStr = formatPartitionDate(startDate);
+ const endDateStr = formatPartitionDate(endDate);
+
+ const partitionName = `${TableName.ScimEvents}_${startDateStr.replace(/-/g, "")}_${endDateStr.replace(/-/g, "")}`;
+
+ await knex.schema.raw(
+ `CREATE TABLE ${partitionName} PARTITION OF ${TableName.ScimEvents} FOR VALUES FROM ('${startDateStr}') TO ('${endDateStr}')`
+ );
+};
+
export async function up(knex: Knex): Promise<void> {
if (!(await knex.schema.hasTable(TableName.ScimEvents))) {
const createTableSql = knex.schema
@@ -23,6 +42,25 @@ export async function up(knex: Knex): Promise<void> {
await knex.schema.raw(`CREATE TABLE ${TableName.ScimEvents}_default PARTITION OF ${TableName.ScimEvents} DEFAULT`);
+ const nextDate = new Date();
+ nextDate.setDate(nextDate.getDate() + 1);
+
+ await createScimEventsPartition(knex, nextDate, new Date(nextDate.getFullYear(), nextDate.getMonth() + 1, 1));
+
+ const partitionMonths = 20 * 12;
+ const partitionPromises: Promise<void>[] = [];
+ for (let x = 1; x <= partitionMonths; x += 1) {
+ partitionPromises.push(
+ createScimEventsPartition(
+ knex,
+ new Date(nextDate.getFullYear(), nextDate.getMonth() + x, 1),
+ new Date(nextDate.getFullYear(), nextDate.getMonth() + (x + 1), 1)
+ )
+ );
+ }
+
+ await Promise.all(partitionPromises);
+
await knex.schema.alterTable(TableName.ScimEvents, (t) => {
t.foreign("orgId").references("id").inTable(TableName.Organization).onDelete("CASCADE");