mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 10:35:17 +00:00
fix: added new identifier field for non-uuid IDs
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TableName } from "../schemas";
|
||||
@@ -6,31 +5,10 @@ import { TableName } from "../schemas";
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
if (await knex.schema.hasTable(TableName.SecretSharing)) {
|
||||
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
|
||||
// Add a new column
|
||||
t.string("new_id", 36).nullable();
|
||||
});
|
||||
t.string("identifier", 36).nullable();
|
||||
|
||||
// Copy data from old column to new column
|
||||
await knex(TableName.SecretSharing).update({
|
||||
// @ts-ignore
|
||||
new_id: knex.raw("id::text")
|
||||
});
|
||||
|
||||
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
|
||||
// Make the new column not nullable
|
||||
t.string("new_id", 36).notNullable().alter();
|
||||
|
||||
// Drop the old primary key
|
||||
t.dropPrimary();
|
||||
|
||||
// Drop the old id column
|
||||
t.dropColumn("id");
|
||||
|
||||
// Rename the new column to 'id'
|
||||
t.renameColumn("new_id", "id");
|
||||
|
||||
// Set the new column as primary key
|
||||
t.primary(["id"]);
|
||||
t.unique("identifier");
|
||||
t.index("identifier");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -38,34 +16,8 @@ export async function up(knex: Knex): Promise<void> {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
if (await knex.schema.hasTable(TableName.SecretSharing)) {
|
||||
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
|
||||
// Add a new UUID column
|
||||
t.uuid("new_id").nullable();
|
||||
});
|
||||
|
||||
// Copy data from string id to UUID, ensuring valid UUID format
|
||||
await knex(TableName.SecretSharing).update({
|
||||
// @ts-ignore
|
||||
new_id: knex.raw("id::uuid")
|
||||
});
|
||||
|
||||
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
|
||||
// Make the new column not nullable
|
||||
t.uuid("new_id").notNullable().alter();
|
||||
|
||||
// Drop the old primary key
|
||||
t.dropPrimary();
|
||||
|
||||
// Drop the old id column
|
||||
t.dropColumn("id");
|
||||
|
||||
// Rename the new column to 'id'
|
||||
t.renameColumn("new_id", "id");
|
||||
|
||||
// Set the new column as primary key
|
||||
t.primary(["id"]);
|
||||
|
||||
// Set the id column to use a UUID default
|
||||
t.uuid("id").defaultTo(knex.raw("gen_random_uuid()")).notNullable().alter();
|
||||
// If rolled back, all secrets created with this new structure will stop working.
|
||||
t.dropColumn("identifier");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { zodBuffer } from "@app/lib/zod";
|
||||
import { TImmutableDBKeys } from "./models";
|
||||
|
||||
export const SecretSharingSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
encryptedValue: z.string().nullable().optional(),
|
||||
iv: z.string().nullable().optional(),
|
||||
tag: z.string().nullable().optional(),
|
||||
@@ -25,7 +26,7 @@ export const SecretSharingSchema = z.object({
|
||||
lastViewedAt: z.date().nullable().optional(),
|
||||
password: z.string().nullable().optional(),
|
||||
encryptedSecret: zodBuffer.nullable().optional(),
|
||||
id: z.string()
|
||||
identifier: z.string().nullable().optional()
|
||||
});
|
||||
|
||||
export type TSecretSharing = z.infer<typeof SecretSharingSchema>;
|
||||
|
||||
Reference in New Issue
Block a user