@cfxlabsinc/b2b-services
    Preparing search index...

    Variable emailTemplateTableConst

    emailTemplateTable: Omit<
        PgTableWithColumns<
            {
                columns: {
                    createdAt: PgBuildColumn<
                        "email_template",
                        SetHasDefault<
                            SetNotNull<
                                PgCustomColumnBuilder<
                                    { data: Instant; dataType: "custom"; driverParam: string },
                                >,
                            >,
                        >,
                        {
                            data: Instant;
                            dataType: "custom";
                            driverParam: string;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: true;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: true;
                            tableName: "email_template";
                        },
                    >;
                    deletedAt: PgBuildColumn<
                        "email_template",
                        PgCustomColumnBuilder<
                            { data: Instant; dataType: "custom"; driverParam: string },
                        >,
                        {
                            data: Instant;
                            dataType: "custom";
                            driverParam: string;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: false;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: false;
                            tableName: "email_template";
                        },
                    >;
                    draftVersionId: PgBuildColumn<
                        "email_template",
                        PgIntegerBuilder,
                        {
                            data: number;
                            dataType: "number int32";
                            driverParam: string
                            | number;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: false;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: false;
                            tableName: "email_template";
                        },
                    >;
                    externalId: PgBuildColumn<
                        "email_template",
                        SetHasRuntimeDefault<SetNotNull<PgTextBuilder<[string, ...string[]]>>>,
                        {
                            data: string;
                            dataType: "string";
                            driverParam: string;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: true;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: true;
                            tableName: "email_template";
                        },
                    >;
                    id: PgBuildColumn<
                        "email_template",
                        HasIdentity<SetIsPrimaryKey<PgIntegerBuilder>, "byDefault">,
                        {
                            data: number;
                            dataType: "number int32";
                            driverParam: string | number;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: true;
                            hasRuntimeDefault: false;
                            identity: "byDefault";
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: true;
                            tableName: "email_template";
                        },
                    >;
                    liveVersionId: PgBuildColumn<
                        "email_template",
                        PgIntegerBuilder,
                        {
                            data: number;
                            dataType: "number int32";
                            driverParam: string
                            | number;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: false;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: false;
                            tableName: "email_template";
                        },
                    >;
                    statusVariant: PgBuildColumn<
                        "email_template",
                        Set$Type<
                            SetNotNull<PgTextBuilder<[string, ...string[]]>>,

                                | "PENDING_VERIFICATION"
                                | "ACTIVE"
                                | "REVIEW"
                                | "DISABLED"
                                | "BLOCKED"
                                | "DELETED"
                                | "PENDING"
                                | "DEPOSITED"
                                | "CANCELLED"
                                | "COMPLETED"
                                | "RETURNED"
                                | "SUCCEEDED"
                                | "DECLINED"
                                | "AUTHORIZED"
                                | "*",
                        >,
                        {
                            data: | "PENDING_VERIFICATION"
                            | "ACTIVE"
                            | "REVIEW"
                            | "DISABLED"
                            | "BLOCKED"
                            | "DELETED"
                            | "PENDING"
                            | "DEPOSITED"
                            | "CANCELLED"
                            | "COMPLETED"
                            | "RETURNED"
                            | "SUCCEEDED"
                            | "DECLINED"
                            | "AUTHORIZED"
                            | "*";
                            dataType: "string";
                            driverParam: string;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: false;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: true;
                            tableName: "email_template";
                        },
                    >;
                    templateKey: PgBuildColumn<
                        "email_template",
                        Set$Type<
                            SetNotNull<PgTextBuilder<[string, ...string[]]>>,

                                | "IDENTITY"
                                | "ORGANIZATION"
                                | "LEDGER_ACCOUNT"
                                | "PAYMENT_INSTRUMENT"
                                | "DEPOSIT"
                                | "WITHDRAW"
                                | "TRANSFER"
                                | "CARD_TRANSACTION",
                        >,
                        {
                            data: | "IDENTITY"
                            | "ORGANIZATION"
                            | "LEDGER_ACCOUNT"
                            | "PAYMENT_INSTRUMENT"
                            | "DEPOSIT"
                            | "WITHDRAW"
                            | "TRANSFER"
                            | "CARD_TRANSACTION";
                            dataType: "string";
                            driverParam: string;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: false;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: true;
                            tableName: "email_template";
                        },
                    >;
                    updatedAt: PgBuildColumn<
                        "email_template",
                        SetHasDefault<
                            SetHasDefault<
                                SetNotNull<
                                    PgCustomColumnBuilder<
                                        { data: Instant; dataType: "custom"; driverParam: string },
                                    >,
                                >,
                            >,
                        >,
                        {
                            data: Instant;
                            dataType: "custom";
                            driverParam: string;
                            enumValues: undefined;
                            generated: undefined;
                            hasDefault: true;
                            hasRuntimeDefault: false;
                            identity: undefined;
                            isAutoincrement: false;
                            isPrimaryKey: false;
                            name: string;
                            notNull: true;
                            tableName: "email_template";
                        },
                    >;
                };
                dialect: "pg";
                name: "email_template";
                schema: "b2b";
            },
        >,
        "enableRLS",
    > = ...

    One row per (templateKey, statusVariant) variant of a transactional email — 26 today. Rows are seeded by migration from the code registry (@cfxlabsinc/notification-services/email-templates); there is no create method, because an operator may only author copy for a variant the payload union declares. Adding one is a registry change plus a migration, and packages/notification-services/test/emailTemplateSchema.test.ts fails if the two ever disagree.

    Follows the product_route / product_fee_rule identity+version shape, with three deliberate differences (RFC §4.2):

    • Two pointers, not one. Those tables carry a single currentVersionId because an edit is immediately live. Email copy is reviewed before it sends, so a save moves draftVersionId and only activation moves liveVersionId.
    • No deferred FK. Theirs is DEFERRABLE INITIALLY DEFERRED because currentVersionId is NOT NULL while the identity row is inserted before its first version exists. Both of ours are nullable and variants seed with no versions at all, so there is no cycle to defer.
    • A human-facing version counter on the version table, because the editor has to say "live v3, draft v7".

    Mutable on liveVersionId, draftVersionId and deletedAt only.