mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 14:27:23 +00:00
requested changes
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import { Knex } from "knex";
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
// 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"]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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"]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ 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 +24,8 @@ export const SecretSharingSchema = z.object({
|
||||
name: z.string().nullable().optional(),
|
||||
lastViewedAt: z.date().nullable().optional(),
|
||||
password: z.string().nullable().optional(),
|
||||
encryptedSecret: zodBuffer.nullable().optional()
|
||||
encryptedSecret: zodBuffer.nullable().optional(),
|
||||
id: z.string()
|
||||
});
|
||||
|
||||
export type TSecretSharing = z.infer<typeof SecretSharingSchema>;
|
||||
|
||||
Reference in New Issue
Block a user