Kaiten
Architecture

Database Schema

The complete Kaiten database schema and ER diagram

Database Schema

Kaiten uses PostgreSQL as its primary database. Below is the auto-generated database schema.

Entity Relationship Diagram

Schema Definition (DBML)

View DBML Source
Enum "aggregation_method" {
  "SUM"
  "COUNT"
  "AVERAGE"
  "MAX"
  "MIN"
  "LATEST"
}

Enum "entitlement_type" {
  "BOOLEAN"
  "NUMBER"
  "CONFIG"
}

Enum "feature_audit_trail_status" {
  "ACCEPTED"
  "REJECTED"
}

Enum "license_type" {
  "DEVELOPMENT"
  "TRIAL"
  "PAID"
  "COMMUNITY"
}

Enum "meter_type" {
  "CALCULATED_USAGE"
  "RAW_EVENT"
}

Enum "user_type" {
  "human"
  "machine"
}

Table "goose_db_version" {
  "id" int4 [pk, not null, increment]
  "version_id" int8 [not null]
  "is_applied" bool [not null]
  "tstamp" timestamp [not null, default: `now()`]
}

Table "organization" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "external_id" text [unique, not null]
  "name" text [not null]
}

Table "user" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "external_id" text [unique, not null]
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "created_by_id" uuid
  "deleted_at" timestamp
  "email" text [unique]
  "name" text [not null]
  "slug" text
  "type" user_type [not null, default: 'human']
  "organization_id" uuid

  Checks {
    `(type <> 'machine'::user_type) OR (slug IS NOT NULL)` [name: 'user_slug_machine_check']
    `(type <> 'machine'::user_type) OR (email IS NULL)` [name: 'user_email_machine_check']
    `(type <> 'machine'::user_type) OR (organization_id IS NOT NULL)` [name: 'user_organization_id_machine_check']
  }

  Indexes {
    (slug, organization_id) [type: btree, unique, name: "idx_unique_machine_slug_per_org"]
  }
}

Table "user_on_organization" {
  "deleted_at" timestamp
  "organization_id" uuid [not null]
  "user_id" uuid [not null]

  Indexes {
    (organization_id, user_id) [pk, type: btree, name: "user_on_organization_pkey"]
  }
}

Table "customer" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "name" text [not null]
  "slug" text [not null]
  "external_customer_id" text
  "created_by_id" uuid [not null]
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "updated_by_id" uuid [not null]
  "updated_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "organization_id" uuid [not null]

  Indexes {
    (organization_id, slug) [type: btree, unique, name: "customer_organization_id_slug_key"]
  }
}

Table "license" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "name" text [not null]
  "slug" text [not null]
  "description" text [not null]
  "type" license_type [not null]
  "version" int4 [not null, increment]
  "version_name" text
  "is_active" bool [not null]
  "is_default" bool [not null, default: false]
  "features" jsonb
  "organization_id" uuid [not null]

  Indexes {
    (name, version, organization_id) [type: btree, unique, name: "license_name_version_organization_id_key"]
    (organization_id, slug) [type: btree, unique, name: "license_organization_id_slug_key"]
  }
}

Table "entitlement" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "name" text [not null]
  "slug" text [not null]
  "description" text
  "type" entitlement_type [not null]
  "event_name" text [not null]
  "meter_type" meter_type
  "aggregation_method" aggregation_method
  "organization_id" uuid [not null]

  Checks {
    `((type = 'NUMBER'::entitlement_type) AND (meter_type = ANY (ARRAY['CALCULATED_USAGE'::meter_type, 'RAW_EVENT'::meter_type]))) OR ((type = ANY (ARRAY['BOOLEAN'::entitlement_type, 'CONFIG'::entitlement_type])) AND (meter_type IS NULL))` [name: 'entitlement_number_meter_check']
    `((type = 'NUMBER'::entitlement_type) AND (meter_type = 'RAW_EVENT'::meter_type) AND (aggregation_method = ANY (ARRAY['COUNT'::aggregation_method, 'SUM'::aggregation_method, 'AVERAGE'::aggregation_method, 'MAX'::aggregation_method, 'MIN'::aggregation_method, 'LATEST'::aggregation_method]))) OR ((type = 'NUMBER'::entitlement_type) AND (meter_type = 'CALCULATED_USAGE'::meter_type)) OR ((type = ANY (ARRAY['BOOLEAN'::entitlement_type, 'CONFIG'::entitlement_type])) AND (aggregation_method IS NULL))` [name: 'entitlement_aggregation_method_check']
  }

  Indexes {
    (organization_id, slug) [type: btree, unique, name: "entitlement_organization_id_slug_key"]
  }
}

