feat: updated backend to new data structure for org

This commit is contained in:
=
2025-02-26 20:45:37 +05:30
parent 7905017121
commit 8520029958
17 changed files with 310 additions and 439 deletions
@@ -4,47 +4,43 @@ import { TableName } from "../schemas";
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";
export async function up(knex: Knex): Promise<void> {
if (!(await knex.schema.hasTable(TableName.GatewayInstanceConfig))) {
await knex.schema.createTable(TableName.GatewayInstanceConfig, (t) => {
if (!(await knex.schema.hasTable(TableName.OrgGatewayConfig))) {
await knex.schema.createTable(TableName.OrgGatewayConfig, (t) => {
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
t.string("caKeyAlgorithm").notNullable();
t.boolean("isDisabled").defaultTo(false);
t.string("rootCaKeyAlgorithm").notNullable();
t.string("infisicalClientCaSerialNumber").notNullable();
t.datetime("infisicalClientCaIssuedAt").notNullable();
t.datetime("infisicalClientCaExpiration").notNullable();
t.binary("encryptedInfisicalClientCaCertificate").notNullable();
t.binary("encryptedInfisicalClientCaPrivateKey").notNullable();
t.datetime("rootCaIssuedAt").notNullable();
t.datetime("rootCaExpiration").notNullable();
t.string("rootCaSerialNumber").notNullable();
t.binary("encryptedRootCaCertificate").notNullable();
t.binary("encryptedRootCaPrivateKey").notNullable();
t.string("infisicalClientCertSerialNumber").notNullable();
t.string("infisicalClientCertKeyAlgorithm").notNullable();
t.datetime("infisicalClientCertIssuedAt").notNullable();
t.datetime("infisicalClientCertExpiration").notNullable();
t.binary("encryptedInfisicalClientCertificate").notNullable();
t.binary("encryptedInfisicalClientPrivateKey").notNullable();
t.timestamps(true, true, true);
});
t.datetime("clientCaIssuedAt").notNullable();
t.datetime("clientCaExpiration").notNullable();
t.string("clientCaSerialNumber");
t.binary("encryptedClientCaCertificate").notNullable();
t.binary("encryptedClientCaPrivateKey").notNullable();
await createOnUpdateTrigger(knex, TableName.GatewayInstanceConfig);
}
t.string("clientCertSerialNumber").notNullable();
t.string("clientCertKeyAlgorithm").notNullable();
t.datetime("clientCertIssuedAt").notNullable();
t.datetime("clientCertExpiration").notNullable();
t.binary("encryptedClientCertificate").notNullable();
t.binary("encryptedClientPrivateKey").notNullable();
if (!(await knex.schema.hasTable(TableName.OrgGatewayRootCa))) {
await knex.schema.createTable(TableName.OrgGatewayRootCa, (t) => {
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
t.string("caKeyAlgorithm").notNullable();
t.string("caSerialNumber").notNullable();
t.datetime("caIssuedAt").notNullable();
t.datetime("caExpiration").notNullable();
t.binary("encryptedCaCertificate").notNullable();
t.binary("encryptedCaPrivateKey").notNullable();
t.datetime("gatewayCaIssuedAt").notNullable();
t.datetime("gatewayCaExpiration").notNullable();
t.string("gatewayCaSerialNumber").notNullable();
t.binary("encryptedGatewayCaCertificate").notNullable();
t.binary("encryptedGatewayCaPrivateKey").notNullable();
t.uuid("orgId").notNullable();
t.foreign("orgId").references("id").inTable(TableName.Organization).onDelete("CASCADE");
t.unique("orgId");
t.timestamps(true, true, true);
});
await createOnUpdateTrigger(knex, TableName.OrgGatewayRootCa);
await createOnUpdateTrigger(knex, TableName.OrgGatewayConfig);
}
if (!(await knex.schema.hasTable(TableName.Gateway))) {
@@ -60,7 +56,7 @@ export async function up(knex: Knex): Promise<void> {
t.binary("relayAddress").notNullable();
t.uuid("orgGatewayRootCaId").notNullable();
t.foreign("orgGatewayRootCaId").references("id").inTable(TableName.OrgGatewayRootCa).onDelete("CASCADE");
t.foreign("orgGatewayRootCaId").references("id").inTable(TableName.OrgGatewayConfig).onDelete("CASCADE");
t.uuid("identityId").notNullable();
t.foreign("identityId").references("id").inTable(TableName.Identity).onDelete("CASCADE");
@@ -73,12 +69,9 @@ export async function up(knex: Knex): Promise<void> {
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists(TableName.GatewayInstanceConfig);
await dropOnUpdateTrigger(knex, TableName.GatewayInstanceConfig);
await knex.schema.dropTableIfExists(TableName.Gateway);
await dropOnUpdateTrigger(knex, TableName.Gateway);
await knex.schema.dropTableIfExists(TableName.OrgGatewayRootCa);
await dropOnUpdateTrigger(knex, TableName.OrgGatewayRootCa);
await knex.schema.dropTableIfExists(TableName.OrgGatewayConfig);
await dropOnUpdateTrigger(knex, TableName.OrgGatewayConfig);
}
@@ -1,33 +0,0 @@
// Code generated by automation script, DO NOT EDIT.
// Automated by pulling database and generating zod schema
// To update. Just run npm run generate:schema
// Written by akhilmhdh.
import { z } from "zod";
import { zodBuffer } from "@app/lib/zod";
import { TImmutableDBKeys } from "./models";
export const GatewayInstanceConfigSchema = z.object({
id: z.string().uuid(),
caKeyAlgorithm: z.string(),
isDisabled: z.boolean().default(false).nullable().optional(),
infisicalClientCaSerialNumber: z.string(),
infisicalClientCaIssuedAt: z.date(),
infisicalClientCaExpiration: z.date(),
encryptedInfisicalClientCaCertificate: zodBuffer,
encryptedInfisicalClientCaPrivateKey: zodBuffer,
infisicalClientCertSerialNumber: z.string(),
infisicalClientCertKeyAlgorithm: z.string(),
infisicalClientCertIssuedAt: z.date(),
infisicalClientCertExpiration: z.date(),
encryptedInfisicalClientCertificate: zodBuffer,
encryptedInfisicalClientPrivateKey: zodBuffer,
createdAt: z.date(),
updatedAt: z.date()
});
export type TGatewayInstanceConfig = z.infer<typeof GatewayInstanceConfigSchema>;
export type TGatewayInstanceConfigInsert = Omit<z.input<typeof GatewayInstanceConfigSchema>, TImmutableDBKeys>;
export type TGatewayInstanceConfigUpdate = Partial<Omit<z.input<typeof GatewayInstanceConfigSchema>, TImmutableDBKeys>>;
+1 -2
View File
@@ -20,7 +20,6 @@ export * from "./certificates";
export * from "./dynamic-secret-leases";
export * from "./dynamic-secrets";
export * from "./external-kms";
export * from "./gateway-instance-config";
export * from "./gateways";
export * from "./git-app-install-sessions";
export * from "./git-app-org";
@@ -59,7 +58,7 @@ export * from "./ldap-group-maps";
export * from "./models";
export * from "./oidc-configs";
export * from "./org-bots";
export * from "./org-gateway-root-ca";
export * from "./org-gateway-config";
export * from "./org-memberships";
export * from "./org-roles";
export * from "./organizations";
+1 -2
View File
@@ -114,8 +114,7 @@ export enum TableName {
SnapshotSecretV2 = "secret_snapshot_secrets_v2",
ProjectSplitBackfillIds = "project_split_backfill_ids",
// Gateway
GatewayInstanceConfig = "gateway_instance_config",
OrgGatewayRootCa = "org_gateway_root_ca",
OrgGatewayConfig = "org_gateway_config",
Gateway = "gateways",
// junction tables with tags
SecretV2JnTag = "secret_v2_tag_junction",
@@ -0,0 +1,43 @@
// Code generated by automation script, DO NOT EDIT.
// Automated by pulling database and generating zod schema
// To update. Just run npm run generate:schema
// Written by akhilmhdh.
import { z } from "zod";
import { zodBuffer } from "@app/lib/zod";
import { TImmutableDBKeys } from "./models";
export const OrgGatewayConfigSchema = z.object({
id: z.string().uuid(),
rootCaKeyAlgorithm: z.string(),
rootCaIssuedAt: z.date(),
rootCaExpiration: z.date(),
rootCaSerialNumber: z.string(),
encryptedRootCaCertificate: zodBuffer,
encryptedRootCaPrivateKey: zodBuffer,
clientCaIssuedAt: z.date(),
clientCaExpiration: z.date(),
clientCaSerialNumber: z.string().nullable().optional(),
encryptedClientCaCertificate: zodBuffer,
encryptedClientCaPrivateKey: zodBuffer,
clientCertSerialNumber: z.string(),
clientCertKeyAlgorithm: z.string(),
clientCertIssuedAt: z.date(),
clientCertExpiration: z.date(),
encryptedClientCertificate: zodBuffer,
encryptedClientPrivateKey: zodBuffer,
gatewayCaIssuedAt: z.date(),
gatewayCaExpiration: z.date(),
gatewayCaSerialNumber: z.string(),
encryptedGatewayCaCertificate: zodBuffer,
encryptedGatewayCaPrivateKey: zodBuffer,
orgId: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date()
});
export type TOrgGatewayConfig = z.infer<typeof OrgGatewayConfigSchema>;
export type TOrgGatewayConfigInsert = Omit<z.input<typeof OrgGatewayConfigSchema>, TImmutableDBKeys>;
export type TOrgGatewayConfigUpdate = Partial<Omit<z.input<typeof OrgGatewayConfigSchema>, TImmutableDBKeys>>;
@@ -1,27 +0,0 @@
// Code generated by automation script, DO NOT EDIT.
// Automated by pulling database and generating zod schema
// To update. Just run npm run generate:schema
// Written by akhilmhdh.
import { z } from "zod";
import { zodBuffer } from "@app/lib/zod";
import { TImmutableDBKeys } from "./models";
export const OrgGatewayRootCaSchema = z.object({
id: z.string().uuid(),
caKeyAlgorithm: z.string(),
caSerialNumber: z.string(),
caIssuedAt: z.date(),
caExpiration: z.date(),
encryptedCaCertificate: zodBuffer,
encryptedCaPrivateKey: zodBuffer,
orgId: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date()
});
export type TOrgGatewayRootCa = z.infer<typeof OrgGatewayRootCaSchema>;
export type TOrgGatewayRootCaInsert = Omit<z.input<typeof OrgGatewayRootCaSchema>, TImmutableDBKeys>;
export type TOrgGatewayRootCaUpdate = Partial<Omit<z.input<typeof OrgGatewayRootCaSchema>, TImmutableDBKeys>>;