src/database/migrations/1774000000000-AddRootExternalKeyIdToKeyChain.ts

Description

Add rootExternalKeyId to key_chain.

This stores the external KMS key identifier for the root CA key in internal-chain key chains, so later rotations can reference the exact root key in external KMS backends without relying on fallback heuristics.

Implements

MigrationInterface

Relationships

Used by

No results matching.

Depends on

  • MigrationInterface

Index

Properties
Methods

Properties

name
Type : string
Default value : "AddRootExternalKeyIdToKeyChain1774000000000"

Methods

Async down
down(queryRunner: QueryRunner)
Parameters :
Name Type Optional
queryRunner QueryRunner No
Returns : Promise<void>
Async up
up(queryRunner: QueryRunner)
Parameters :
Name Type Optional
queryRunner QueryRunner No
Returns : Promise<void>
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";

/**
 * Add rootExternalKeyId to key_chain.
 *
 * This stores the external KMS key identifier for the root CA key in
 * internal-chain key chains, so later rotations can reference the exact
 * root key in external KMS backends without relying on fallback heuristics.
 */
export class AddRootExternalKeyIdToKeyChain1774000000000
    implements MigrationInterface
{
    name = "AddRootExternalKeyIdToKeyChain1774000000000";

    async up(queryRunner: QueryRunner): Promise<void> {
        const table = await queryRunner.getTable("key_chain");
        if (!table) return;

        const hasColumn = table.columns.some(
            (col) => col.name === "rootExternalKeyId",
        );
        if (hasColumn) {
            return;
        }

        await queryRunner.addColumn(
            "key_chain",
            new TableColumn({
                name: "rootExternalKeyId",
                type: "varchar",
                isNullable: true,
            }),
        );
    }

    async down(queryRunner: QueryRunner): Promise<void> {
        const table = await queryRunner.getTable("key_chain");
        if (!table) return;

        const hasColumn = table.columns.some(
            (col) => col.name === "rootExternalKeyId",
        );
        if (!hasColumn) {
            return;
        }

        await queryRunner.dropColumn("key_chain", "rootExternalKeyId");
    }
}

results matching ""

    No results matching ""