Table "license_entitlement" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "entitlement_id" uuid [not null]
  "license_id" uuid [not null]
  "created_by_id" uuid [not null]
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "updated_by_id" uuid [not null]
  "updated_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "value" jsonb [not null, check: `(jsonb_typeof(value) = 'object'::text) AND (value ? 'type'::text) AND (value ? 'value'::text) AND ((((value ->> 'type'::text) = 'number'::text) AND (jsonb_typeof((value -> 'value'::text)) = 'number'::text)) OR (((value ->> 'type'::text) = 'boolean'::text) AND (jsonb_typeof((value -> 'value'::text)) = 'boolean'::text)) OR (((value ->> 'type'::text) = 'object'::text) AND (jsonb_typeof((value -> 'value'::text)) = 'object'::text)))`]
  "organization_id" uuid [not null]
}

Table "instance" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "created_by_id" uuid [not null]
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "updated_by_id" uuid [not null]
  "updated_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "deleted_at" timestamp
  "name" text [not null]
  "slug" text [not null]
  "description" text [not null]
  "customer_id" uuid [not null]
  "license_id" uuid [not null]
  "deployment_zone_id" uuid
  "start_license_date" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "end_license_date" timestamp [not null, default: `(now() + '1 year'::interval)`]
  "platform" jsonb
  "metadata" jsonb [not null, default: `{}`]
  "organization_id" uuid [not null]

  Indexes {
    (organization_id, slug) [type: btree, unique, name: "instance_organization_id_slug_key"]
  }
}

Table "entitlement_usage" {
  "entitlement_id" uuid [not null]
  "instance_id" uuid [not null]
  "value" jsonb [not null, check: `(jsonb_typeof(value) = 'object'::text) AND (value ? 'type'::text) AND (value ? 'value'::text) AND (value ? 'event_count'::text) AND ((value ->> 'type'::text) = 'number'::text) AND (jsonb_typeof((value -> 'value'::text)) = 'number'::text) AND (jsonb_typeof((value -> 'event_count'::text)) = 'number'::text) AND (((value ->> 'event_count'::text))::numeric >= (0)::numeric) AND (floor(((value ->> 'event_count'::text))::numeric) = ((value ->> 'event_count'::text))::numeric)`]
  "organization_id" uuid [not null]

  Indexes {
    (entitlement_id, instance_id) [pk, type: btree, name: "entitlement_usage_pkey"]
  }
}

Table "feature_audit_trail" {
  "id" int4 [pk, not null, increment]
  "instance_id" uuid [not null]
  "event_name" text [not null]
  "timestamp" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "payload" jsonb
  "organization_id" uuid [not null]
  "status" feature_audit_trail_status [not null]
}

Table "feature_flags" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "type" varchar [not null]
  "variants" jsonb [not null]
  "targeting_rules" jsonb
  "name" varchar [not null]
  "description" text
  "slug" varchar [not null]
  "metadata" jsonb
  "enabled" bool [not null]
  "event_name" varchar [not null]
  "organization_id" uuid [not null]
  "default_variant" jsonb [not null]

  Indexes {
    (slug, organization_id) [type: btree, unique, name: "uq_feature_flags_slug"]
  }
}

