From 329faa8913a77ac312dab60f527523568a7c7bca Mon Sep 17 00:00:00 2001 From: Charles Gauthereau Date: Wed, 25 Nov 2026 20:59:30 +0100 Subject: [PATCH 1/6] feat: add encryption flag to organization, project and database --- .../migrations/0101_granular_encryption.sql | 3 + src/db/migrations/meta/0101_snapshot.json | 3548 +++++++++++++++++ src/db/migrations/meta/_journal.json | 7 + src/db/schema/03_organization.ts | 3 +- src/db/schema/06_project.ts | 1 + src/db/schema/07_database.ts | 3 + .../database/utils/policy-resolution.ts | 9 + 7 files changed, 3573 insertions(+), 1 deletion(-) create mode 100644 src/db/migrations/0101_granular_encryption.sql create mode 100644 src/db/migrations/meta/0101_snapshot.json diff --git a/src/db/migrations/0101_granular_encryption.sql b/src/db/migrations/0101_granular_encryption.sql new file mode 100644 index 000000000..232884fc5 --- /dev/null +++ b/src/db/migrations/0101_granular_encryption.sql @@ -0,0 +1,3 @@ +ALTER TABLE "organization" ADD COLUMN "encryption" boolean DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE "projects" ADD COLUMN "encryption" boolean DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE "databases" ADD COLUMN "encryption" boolean DEFAULT false NOT NULL; \ No newline at end of file diff --git a/src/db/migrations/meta/0101_snapshot.json b/src/db/migrations/meta/0101_snapshot.json new file mode 100644 index 000000000..beaa74cc5 --- /dev/null +++ b/src/db/migrations/meta/0101_snapshot.json @@ -0,0 +1,3548 @@ +{ + "id": "1321efbc-7b0e-4b26-9def-c965a4632468", + "prevId": "6653ee25-613e-4711-9488-e1ca76cb6098", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.settings": { + "name": "settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "smtp_password": { + "name": "smtp_password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "smtp_from": { + "name": "smtp_from", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "smtp_host": { + "name": "smtp_host", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "smtp_port": { + "name": "smtp_port", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "smtp_user": { + "name": "smtp_user", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "smtp_secure": { + "name": "smtp_secure", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "default_notification_channel_id": { + "name": "default_notification_channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "default_storage_channel_id": { + "name": "default_storage_channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "encryption": { + "name": "encryption", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "onboarding": { + "name": "onboarding", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "settings_default_notification_channel_id_notification_channel_id_fk": { + "name": "settings_default_notification_channel_id_notification_channel_id_fk", + "tableFrom": "settings", + "tableTo": "notification_channel", + "columnsFrom": [ + "default_notification_channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "settings_default_storage_channel_id_storage_channel_id_fk": { + "name": "settings_default_storage_channel_id_storage_channel_id_fk", + "tableFrom": "settings", + "tableTo": "storage_channel", + "columnsFrom": [ + "default_storage_channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "settings_name_unique": { + "name": "settings_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issuer": { + "name": "issuer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey": { + "name": "passkey", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "publicKey": { + "name": "publicKey", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "credentialID": { + "name": "credentialID", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "deviceType": { + "name": "deviceType", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backedUp": { + "name": "backedUp", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "aaguid": { + "name": "aaguid", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "passkey_user_id_user_id_fk": { + "name": "passkey_user_id_user_id_fk", + "tableFrom": "passkey", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "impersonated_by": { + "name": "impersonated_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sso_provider": { + "name": "sso_provider", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "issuer": { + "name": "issuer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "oidc_config": { + "name": "oidc_config", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "saml_config": { + "name": "saml_config", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "sso_provider_user_id_user_id_fk": { + "name": "sso_provider_user_id_user_id_fk", + "tableFrom": "sso_provider", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "sso_provider_provider_id_unique": { + "name": "sso_provider_provider_id_unique", + "nullsNotDistinct": false, + "columns": [ + "provider_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.two_factor": { + "name": "two_factor", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backup_codes": { + "name": "backup_codes", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "failed_verification_count": { + "name": "failed_verification_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "two_factor_user_id_user_id_fk": { + "name": "two_factor_user_id_user_id_fk", + "tableFrom": "two_factor", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "theme": { + "name": "theme", + "type": "user_themes", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'light'" + }, + "banned": { + "name": "banned", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "ban_reason": { + "name": "ban_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ban_expires": { + "name": "ban_expires", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "lastConnectedAt": { + "name": "lastConnectedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "lastChangedPasswordAt": { + "name": "lastChangedPasswordAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "two_factor_enabled": { + "name": "two_factor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization": { + "name": "organization", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "logo": { + "name": "logo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encryption": { + "name": "encryption", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "organization_slug_unique": { + "name": "organization_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.member": { + "name": "member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "member_organization_id_organization_id_fk": { + "name": "member_organization_id_organization_id_fk", + "tableFrom": "member", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "member_user_id_user_id_fk": { + "name": "member_user_id_user_id_fk", + "tableFrom": "member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.invitation": { + "name": "invitation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "inviter_id": { + "name": "inviter_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "invitation_organization_id_organization_id_fk": { + "name": "invitation_organization_id_organization_id_fk", + "tableFrom": "invitation", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "invitation_inviter_id_user_id_fk": { + "name": "invitation_inviter_id_user_id_fk", + "tableFrom": "invitation", + "tableTo": "user", + "columnsFrom": [ + "inviter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.projects": { + "name": "projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_archived": { + "name": "is_archived", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "backup_policy": { + "name": "backup_policy", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encryption": { + "name": "encryption", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "projects_organization_id_organization_id_fk": { + "name": "projects_organization_id_organization_id_fk", + "tableFrom": "projects", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "projects_slug_unique": { + "name": "projects_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.backups": { + "name": "backups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "status": { + "name": "status", + "type": "status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'waiting'" + }, + "file": { + "name": "file", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "database_id": { + "name": "database_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "imported": { + "name": "imported", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "migrated": { + "name": "migrated", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "parent_backup_id": { + "name": "parent_backup_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "full_requested": { + "name": "full_requested", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_backups_parent": { + "name": "idx_backups_parent", + "columns": [ + { + "expression": "parent_backup_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_backups_status_core": { + "name": "idx_backups_status_core", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_backups_evolution": { + "name": "idx_backups_evolution", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "status = 'success' AND deleted_at IS NULL AND file_size IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "backups_database_id_databases_id_fk": { + "name": "backups_database_id_databases_id_fk", + "tableFrom": "backups", + "tableTo": "databases", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "backups_parent_backup_id_backups_id_fk": { + "name": "backups_parent_backup_id_backups_id_fk", + "tableFrom": "backups", + "tableTo": "backups", + "columnsFrom": [ + "parent_backup_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.backup_manifests": { + "name": "backup_manifests", + "schema": "", + "columns": { + "backup_id": { + "name": "backup_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "manifest": { + "name": "manifest", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "backup_manifests_backup_id_backups_id_fk": { + "name": "backup_manifests_backup_id_backups_id_fk", + "tableFrom": "backup_manifests", + "tableTo": "backups", + "columnsFrom": [ + "backup_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.databases": { + "name": "databases", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "agent_database_id": { + "name": "agent_database_id", + "type": "uuid", + "primaryKey": false, + "notNull": false, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dbms": { + "name": "dbms", + "type": "dbms_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "backup_policy": { + "name": "backup_policy", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encryption": { + "name": "encryption", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_waiting_for_backup": { + "name": "is_waiting_for_backup", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "backup_to_restore": { + "name": "backup_to_restore", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "backup_engine": { + "name": "backup_engine", + "type": "backup_engine", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'archive'" + }, + "method_conflict": { + "name": "method_conflict", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "full_backup_cron": { + "name": "full_backup_cron", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "health_error_count": { + "name": "health_error_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "agent_id": { + "name": "agent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_contact": { + "name": "last_contact", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_databases_availability": { + "name": "idx_databases_availability", + "columns": [ + { + "expression": "last_contact", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "deleted_at IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "databases_agent_id_agents_id_fk": { + "name": "databases_agent_id_agents_id_fk", + "tableFrom": "databases", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "databases_project_id_projects_id_fk": { + "name": "databases_project_id_projects_id_fk", + "tableFrom": "databases", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.restorations": { + "name": "restorations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "status": { + "name": "status", + "type": "status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'waiting'" + }, + "duration_ms": { + "name": "duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "backup_storage_id": { + "name": "backup_storage_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "backup_id": { + "name": "backup_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "database_id": { + "name": "database_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "restorations_backup_storage_id_backup_storage_id_fk": { + "name": "restorations_backup_storage_id_backup_storage_id_fk", + "tableFrom": "restorations", + "tableTo": "backup_storage", + "columnsFrom": [ + "backup_storage_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "restorations_backup_id_backups_id_fk": { + "name": "restorations_backup_id_backups_id_fk", + "tableFrom": "restorations", + "tableTo": "backups", + "columnsFrom": [ + "backup_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "restorations_database_id_databases_id_fk": { + "name": "restorations_database_id_databases_id_fk", + "tableFrom": "restorations", + "tableTo": "databases", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.retention_policies": { + "name": "retention_policies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "database_id": { + "name": "database_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "retention_policy_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "count": { + "name": "count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 7 + }, + "days": { + "name": "days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "gfs_hourly": { + "name": "gfs_hourly", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "gfs_daily": { + "name": "gfs_daily", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 7 + }, + "gfs_weekly": { + "name": "gfs_weekly", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 4 + }, + "gfs_monthly": { + "name": "gfs_monthly", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 12 + }, + "gfs_yearly": { + "name": "gfs_yearly", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "retention_policies_database_id_databases_id_fk": { + "name": "retention_policies_database_id_databases_id_fk", + "tableFrom": "retention_policies", + "tableTo": "databases", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "retention_policies_project_id_projects_id_fk": { + "name": "retention_policies_project_id_projects_id_fk", + "tableFrom": "retention_policies", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "retention_policy_owner_xor": { + "name": "retention_policy_owner_xor", + "value": "num_nonnulls(\"retention_policies\".\"database_id\", \"retention_policies\".\"project_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.agents": { + "name": "agents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "health_error_count": { + "name": "health_error_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "override_url": { + "name": "override_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_archived": { + "name": "is_archived", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "last_contact": { + "name": "last_contact", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_agents_availability": { + "name": "idx_agents_availability", + "columns": [ + { + "expression": "last_contact", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "is_archived = false AND deleted_at IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agents_organization_id_organization_id_fk": { + "name": "agents_organization_id_organization_id_fk", + "tableFrom": "agents", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agents_slug_unique": { + "name": "agents_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_agents": { + "name": "organization_agents", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "organization_agents_organization_id_organization_id_fk": { + "name": "organization_agents_organization_id_organization_id_fk", + "tableFrom": "organization_agents", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_agents_agent_id_agents_id_fk": { + "name": "organization_agents_agent_id_agents_id_fk", + "tableFrom": "organization_agents", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "organization_agents_organization_id_agent_id_unique": { + "name": "organization_agents_organization_id_agent_id_unique", + "nullsNotDistinct": false, + "columns": [ + "organization_id", + "agent_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notification_channel": { + "name": "notification_channel", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "provider": { + "name": "provider", + "type": "provider_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "notification_channel_organization_id_organization_id_fk": { + "name": "notification_channel_organization_id_organization_id_fk", + "tableFrom": "notification_channel", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_notification_channels": { + "name": "organization_notification_channels", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "notification_channel_id": { + "name": "notification_channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "organization_notification_channels_organization_id_organization_id_fk": { + "name": "organization_notification_channels_organization_id_organization_id_fk", + "tableFrom": "organization_notification_channels", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_notification_channels_notification_channel_id_notification_channel_id_fk": { + "name": "organization_notification_channels_notification_channel_id_notification_channel_id_fk", + "tableFrom": "organization_notification_channels", + "tableTo": "notification_channel", + "columnsFrom": [ + "notification_channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "organization_notification_channels_organization_id_notification_channel_id_unique": { + "name": "organization_notification_channels_organization_id_notification_channel_id_unique", + "nullsNotDistinct": false, + "columns": [ + "organization_id", + "notification_channel_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alert_policy": { + "name": "alert_policy", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "notification_channel_id": { + "name": "notification_channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "event_kind": { + "name": "event_kind", + "type": "event_kind[]", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "database_id": { + "name": "database_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "alert_policy_notification_channel_id_notification_channel_id_fk": { + "name": "alert_policy_notification_channel_id_notification_channel_id_fk", + "tableFrom": "alert_policy", + "tableTo": "notification_channel", + "columnsFrom": [ + "notification_channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "alert_policy_database_id_databases_id_fk": { + "name": "alert_policy_database_id_databases_id_fk", + "tableFrom": "alert_policy", + "tableTo": "databases", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "alert_policy_project_id_projects_id_fk": { + "name": "alert_policy_project_id_projects_id_fk", + "tableFrom": "alert_policy", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "alert_policy_owner_xor": { + "name": "alert_policy_owner_xor", + "value": "num_nonnulls(\"alert_policy\".\"database_id\", \"alert_policy\".\"project_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.notification_log": { + "name": "notification_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "channel_id": { + "name": "channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "policy_id": { + "name": "policy_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "event": { + "name": "event", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_name": { + "name": "provider_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "level", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_response": { + "name": "provider_response", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_notif_log_critical_24h": { + "name": "idx_notif_log_critical_24h", + "columns": [ + { + "expression": "sent_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "event IN ('error_backup', 'error_restore', 'error_health_agent', 'error_health_database')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_storage_channels": { + "name": "organization_storage_channels", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "storage_channel_id": { + "name": "storage_channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "organization_storage_channels_organization_id_organization_id_fk": { + "name": "organization_storage_channels_organization_id_organization_id_fk", + "tableFrom": "organization_storage_channels", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_storage_channels_storage_channel_id_storage_channel_id_fk": { + "name": "organization_storage_channels_storage_channel_id_storage_channel_id_fk", + "tableFrom": "organization_storage_channels", + "tableTo": "storage_channel", + "columnsFrom": [ + "storage_channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "organization_storage_channels_organization_id_storage_channel_id_unique": { + "name": "organization_storage_channels_organization_id_storage_channel_id_unique", + "nullsNotDistinct": false, + "columns": [ + "organization_id", + "storage_channel_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.storage_channel": { + "name": "storage_channel", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "provider_storage_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "storage_channel_organization_id_organization_id_fk": { + "name": "storage_channel_organization_id_organization_id_fk", + "tableFrom": "storage_channel", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.storage_policy": { + "name": "storage_policy", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "storage_channel_id": { + "name": "storage_channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "database_id": { + "name": "database_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "storage_policy_storage_channel_id_storage_channel_id_fk": { + "name": "storage_policy_storage_channel_id_storage_channel_id_fk", + "tableFrom": "storage_policy", + "tableTo": "storage_channel", + "columnsFrom": [ + "storage_channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "storage_policy_database_id_databases_id_fk": { + "name": "storage_policy_database_id_databases_id_fk", + "tableFrom": "storage_policy", + "tableTo": "databases", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "storage_policy_project_id_projects_id_fk": { + "name": "storage_policy_project_id_projects_id_fk", + "tableFrom": "storage_policy", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "storage_policy_owner_xor": { + "name": "storage_policy_owner_xor", + "value": "num_nonnulls(\"storage_policy\".\"database_id\", \"storage_policy\".\"project_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.backup_storage": { + "name": "backup_storage", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "backup_id": { + "name": "backup_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "storage_channel_id": { + "name": "storage_channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "backup_storage_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "checksum": { + "name": "checksum", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "engine": { + "name": "engine", + "type": "backup_engine", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'archive'" + }, + "stats": { + "name": "stats", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "presence": { + "name": "presence", + "type": "backup_presence", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_check_error": { + "name": "last_check_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_backup_storage_treemap": { + "name": "idx_backup_storage_treemap", + "columns": [ + { + "expression": "storage_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "status = 'success' AND size IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_backup_storage_presence_due": { + "name": "idx_backup_storage_presence_due", + "columns": [ + { + "expression": "presence", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "deleted_at IS NULL AND status = 'success'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "backup_storage_backup_id_backups_id_fk": { + "name": "backup_storage_backup_id_backups_id_fk", + "tableFrom": "backup_storage", + "tableTo": "backups", + "columnsFrom": [ + "backup_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "backup_storage_storage_channel_id_storage_channel_id_fk": { + "name": "backup_storage_storage_channel_id_storage_channel_id_fk", + "tableFrom": "backup_storage", + "tableTo": "storage_channel", + "columnsFrom": [ + "storage_channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.healthcheck_log": { + "name": "healthcheck_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "kind": { + "name": "kind", + "type": "healthcheck_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "healthcheck_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "object_id": { + "name": "object_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.apikey": { + "name": "apikey", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "config_id": { + "name": "config_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start": { + "name": "start", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "prefix": { + "name": "prefix", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "refill_interval": { + "name": "refill_interval", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "refill_amount": { + "name": "refill_amount", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "last_refill_at": { + "name": "last_refill_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "rate_limit_enabled": { + "name": "rate_limit_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "rate_limit_time_window": { + "name": "rate_limit_time_window", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rate_limit_max": { + "name": "rate_limit_max", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "request_count": { + "name": "request_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "remaining": { + "name": "remaining", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "last_request": { + "name": "last_request", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (6) with time zone", + "primaryKey": false, + "notNull": true + }, + "permissions": { + "name": "permissions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.job_log": { + "name": "job_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "backup_id": { + "name": "backup_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "restoration_id": { + "name": "restoration_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "logged_at": { + "name": "logged_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "entry_type": { + "name": "entry_type", + "type": "job_log_entry_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "job_log_level", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "command": { + "name": "command", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "output": { + "name": "output", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "exit_code": { + "name": "exit_code", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "job_log_backup_id_backups_id_fk": { + "name": "job_log_backup_id_backups_id_fk", + "tableFrom": "job_log", + "tableTo": "backups", + "columnsFrom": [ + "backup_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "job_log_restoration_id_restorations_id_fk": { + "name": "job_log_restoration_id_restorations_id_fk", + "tableFrom": "job_log", + "tableTo": "restorations", + "columnsFrom": [ + "restoration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.user_themes": { + "name": "user_themes", + "schema": "public", + "values": [ + "light", + "dark", + "system" + ] + }, + "public.retention_policy_type": { + "name": "retention_policy_type", + "schema": "public", + "values": [ + "count", + "days", + "gfs" + ] + }, + "public.provider_kind": { + "name": "provider_kind", + "schema": "public", + "values": [ + "slack", + "smtp", + "discord", + "telegram", + "gotify", + "ntfy", + "webhook", + "nextcloud", + "teams", + "pushover", + "apprise", + "healthchecks" + ] + }, + "public.event_kind": { + "name": "event_kind", + "schema": "public", + "values": [ + "error_backup", + "error_restore", + "success_restore", + "success_backup", + "weekly_report", + "error_health_agent", + "error_health_database", + "error_backup_missing", + "success_backup_recovered" + ] + }, + "public.level": { + "name": "level", + "schema": "public", + "values": [ + "critical", + "warning", + "info" + ] + }, + "public.provider_storage_kind": { + "name": "provider_storage_kind", + "schema": "public", + "values": [ + "local", + "s3", + "google-drive", + "google-cloud-storage", + "blob", + "rclone", + "sftp", + "webdav", + "ftp", + "smb" + ] + }, + "public.backup_presence": { + "name": "backup_presence", + "schema": "public", + "values": [ + "present", + "missing", + "unknown" + ] + }, + "public.backup_storage_status": { + "name": "backup_storage_status", + "schema": "public", + "values": [ + "pending", + "success", + "failed" + ] + }, + "public.healthcheck_status": { + "name": "healthcheck_status", + "schema": "public", + "values": [ + "success", + "failed" + ] + }, + "public.healthcheck_kind": { + "name": "healthcheck_kind", + "schema": "public", + "values": [ + "database", + "agent" + ] + }, + "public.job_log_entry_type": { + "name": "job_log_entry_type", + "schema": "public", + "values": [ + "log", + "command" + ] + }, + "public.job_log_level": { + "name": "job_log_level", + "schema": "public", + "values": [ + "debug", + "info", + "warn", + "error" + ] + }, + "public.backup_engine": { + "name": "backup_engine", + "schema": "public", + "values": [ + "archive", + "restic", + "sync", + "copy", + "physical" + ] + }, + "public.dbms_status": { + "name": "dbms_status", + "schema": "public", + "values": [ + "postgresql", + "postgresql-cluster", + "mysql", + "mariadb", + "mongodb", + "sqlite", + "redis", + "valkey", + "firebird", + "mssql", + "docker-volume", + "files" + ] + }, + "public.status": { + "name": "status", + "schema": "public", + "values": [ + "waiting", + "ongoing", + "failed", + "success" + ] + }, + "public.type_storage": { + "name": "type_storage", + "schema": "public", + "values": [ + "local", + "s3" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.mv_kpi_backup_counts": { + "columns": { + "available_count": { + "name": "available_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "total_done": { + "name": "total_done", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "possession_rate_pct": { + "name": "possession_rate_pct", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "singleton": { + "name": "singleton", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT\n COUNT(*) FILTER (WHERE status = 'success' AND deleted_at IS NULL) AS available_count,\n COUNT(*) FILTER (WHERE status IN ('success', 'failed')) AS total_done,\n ROUND(\n COUNT(*) FILTER (WHERE status = 'success' AND deleted_at IS NULL)::numeric\n / NULLIF(COUNT(*) FILTER (WHERE status IN ('success', 'failed')), 0) * 100, 1\n ) AS possession_rate_pct,\n 1 AS singleton\n FROM backups\n", + "name": "mv_kpi_backup_counts", + "schema": "public", + "isExisting": false, + "materialized": true + }, + "public.mv_kpi_dbms_treemap": { + "columns": { + "dbms": { + "name": "dbms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "total_bytes": { + "name": "total_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "database_count": { + "name": "database_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "backup_count": { + "name": "backup_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT\n db.dbms,\n SUM(b.file_size) AS total_bytes,\n COUNT(DISTINCT db.id) AS database_count,\n COUNT(b.id) AS backup_count\n FROM backups b\n JOIN databases db ON db.id = b.database_id\n WHERE b.status = 'success' AND b.deleted_at IS NULL AND b.file_size IS NOT NULL\n GROUP BY db.dbms\n ORDER BY total_bytes DESC\n", + "name": "mv_kpi_dbms_treemap", + "schema": "public", + "isExisting": false, + "materialized": true + }, + "public.mv_kpi_evolution_monthly": { + "columns": { + "period": { + "name": "period", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "total_bytes": { + "name": "total_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "success_count": { + "name": "success_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "failed_count": { + "name": "failed_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT\n DATE_TRUNC('day', created_at) AS period,\n COALESCE(\n SUM(file_size) FILTER (\n WHERE status = 'success' AND deleted_at IS NULL AND file_size IS NOT NULL\n ), 0\n ) AS total_bytes,\n COUNT(*) FILTER (WHERE status = 'success') AS success_count,\n COUNT(*) FILTER (WHERE status = 'failed') AS failed_count\n FROM backups\n WHERE status IN ('success', 'failed')\n GROUP BY DATE_TRUNC('day', created_at)\n ORDER BY period ASC\n", + "name": "mv_kpi_evolution_monthly", + "schema": "public", + "isExisting": false, + "materialized": true + }, + "public.mv_kpi_storage_treemap": { + "columns": { + "channel_id": { + "name": "channel_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "channel_name": { + "name": "channel_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "total_bytes": { + "name": "total_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "backup_count": { + "name": "backup_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT\n sc.id AS channel_id,\n sc.name AS channel_name,\n sc.provider,\n SUM(bs.size) AS total_bytes,\n COUNT(bs.id) AS backup_count\n FROM backup_storage bs\n JOIN storage_channel sc ON sc.id = bs.storage_channel_id\n JOIN backups b ON b.id = bs.backup_id\n WHERE bs.status = 'success' AND bs.size IS NOT NULL AND b.deleted_at IS NULL\n GROUP BY sc.id, sc.name, sc.provider\n ORDER BY total_bytes DESC\n", + "name": "mv_kpi_storage_treemap", + "schema": "public", + "isExisting": false, + "materialized": true + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index 19348d5f6..5f6be5cfc 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -708,6 +708,13 @@ "when": 1795632898547, "tag": "0100_smb_storage", "breakpoints": true + }, + { + "idx": 101, + "version": "7", + "when": 1795636719689, + "tag": "0101_granular_encryption", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/db/schema/03_organization.ts b/src/db/schema/03_organization.ts index 6772e6bcd..9cc05d46a 100644 --- a/src/db/schema/03_organization.ts +++ b/src/db/schema/03_organization.ts @@ -1,4 +1,4 @@ -import {pgTable, text, uuid} from "drizzle-orm/pg-core"; +import {boolean, pgTable, text, uuid} from "drizzle-orm/pg-core"; import {relations} from "drizzle-orm"; import {Project, project} from "./06_project"; import {createSelectSchema} from "drizzle-zod"; @@ -16,6 +16,7 @@ export const organization = pgTable("organization", { slug: text("slug").unique().notNull(), logo: text("logo"), metadata: text("metadata"), + encryption: boolean("encryption").default(false).notNull(), ...timestamps }); diff --git a/src/db/schema/06_project.ts b/src/db/schema/06_project.ts index d6cde2b45..070e50d49 100644 --- a/src/db/schema/06_project.ts +++ b/src/db/schema/06_project.ts @@ -14,6 +14,7 @@ export const project = pgTable("projects", { name: text("name").notNull().notNull(), isArchived: boolean("is_archived").default(false), backupPolicy: text("backup_policy"), + encryption: boolean("encryption").default(false).notNull(), organizationId: uuid("organization_id") .notNull() .references(() => organization.id, {onDelete: "cascade"}), diff --git a/src/db/schema/07_database.ts b/src/db/schema/07_database.ts index a8749fa84..f1d688b68 100644 --- a/src/db/schema/07_database.ts +++ b/src/db/schema/07_database.ts @@ -1,6 +1,7 @@ import {pgTable, text, boolean, timestamp, uuid, integer, pgEnum, bigint, index, check, jsonb, type AnyPgColumn} from "drizzle-orm/pg-core"; import {Agent, agent, AgentWith} from "./08_agent"; import {Project, project} from "./06_project"; +import type {Organization} from "./03_organization"; import {relations, sql} from "drizzle-orm"; import {backupEngineEnum, dbmsEnum, statusEnum} from "./types"; import {createSelectSchema} from "drizzle-zod"; @@ -18,6 +19,7 @@ export const database = pgTable("databases", { dbms: dbmsEnum("dbms").notNull(), description: text("description"), backupPolicy: text("backup_policy"), + encryption: boolean("encryption").default(false).notNull(), isWaitingForBackup: boolean("is_waiting_for_backup").default(false).notNull(), backupToRestore: text("backup_to_restore"), config: jsonb("config").$type>(), @@ -165,6 +167,7 @@ export type RetentionPolicy = z.infer; export type DatabaseWith = Database & { agent?: Agent | AgentWith | null; project?: (Project & { + organization?: Pick | null; storagePolicies?: StoragePolicy[]; alertPolicies?: AlertPolicy[]; retentionPolicy?: RetentionPolicy | null; diff --git a/src/features/database/utils/policy-resolution.ts b/src/features/database/utils/policy-resolution.ts index d7032cc1d..f5c45cf94 100644 --- a/src/features/database/utils/policy-resolution.ts +++ b/src/features/database/utils/policy-resolution.ts @@ -22,3 +22,12 @@ export function resolveRetentionPolicy(db: DatabaseWith): RetentionPolicy | null export function resolveBackupCron(db: DatabaseWith): string | null { return db.backupPolicy ?? db.project?.backupPolicy ?? null; } + +const ENCRYPTION_LEVELS = ["system", "organization", "project", "database"] as const; +export type EncryptionLevel = (typeof ENCRYPTION_LEVELS)[number]; + +export function resolveEncryptionSource( + flags: Partial>, +): EncryptionLevel | null { + return ENCRYPTION_LEVELS.find((level) => flags[level]) ?? null; +} From 35928c83a471c5616df778b94ab98fbe40676f6d Mon Sep 17 00:00:00 2001 From: Charles Gauthereau Date: Wed, 25 Nov 2026 20:59:57 +0100 Subject: [PATCH 2/6] feat: resolve backup encryption per database --- .../agents/utils/status/status.helpers.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/features/agents/utils/status/status.helpers.ts b/src/features/agents/utils/status/status.helpers.ts index a8978bed1..aa7be5ef5 100644 --- a/src/features/agents/utils/status/status.helpers.ts +++ b/src/features/agents/utils/status/status.helpers.ts @@ -16,7 +16,7 @@ import {applyStorageEncryption} from "./storage-encryption.helpers"; import {applyConfigEncryption} from "./config-encryption.helpers"; import {isAgentVersionAtLeast, MIN_AGENT_VERSION_DB_CONFIG} from "@/utils/status-crypto"; import {prepareRestoration} from "./restoration.helpers"; -import {resolveBackupCron} from "@/features/database/utils/policy-resolution"; +import {resolveBackupCron, resolveEncryptionSource} from "@/features/database/utils/policy-resolution"; import {agentSupportsPhysical, MIN_PHYSICAL_AGENT_VERSION} from "@/features/agents/utils/version"; import {engineFromWire, resolveMethodConflict} from "@/features/database/utils/backup-method"; @@ -55,7 +55,12 @@ export async function handleDatabases(body: Body, agent: Agent, lastContact: Dat generatedId: database.agentDatabaseId, dbms: database.dbms, storages: storages, - encrypt: settings.encryption, + encrypt: resolveEncryptionSource({ + system: settings.encryption, + organization: database.project?.organization?.encryption, + project: database.project?.encryption, + database: database.encryption, + }) !== null, data: { backup: {action: physicalUnsupported ? false : backupAction, cron: physicalUnsupported ? null : cron, engine: database.backupEngine}, restore: {action: restoreAction, file: UrlBackup, metaFile: urlMeta, size: backupSize}, @@ -73,7 +78,7 @@ export async function handleDatabases(body: Body, agent: Agent, lastContact: Dat isNull(drizzleDb.schemas.database.deletedAt), ), with: { - project: true + project: {with: {organization: {columns: {encryption: true}}}} } }); @@ -254,12 +259,13 @@ export async function handleDatabases(body: Body, agent: Agent, lastContact: Dat backupSize = restore.size enginePayload = restore.enginePayload } - const resolvedCron = resolveBackupCron({ + const databaseWithProject = { ...databaseUpdated, project: existingDatabase.project, - } as DatabaseWith); + } as DatabaseWith; + const resolvedCron = resolveBackupCron(databaseWithProject); const storages = await getDatabaseStorageChannels(databaseUpdated.id) - const entry = formatDatabase(databaseUpdated, backupAction, restoreAction, urlBackup, storages, urlMeta, backupSize, methodConflict ? null : resolvedCron); + const entry = formatDatabase(databaseWithProject, backupAction, restoreAction, urlBackup, storages, urlMeta, backupSize, methodConflict ? null : resolvedCron); if (enginePayload) Object.assign(entry.data.restore, enginePayload); applyStorageEncryption(entry, body.version, masterKey, agent.id); applyConfigEncryption(entry, body.version, masterKey, agent.id); @@ -276,7 +282,7 @@ export async function handleDatabases(body: Body, agent: Agent, lastContact: Dat isNotNull(drizzleDb.schemas.database.config), isNull(drizzleDb.schemas.database.deletedAt), ), - with: {project: true}, + with: {project: {with: {organization: {columns: {encryption: true}}}}}, }); for (const dashDb of dashboardDbs) { From 1913e310fc3fedbd602c1a822adb89be11e2fc5f Mon Sep 17 00:00:00 2001 From: Charles Gauthereau Date: Wed, 25 Nov 2026 21:01:17 +0100 Subject: [PATCH 3/6] feat: database encryption switch --- .../database/[databaseId]/page.tsx | 14 ++++- .../database/actions/encryption.action.ts | 38 +++++++++++++ .../database/components/database-content.tsx | 9 ++++ .../database/components/encryption-switch.tsx | 53 +++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/features/database/actions/encryption.action.ts create mode 100644 src/features/database/components/encryption-switch.tsx diff --git a/app/(customer)/dashboard/(organization)/projects/[projectId]/database/[databaseId]/page.tsx b/app/(customer)/dashboard/(organization)/projects/[projectId]/database/[databaseId]/page.tsx index c0c5b97e6..16f0acbe8 100644 --- a/app/(customer)/dashboard/(organization)/projects/[projectId]/database/[databaseId]/page.tsx +++ b/app/(customer)/dashboard/(organization)/projects/[projectId]/database/[databaseId]/page.tsx @@ -11,6 +11,7 @@ import { DatabaseContent } from "@/features/database/components/database-content import { getHealthLast12hLogs } from "@/db/services/healthcheck"; import { LogsModalProvider } from "@/features/logs/components/logs-modal-context"; import { maskConfigForDashboard } from "@/features/database/utils/credential-fields"; +import { resolveEncryptionSource } from "@/features/database/utils/policy-resolution"; export default async function RoutePage( props: PageParams<{ @@ -39,7 +40,7 @@ export default async function RoutePage( eq(drizzleDb.schemas.database.projectId, projectId), ), with: { - project: true, + project: { with: { organization: { columns: { encryption: true } } } }, retentionPolicy: true, alertPolicies: true, storagePolicies: true, @@ -99,6 +100,16 @@ export default async function RoutePage( const successRate = totalBackups > 0 ? (successfulBackups / totalBackups) * 100 : null; + const systemSettings = await db.query.setting.findFirst({ + where: eq(drizzleDb.schemas.setting.name, "system"), + columns: { encryption: true }, + }); + const encryptionEnforcedBy = resolveEncryptionSource({ + system: systemSettings?.encryption, + organization: dbItem.project?.organization?.encryption, + project: dbItem.project?.encryption, + }); + return ( @@ -114,6 +125,7 @@ export default async function RoutePage( organizationId={organization.id} activeOrganizationChannels={[]} activeOrganizationStorageChannels={[]} + encryptionEnforcedBy={encryptionEnforcedBy} /> diff --git a/src/features/database/actions/encryption.action.ts b/src/features/database/actions/encryption.action.ts new file mode 100644 index 000000000..4871f3d96 --- /dev/null +++ b/src/features/database/actions/encryption.action.ts @@ -0,0 +1,38 @@ +"use server"; + +import {z} from "zod"; +import {eq} from "drizzle-orm"; +import {db} from "@/db"; +import * as drizzleDb from "@/db"; +import {withUpdatedAt} from "@/db/utils"; +import {ActionError, userAction} from "@/lib/safe-actions/actions"; +import {assertCanManagePolicyScope} from "@/features/database/utils/database-acl"; +import {assertCanManageOrganization} from "@/lib/acl/organization-guard"; + +const EncryptionScopeSchema = z.object({ + type: z.enum(["database", "project", "organization"]), + id: z.string().uuid(), +}); + +export type EncryptionScope = z.infer; + +export const updateEncryptionAction = userAction + .inputSchema(z.object({scope: EncryptionScopeSchema, enabled: z.boolean()})) + .action(async ({parsedInput: {scope, enabled}, ctx}) => { + const authorization = scope.type === "organization" + ? assertCanManageOrganization(ctx.user, scope.id) + : assertCanManagePolicyScope({type: scope.type, id: scope.id}); + await authorization.catch(() => { + throw new ActionError("Not authorized"); + }); + + const values = withUpdatedAt({encryption: enabled}); + if (scope.type === "database") { + await db.update(drizzleDb.schemas.database).set(values).where(eq(drizzleDb.schemas.database.id, scope.id)); + } else if (scope.type === "project") { + await db.update(drizzleDb.schemas.project).set(values).where(eq(drizzleDb.schemas.project.id, scope.id)); + } else { + await db.update(drizzleDb.schemas.organization).set(values).where(eq(drizzleDb.schemas.organization.id, scope.id)); + } + return {data: {enabled}}; + }); diff --git a/src/features/database/components/database-content.tsx b/src/features/database/components/database-content.tsx index a6c3e11a8..7f8df2802 100644 --- a/src/features/database/components/database-content.tsx +++ b/src/features/database/components/database-content.tsx @@ -28,6 +28,8 @@ import {METHOD_DESCRIPTIONS, METHOD_LABELS} from "@/features/database/utils/back import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert"; import {AlertCircleIcon} from "lucide-react"; import {agentSupportsPhysical, MIN_PHYSICAL_AGENT_VERSION} from "@/features/agents/utils/version"; +import {EncryptionSwitch} from "@/features/database/components/encryption-switch"; +import type {EncryptionLevel} from "@/features/database/utils/policy-resolution"; export type DatabaseContentProps = { isAlreadyRestore: boolean; @@ -40,6 +42,7 @@ export type DatabaseContentProps = { activeOrganizationChannels: any[]; activeOrganizationStorageChannels: any[]; databaseHealthLogs: HealthcheckLog[] + encryptionEnforcedBy: EncryptionLevel | null; }; export const DatabaseContent = (props: DatabaseContentProps) => { @@ -162,6 +165,12 @@ export const DatabaseContent = (props: DatabaseContentProps) => { organizationId={props.organizationId} queryKey={["database-data", database.id]} /> + {/* A physical backup only restores as part of its chain: nothing to import. */} {database.dbms !== "docker-volume" && database.dbms !== "files" && database.backupEngine !== "physical" && ( diff --git a/src/features/database/components/encryption-switch.tsx b/src/features/database/components/encryption-switch.tsx new file mode 100644 index 000000000..56fafb722 --- /dev/null +++ b/src/features/database/components/encryption-switch.tsx @@ -0,0 +1,53 @@ +"use client"; + +import {Lock} from "lucide-react"; +import {useMutation, useQueryClient} from "@tanstack/react-query"; +import {useRouter} from "next/navigation"; +import {toast} from "sonner"; +import {Switch} from "@/components/ui/switch"; +import {Label} from "@/components/ui/label"; +import {InfoTooltip} from "@/features/stats/components/info-tooltip"; +import {type EncryptionScope, updateEncryptionAction} from "@/features/database/actions/encryption.action"; +import type {EncryptionLevel} from "@/features/database/utils/policy-resolution"; + +export type EncryptionSwitchProps = { + scope: EncryptionScope; + enabled: boolean; + enforcedBy: EncryptionLevel | null; + queryKey?: unknown[]; +}; + +export const EncryptionSwitch = ({scope, enabled, enforcedBy, queryKey}: EncryptionSwitchProps) => { + const queryClient = useQueryClient(); + const router = useRouter(); + const switchId = `encryption-${scope.type}-${scope.id}`; + + const updateEncryption = useMutation({ + mutationFn: async (nextEnabled: boolean) => { + const result = await updateEncryptionAction({scope, enabled: nextEnabled}); + if (!result?.data) throw new Error(result?.serverError ?? "Encryption update failed"); + }, + onSuccess: () => { + toast.success("Encryption updated."); + if (queryKey) queryClient.invalidateQueries({queryKey}); + router.refresh(); + }, + onError: () => { + toast.error("An error occurred while updating encryption."); + }, + }); + + return ( +
+ + + updateEncryption.mutate(checked)} + /> + {enforcedBy && } +
+ ); +}; From 155f9da12bf6c9e275d81d526835542c3b611c85 Mon Sep 17 00:00:00 2001 From: Charles Gauthereau Date: Wed, 25 Nov 2026 21:03:00 +0100 Subject: [PATCH 4/6] feat: project and organization encryption switches --- .../(organization)/projects/[projectId]/page.tsx | 16 ++++++++++++++++ .../dashboard/(organization)/settings/page.tsx | 11 +++++++++++ .../components/organization-storages-tab.tsx | 16 ++++++++++++++++ .../components/organization-tabs.tsx | 6 +++++- .../settings/components/storage-section.tsx | 6 +++++- 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx b/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx index 2889a2cd6..30b647882 100644 --- a/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx +++ b/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx @@ -21,6 +21,8 @@ import { ChannelPoliciesModal } from "@/features/database/components/channels-po import { Megaphone, HardDrive } from "lucide-react"; import { InfoTooltip } from "@/features/stats/components/info-tooltip"; import { getDbmsFilter, lastBackupFilter, livenessFilter } from "@/components/common/filters/presets"; +import { EncryptionSwitch } from "@/features/database/components/encryption-switch"; +import { resolveEncryptionSource } from "@/features/database/utils/policy-resolution"; export default async function RoutePage( props: PageParams<{ @@ -80,6 +82,11 @@ export default async function RoutePage( await getOrganizationStorageChannels(organizationRecord.id) ).filter((channel) => channel.enabled); + const systemSettings = await db.query.setting.findFirst({ + where: eq(drizzleDb.schemas.setting.name, "system"), + columns: { encryption: true }, + }); + return (
@@ -125,6 +132,15 @@ export default async function RoutePage( organizationId={organizationRecord.id} queryKey={["project-policies", project.id]} /> + ) { if (!organizationWithMembers) notFound(); + const systemSettings = await db.query.setting.findFirst({ + where: eq(drizzleDb.schemas.setting.name, "system"), + columns: {encryption: true}, + }); + const encryption = { + enabled: organizationWithMembers.encryption, + enforcedBy: resolveEncryptionSource({system: systemSettings?.encryption}), + }; + return ( @@ -113,6 +123,7 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) { notificationChannels={notificationChannels} storageChannels={storageChannels} agents={agents} + encryption={encryption} /> diff --git a/src/features/organizations/components/organization-storages-tab.tsx b/src/features/organizations/components/organization-storages-tab.tsx index 820046e81..04bbcc85b 100644 --- a/src/features/organizations/components/organization-storages-tab.tsx +++ b/src/features/organizations/components/organization-storages-tab.tsx @@ -6,15 +6,24 @@ import {cn} from "@/lib/utils"; import {ChannelAddEditModal} from "@/features/channel/components/channel-add-edit-modal"; import {ChannelCard} from "@/features/channel/components/channel-card"; import {StorageChannel} from "@/db/schema/12_storage-channel"; +import {EncryptionSwitch} from "@/features/database/components/encryption-switch"; +import type {EncryptionLevel} from "@/features/database/utils/policy-resolution"; + +export type OrganizationEncryption = { + enabled: boolean; + enforcedBy: EncryptionLevel | null; +}; export type OrganizationNotifiersTabProps = { organization: OrganizationWithMembers; storageChannels: StorageChannel[]; + encryption: OrganizationEncryption; }; export const OrganizationStoragesTab = ({ organization, storageChannels, + encryption, }: OrganizationNotifiersTabProps) => { const [isAddModalOpen, setIsAddModalOpen] = useState(false); @@ -22,6 +31,13 @@ export const OrganizationStoragesTab = ({ const kind = "storage" return (
+
+ +
diff --git a/src/features/organizations/components/organization-tabs.tsx b/src/features/organizations/components/organization-tabs.tsx index 37166e318..e9bd74a1a 100644 --- a/src/features/organizations/components/organization-tabs.tsx +++ b/src/features/organizations/components/organization-tabs.tsx @@ -14,6 +14,7 @@ import { OrganizationNotifiersTab } from "@/features/organizations/components/organization-notifiers-tab"; import { + type OrganizationEncryption, OrganizationStoragesTab } from "@/features/organizations/components/organization-storages-tab"; import { @@ -27,6 +28,7 @@ export type OrganizationTabsProps = { storageChannels: StorageChannel[]; activeMember: MemberWithUser; agents: Agent[] + encryption: OrganizationEncryption; }; export const OrganizationTabs = ({ @@ -34,7 +36,8 @@ export const OrganizationTabs = ({ organization, notificationChannels, storageChannels, - agents + agents, + encryption }: OrganizationTabsProps) => { const router = useRouter(); const searchParams = useSearchParams(); @@ -101,6 +104,7 @@ export const OrganizationTabs = ({ diff --git a/src/features/settings/components/storage-section.tsx b/src/features/settings/components/storage-section.tsx index 5a229c6a6..6b46a30a8 100644 --- a/src/features/settings/components/storage-section.tsx +++ b/src/features/settings/components/storage-section.tsx @@ -7,6 +7,7 @@ import {Setting} from "@/db/schema/01_setting"; import { Form, FormControl, + FormDescription, FormField, FormItem, FormLabel, @@ -139,13 +140,16 @@ export const SettingsStorageSection = ({settings, storageChannels}: SettingsStor name="encryption" render={({field}) => ( - Backups Encryption + Encrypt all backups + + Organizations, projects and databases can also enable encryption individually. + )} From 33194f22e0e0d3f41d95b07494782861f12e59f2 Mon Sep 17 00:00:00 2001 From: Charles Gauthereau Date: Thu, 26 Nov 2026 08:05:58 +0100 Subject: [PATCH 5/6] feat: project encryption in dialog and compact database toggle --- .../projects/[projectId]/page.tsx | 14 ++---- .../(organization)/projects/page.tsx | 20 ++++++++- .../database/actions/encryption.action.ts | 4 +- .../database/components/database-content.tsx | 4 +- .../database/components/encryption-switch.tsx | 43 +++++++++++++++++-- .../projects/actions/projects.action.ts | 2 + .../projects/components/project-dialog.tsx | 6 ++- .../projects/components/project-form.tsx | 28 ++++++++++++ .../projects/schemas/projects.schema.ts | 1 + 9 files changed, 100 insertions(+), 22 deletions(-) diff --git a/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx b/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx index 30b647882..63c0738a7 100644 --- a/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx +++ b/app/(customer)/dashboard/(organization)/projects/[projectId]/page.tsx @@ -21,7 +21,6 @@ import { ChannelPoliciesModal } from "@/features/database/components/channels-po import { Megaphone, HardDrive } from "lucide-react"; import { InfoTooltip } from "@/features/stats/components/info-tooltip"; import { getDbmsFilter, lastBackupFilter, livenessFilter } from "@/components/common/filters/presets"; -import { EncryptionSwitch } from "@/features/database/components/encryption-switch"; import { resolveEncryptionSource } from "@/features/database/utils/policy-resolution"; export default async function RoutePage( @@ -102,6 +101,10 @@ export default async function RoutePage( organization={organizationRecord} project={project as unknown as ProjectWith} isEdit={true} + encryptionEnforcedBy={resolveEncryptionSource({ + system: systemSettings?.encryption, + organization: organizationRecord.encryption, + })} /> - ) { await getOrganizationAvailableDatabases(organization.id), ) + const organizationRecord = await db.query.organization.findFirst({ + where: eq(drizzleDb.schemas.organization.id, organization.id), + columns: {encryption: true}, + }); + const systemSettings = await db.query.setting.findFirst({ + where: eq(drizzleDb.schemas.setting.name, "system"), + columns: {encryption: true}, + }); + const encryptionEnforcedBy = resolveEncryptionSource({ + system: systemSettings?.encryption, + organization: organizationRecord?.encryption, + }); + return ( @@ -51,7 +67,7 @@ export default async function RoutePage(props: PageParams<{}>) { Projects {(projects.length > 0 && !isMember) && ( - + )} @@ -71,7 +87,7 @@ export default async function RoutePage(props: PageParams<{}>) { ) : isMember ? ( ) : ( - + )} diff --git a/src/features/database/actions/encryption.action.ts b/src/features/database/actions/encryption.action.ts index 4871f3d96..102347ac7 100644 --- a/src/features/database/actions/encryption.action.ts +++ b/src/features/database/actions/encryption.action.ts @@ -10,7 +10,7 @@ import {assertCanManagePolicyScope} from "@/features/database/utils/database-acl import {assertCanManageOrganization} from "@/lib/acl/organization-guard"; const EncryptionScopeSchema = z.object({ - type: z.enum(["database", "project", "organization"]), + type: z.enum(["database", "organization"]), id: z.string().uuid(), }); @@ -29,8 +29,6 @@ export const updateEncryptionAction = userAction const values = withUpdatedAt({encryption: enabled}); if (scope.type === "database") { await db.update(drizzleDb.schemas.database).set(values).where(eq(drizzleDb.schemas.database.id, scope.id)); - } else if (scope.type === "project") { - await db.update(drizzleDb.schemas.project).set(values).where(eq(drizzleDb.schemas.project.id, scope.id)); } else { await db.update(drizzleDb.schemas.organization).set(values).where(eq(drizzleDb.schemas.organization.id, scope.id)); } diff --git a/src/features/database/components/database-content.tsx b/src/features/database/components/database-content.tsx index 7f8df2802..70d145f42 100644 --- a/src/features/database/components/database-content.tsx +++ b/src/features/database/components/database-content.tsx @@ -28,7 +28,7 @@ import {METHOD_DESCRIPTIONS, METHOD_LABELS} from "@/features/database/utils/back import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert"; import {AlertCircleIcon} from "lucide-react"; import {agentSupportsPhysical, MIN_PHYSICAL_AGENT_VERSION} from "@/features/agents/utils/version"; -import {EncryptionSwitch} from "@/features/database/components/encryption-switch"; +import {EncryptionToggleButton} from "@/features/database/components/encryption-switch"; import type {EncryptionLevel} from "@/features/database/utils/policy-resolution"; export type DatabaseContentProps = { @@ -165,7 +165,7 @@ export const DatabaseContent = (props: DatabaseContentProps) => { organizationId={props.organizationId} queryKey={["database-data", database.id]} /> - { +function useUpdateEncryption(scope: EncryptionScope, queryKey?: unknown[]) { const queryClient = useQueryClient(); const router = useRouter(); - const switchId = `encryption-${scope.type}-${scope.id}`; - const updateEncryption = useMutation({ + return useMutation({ mutationFn: async (nextEnabled: boolean) => { const result = await updateEncryptionAction({scope, enabled: nextEnabled}); if (!result?.data) throw new Error(result?.serverError ?? "Encryption update failed"); @@ -36,6 +37,11 @@ export const EncryptionSwitch = ({scope, enabled, enforcedBy, queryKey}: Encrypt toast.error("An error occurred while updating encryption."); }, }); +} + +export const EncryptionSwitch = ({scope, enabled, enforcedBy, queryKey}: EncryptionSwitchProps) => { + const updateEncryption = useUpdateEncryption(scope, queryKey); + const switchId = `encryption-${scope.type}-${scope.id}`; return (
@@ -51,3 +57,32 @@ export const EncryptionSwitch = ({scope, enabled, enforcedBy, queryKey}: Encrypt
); }; + +export const EncryptionToggleButton = ({scope, enabled, enforcedBy, queryKey}: EncryptionSwitchProps) => { + const updateEncryption = useUpdateEncryption(scope, queryKey); + const encrypted = enabled || enforcedBy !== null; + const label = enforcedBy + ? `Backups encrypted, enforced by ${enforcedBy}` + : encrypted + ? "Backups encrypted, click to disable" + : "Backups not encrypted, click to encrypt"; + + return ( + + + + + + + {label} + + ); +}; diff --git a/src/features/projects/actions/projects.action.ts b/src/features/projects/actions/projects.action.ts index d09b0d31e..f416567ab 100644 --- a/src/features/projects/actions/projects.action.ts +++ b/src/features/projects/actions/projects.action.ts @@ -55,6 +55,7 @@ export const createProjectAction = userAction name: parsedInput.data.name, slug: slug, organizationId: parsedInput.organizationId, + encryption: parsedInput.data.encryption, }) .returning(); @@ -143,6 +144,7 @@ export const updateProjectAction = userAction .update(drizzleDb.schemas.project) .set({ name: parsedInput.data.name, + encryption: parsedInput.data.encryption, }) .where(eq(drizzleDb.schemas.project.id, parsedInput.projectId)) .returning(); diff --git a/src/features/projects/components/project-dialog.tsx b/src/features/projects/components/project-dialog.tsx index b4d85e021..f580fd6e9 100644 --- a/src/features/projects/components/project-dialog.tsx +++ b/src/features/projects/components/project-dialog.tsx @@ -17,6 +17,7 @@ import {ProjectWith} from "@/db/schema/06_project"; import {GearIcon} from "@radix-ui/react-icons"; import {EmptyStatePlaceholder} from "@/components/common/empty-state-placeholder"; import {useRouter} from "next/navigation"; +import type {EncryptionLevel} from "@/features/database/utils/policy-resolution"; type ProjectDialogProps = { databases: DatabaseWith[]; @@ -24,6 +25,7 @@ type ProjectDialogProps = { project?: ProjectWith; isEdit?: boolean; isEmpty?: boolean; + encryptionEnforcedBy: EncryptionLevel | null; }; export const ProjectDialog = ({ @@ -31,7 +33,8 @@ export const ProjectDialog = ({ organization, project, isEdit = false, - isEmpty = false + isEmpty = false, + encryptionEnforcedBy }: ProjectDialogProps) => { const [open, setOpen] = useState(false); const [isDirty, setIsDirty] = useState(false); @@ -76,6 +79,7 @@ export const ProjectDialog = ({ databases: project.databases.map(db => db.id) } : undefined} projectId={project?.id} + encryptionEnforcedBy={encryptionEnforcedBy} /> diff --git a/src/features/projects/components/project-form.tsx b/src/features/projects/components/project-form.tsx index 2628caab5..c0e95567f 100644 --- a/src/features/projects/components/project-form.tsx +++ b/src/features/projects/components/project-form.tsx @@ -13,6 +13,8 @@ import { toast } from "sonner"; import {DatabaseWith} from "@/db/schema/07_database"; import {Organization} from "@/db/schema/03_organization"; import {useReportFormDirty} from "@/hooks/use-report-form-dirty"; +import { Switch } from "@/components/ui/switch"; +import type { EncryptionLevel } from "@/features/database/utils/policy-resolution"; export type projectFormProps = { defaultValues?: ProjectType; @@ -21,6 +23,7 @@ export type projectFormProps = { projectId?: string; onSuccess?: (data: any) => void; onDirtyChange?: (dirty: boolean) => void; + encryptionEnforcedBy: EncryptionLevel | null; }; @@ -43,6 +46,7 @@ export const ProjectForm = (props: projectFormProps) => { ...props.defaultValues, name: props.defaultValues?.name ?? "", databases: !isCreate ? formatDefaultDatabases(props.defaultValues?.databases ?? []) : [], + encryption: props.defaultValues?.encryption ?? false, }; const form = useZodForm({ @@ -135,6 +139,30 @@ export const ProjectForm = (props: projectFormProps) => { )} /> + ( + +
+ Encrypt backups + + + +
+ + {props.encryptionEnforcedBy + ? `Enforced by ${props.encryptionEnforcedBy}` + : "Applies to every database in this project"} + + +
+ )} + />