mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 22:20:36 +00:00
62 lines
2.6 KiB
TypeScript
62 lines
2.6 KiB
TypeScript
import { Knex } from "knex";
|
|
|
|
import { TableName } from "../schemas";
|
|
|
|
export async function up(knex: Knex): Promise<void> {
|
|
const doesPasswordFieldExist = await knex.schema.hasColumn(TableName.UserEncryptionKey, "hashedPassword");
|
|
const doesPrivateKeyFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKey"
|
|
);
|
|
const doesPrivateKeyIVFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKeyIV"
|
|
);
|
|
const doesPrivateKeyTagFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKeyTag"
|
|
);
|
|
const doesPrivateKeyEncodingFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKeyEncoding"
|
|
);
|
|
if (await knex.schema.hasTable(TableName.UserEncryptionKey)) {
|
|
await knex.schema.alterTable(TableName.UserEncryptionKey, (t) => {
|
|
if (!doesPasswordFieldExist) t.string("hashedPassword");
|
|
if (!doesPrivateKeyFieldExist) t.text("serverEncryptedPrivateKey");
|
|
if (!doesPrivateKeyIVFieldExist) t.text("serverEncryptedPrivateKeyIV");
|
|
if (!doesPrivateKeyTagFieldExist) t.text("serverEncryptedPrivateKeyTag");
|
|
if (!doesPrivateKeyEncodingFieldExist) t.text("serverEncryptedPrivateKeyEncoding");
|
|
});
|
|
}
|
|
}
|
|
|
|
export async function down(knex: Knex): Promise<void> {
|
|
const doesPasswordFieldExist = await knex.schema.hasColumn(TableName.UserEncryptionKey, "hashedPassword");
|
|
const doesPrivateKeyFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKey"
|
|
);
|
|
const doesPrivateKeyIVFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKeyIV"
|
|
);
|
|
const doesPrivateKeyTagFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKeyTag"
|
|
);
|
|
const doesPrivateKeyEncodingFieldExist = await knex.schema.hasColumn(
|
|
TableName.UserEncryptionKey,
|
|
"serverEncryptedPrivateKeyEncoding"
|
|
);
|
|
if (await knex.schema.hasTable(TableName.UserEncryptionKey)) {
|
|
await knex.schema.alterTable(TableName.UserEncryptionKey, (t) => {
|
|
if (doesPasswordFieldExist) t.dropColumn("hashedPassword");
|
|
if (doesPrivateKeyFieldExist) t.dropColumn("serverEncryptedPrivateKey");
|
|
if (doesPrivateKeyIVFieldExist) t.dropColumn("serverEncryptedPrivateKeyIV");
|
|
if (doesPrivateKeyTagFieldExist) t.dropColumn("serverEncryptedPrivateKeyTag");
|
|
if (doesPrivateKeyEncodingFieldExist) t.dropColumn("serverEncryptedPrivateKeyEncoding");
|
|
});
|
|
}
|
|
}
|