Table "token" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "name" text [not null]
  "slug" text [not null]
  "hash" text [unique, not null]
  "lookup_hash" text [not null]
  "created_by" uuid [not null]
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "expires_at" timestamp
  "service_account_id" uuid [not null]
  "revoked_by" uuid
  "revoked_date" timestamp
  "organization_id" uuid [not null]
  "scopes" "text[]" [not null, default: 'ARRAY[text[]']

  Indexes {
    (service_account_id, name, organization_id) [type: btree, unique, name: "token_name"]
    (slug, organization_id) [type: btree, unique, name: "token_slug"]
  }
}

Table "outbox_events" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "organization_id" uuid [not null]
  "event_name" text [not null]
  "event_type" text [not null]
  "occurred_at" timestamptz [not null, default: `now()`]
  "data" jsonb [not null]
  "headers" jsonb
}

Table "deployment_zone" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "name" varchar [not null]
  "slug" text [not null]
  "type" varchar [not null]
  "features" jsonb
  "description" text [not null]
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "created_by_id" uuid [not null]
  "updated_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "updated_by_id" uuid [not null]
  "organization_id" uuid [not null]

  Indexes {
    (organization_id, slug) [type: btree, unique, name: "deployment_zone_organization_id_slug_key"]
  }
}

Table "release" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "previous_release_id" uuid
  "version" varchar [not null]
  "slug" text [not null]
  "description" text
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "created_by_id" uuid [not null]
  "updated_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "updated_by_id" uuid [not null]
  "organization_id" uuid [not null]

  Indexes {
    (version, organization_id) [type: btree, unique, name: "component_version_unique"]
    (organization_id, slug) [type: btree, unique, name: "release_organization_id_slug_key"]
  }
}

Table "deployment" {
  "deployment_zone_id" uuid [not null]
  "release_id" uuid [not null]
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "created_by_id" uuid [not null]
  "organization_id" uuid [not null]

  Indexes {
    (deployment_zone_id, release_id) [pk, type: btree, name: "deployment_pkey"]
  }
}

Table "component" {
  "id" uuid [pk, not null, default: `gen_random_uuid()`]
  "previous_component_id" uuid
  "name" varchar [not null]
  "version" varchar [not null]
  "slug" text [not null]
  "description" text
  "created_at" timestamp [not null, default: `CURRENT_TIMESTAMP`]
  "created_by_id" uuid [not null]
  "organization_id" uuid [not null]

  Indexes {
    (organization_id, name, version) [type: btree, unique, name: "component_name_version_unique"]
    (organization_id, slug) [type: btree, unique, name: "component_organization_id_slug_key"]
  }
}

Table "component_release" {
  "component_id" uuid [not null]
  "release_id" uuid [not null]
  "organization_id" uuid [not null]

  Indexes {
    (component_id, release_id) [pk, type: btree, name: "component_on_release_pkey"]
  }
}

Ref "component_created_by_fkey":"user"."id" < "component"."created_by_id" [update: cascade, delete: restrict]

Ref "component_organization_fkey":"organization"."id" < "component"."organization_id" [update: cascade, delete: cascade]

Ref "component_release_component_fkey":"component"."id" < "component_release"."component_id" [update: cascade, delete: restrict]

Ref "component_release_organization_fkey":"organization"."id" < "component_release"."organization_id" [update: cascade, delete: cascade]

Ref "component_release_release_fkey":"release"."id" < "component_release"."release_id" [update: cascade, delete: restrict]

Ref "customer_created_by_id_fkey":"user"."id" < "customer"."created_by_id" [update: cascade, delete: restrict]

Ref "customer_organization_id_fkey":"organization"."id" < "customer"."organization_id" [update: cascade, delete: cascade]

Ref "customer_updated_by_id_fkey":"user"."id" < "customer"."updated_by_id" [update: cascade, delete: restrict]

Ref "deployment_created_by_fkey":"user"."id" < "deployment"."created_by_id" [update: cascade, delete: restrict]

Ref "deployment_deployment_zone_fkey":"deployment_zone"."id" < "deployment"."deployment_zone_id" [update: cascade, delete: cascade]

Ref "deployment_organization_fkey":"organization"."id" < "deployment"."organization_id" [update: cascade, delete: cascade]

Ref "deployment_release_fkey":"release"."id" < "deployment"."release_id" [update: cascade, delete: set null]

Ref "entitlement_organization_id_fkey":"organization"."id" < "entitlement"."organization_id" [update: cascade, delete: cascade]

Ref "entitlement_usage_entitlement_id_fkey":"entitlement"."id" < "entitlement_usage"."entitlement_id" [update: cascade, delete: restrict]

Ref "entitlement_usage_instance_id_fkey":"instance"."id" < "entitlement_usage"."instance_id" [update: cascade, delete: restrict]

Ref "entitlement_usage_organization_id_fkey":"organization"."id" < "entitlement_usage"."organization_id" [update: cascade, delete: cascade]

Ref "feature_audit_trail_instance_id_fkey":"instance"."id" < "feature_audit_trail"."instance_id" [update: cascade, delete: restrict]

Ref "feature_audit_trail_organization_id_fkey":"organization"."id" < "feature_audit_trail"."organization_id" [update: cascade, delete: cascade]

Ref "feature_flags_organization_id_fkey":"organization"."id" < "feature_flags"."organization_id" [update: cascade, delete: restrict]

Ref "instance_created_by_id_fkey":"user"."id" < "instance"."created_by_id" [update: cascade, delete: restrict]

Ref "instance_customer_id_fkey":"customer"."id" < "instance"."customer_id" [update: cascade, delete: cascade]

Ref "instance_deployment_zone_id_fkey":"deployment_zone"."id" < "instance"."deployment_zone_id" [update: cascade, delete: set null]

Ref "instance_license_id_fkey":"license"."id" < "instance"."license_id" [update: cascade, delete: restrict]

Ref "instance_organization_id_fkey":"organization"."id" < "instance"."organization_id" [update: cascade, delete: cascade]

Ref "instance_updated_by_id_fkey":"user"."id" < "instance"."updated_by_id" [update: cascade, delete: restrict]

Ref "license_organization_id_fkey":"organization"."id" < "license"."organization_id" [update: cascade, delete: cascade]

Ref "license_entitlement_entitlement_id_fkey":"entitlement"."id" < "license_entitlement"."entitlement_id" [update: cascade, delete: restrict]

Ref "license_entitlement_license_id_fkey":"license"."id" < "license_entitlement"."license_id" [update: cascade, delete: restrict]

Ref "license_entitlement_organization_id_fkey":"organization"."id" < "license_entitlement"."organization_id" [update: cascade, delete: cascade]

Ref "previous_release_fkey":"release"."id" < "release"."previous_release_id" [update: cascade, delete: restrict]

Ref "release_created_by_fkey":"user"."id" < "release"."created_by_id" [update: cascade, delete: restrict]

Ref "release_organization_fkey":"organization"."id" < "release"."organization_id" [update: cascade, delete: cascade]

Ref "token_created_by_fkey":"user"."id" < "token"."created_by" [update: cascade, delete: cascade]

Ref "token_organization_id_fkey":"organization"."id" < "token"."organization_id" [update: cascade, delete: cascade]

Ref "token_revoked_by_fkey":"user"."id" < "token"."revoked_by" [update: cascade, delete: set null]

Ref "token_service_account_id_fkey":"user"."id" < "token"."service_account_id" [update: cascade, delete: cascade]

Ref "user_organization_id_fkey":"organization"."id" < "user"."organization_id" [update: cascade, delete: cascade]

Ref "user_on_organization_organization_id_fkey":"organization"."id" < "user_on_organization"."organization_id" [update: cascade, delete: cascade]

Ref "user_on_organization_user_id_fkey":"user"."id" < "user_on_organization"."user_id" [update: cascade, delete: restrict]

On this page