// The content of the file is just to have a basic idea of the current state of the database and is not fully accurate. 
// It is also not used by any piece of code to generate anything. 
// It doesn't contain the enums created in the database and the default values might also be buggy. 

create table "public"."actor"(
  "id" uuid not null,
  "workspace_id" uuid not null,
  "actor_definition_id" uuid not null,
  "name" varchar(256) not null,
  "configuration" jsonb not null,
  "actor_type" actor_type not null,
  "tombstone" bool not null default false,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  constraint "actor_pkey"
    primary key ("id")
);
create table "public"."actor_catalog"(
  "id" uuid not null,
  "catalog" jsonb not null,
  "catalog_hash" varchar(32) not null,
  "created_at" timestamptz(35) not null,
  "modified_at" timestamptz(35) not null default null,
  constraint "actor_catalog_pkey"
    primary key ("id")
);
create table "public"."actor_catalog_fetch_event"(
  "id" uuid not null,
  "actor_catalog_id" uuid not null,
  "actor_id" uuid not null,
  "config_hash" varchar(32) not null,
  "actor_version" varchar(256) not null,
  "created_at" timestamptz(35) not null default null,
  "modified_at" timestamptz(35) not null default null,
  constraint "actor_catalog_fetch_event_pkey"
    primary key ("id")
);
create table "public"."actor_definition"(
  "id" uuid not null,
  "name" varchar(256) not null,
  "docker_repository" varchar(256) not null,
  "docker_image_tag" varchar(256) not null,
  "documentation_url" varchar(256) null,
  "icon" varchar(256) null,
  "actor_type" actor_type not null,
  "source_type" source_type null,
  "spec" jsonb not null,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  "tombstone" bool not null default false,
  "release_stage" release_stage null,
  "release_date" date null,
  "resource_requirements" jsonb null,
  "public" bool not null default false,
  "custom" bool not null default false,
  constraint "actor_definition_pkey"
    primary key ("id")
);
create table "public"."actor_definition_workspace_grant"(
  "actor_definition_id" uuid not null,
  "workspace_id" uuid not null
);
create table "public"."actor_oauth_parameter"(
  "id" uuid not null,
  "workspace_id" uuid null,
  "actor_definition_id" uuid not null,
  "configuration" jsonb not null,
  "actor_type" actor_type not null,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  constraint "actor_oauth_parameter_pkey"
    primary key ("id")
);
create table "public"."airbyte_configs_migrations"(
  "installed_rank" int4 not null,
  "version" varchar(50) null,
  "description" varchar(200) not null,
  "type" varchar(20) not null,
  "script" varchar(1000) not null,
  "checksum" int4 null,
  "installed_by" varchar(100) not null,
  "installed_on" timestamp(29) not null default null,
  "execution_time" int4 not null,
  "success" bool not null,
  constraint "airbyte_configs_migrations_pk"
    primary key ("installed_rank")
);
create table "public"."connection"(
  "id" uuid not null,
  "namespace_definition" namespace_definition_type not null,
  "namespace_format" varchar(256) null,
  "prefix" varchar(256) null,
  "source_id" uuid not null,
  "destination_id" uuid not null,
  "name" varchar(256) not null,
  "catalog" jsonb not null,
  "status" status_type null,
  "schedule" jsonb null,
  "manual" bool not null,
  "resource_requirements" jsonb null,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  "source_catalog_id" uuid null,
  "schedule_type" schedule_type null,
  "schedule_data" jsonb null,
  constraint "connection_pkey"
    primary key ("id")
);
create table "public"."connection_operation"(
  "id" uuid not null,
  "connection_id" uuid not null,
  "operation_id" uuid not null,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  constraint "connection_operation_pkey"
    primary key (
      "id", 
      "connection_id", 
      "operation_id"
    )
);
create table "public"."operation"(
  "id" uuid not null,
  "workspace_id" uuid not null,
  "name" varchar(256) not null,
  "operator_type" operator_type not null,
  "operator_normalization" jsonb null,
  "operator_dbt" jsonb null,
  "tombstone" bool not null default false,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  constraint "operation_pkey"
    primary key ("id")
);
create table "public"."state"(
  "id" uuid not null,
  "connection_id" uuid not null,
  "state" jsonb null,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  constraint "state_pkey"
    primary key (
      "id", 
      "connection_id"
    )
);
create table "public"."workspace"(
  "id" uuid not null,
  "customer_id" uuid null,
  "name" varchar(256) not null,
  "slug" varchar(256) not null,
  "email" varchar(256) null,
  "initial_setup_complete" bool not null,
  "anonymous_data_collection" bool null,
  "send_newsletter" bool null,
  "send_security_updates" bool null,
  "display_setup_wizard" bool null,
  "tombstone" bool not null default false,
  "notifications" jsonb null,
  "first_sync_complete" bool null,
  "feedback_complete" bool null,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  constraint "workspace_pkey"
    primary key ("id")
);
create table "public"."workspace_service_account"(
  "workspace_id" uuid not null,
  "service_account_id" varchar(31) not null,
  "service_account_email" varchar(256) not null,
  "json_credential" jsonb not null,
  "hmac_key" jsonb not null,
  "created_at" timestamptz(35) not null default null,
  "updated_at" timestamptz(35) not null default null,
  constraint "workspace_service_account_pkey"
    primary key (
      "workspace_id", 
      "service_account_id"
    )
);
alter table "public"."actor"
  add constraint "actor_actor_definition_id_fkey"
    foreign key ("actor_definition_id")
    references "public"."actor_definition" ("id");
alter table "public"."actor"
  add constraint "actor_workspace_id_fkey"
    foreign key ("workspace_id")
    references "public"."workspace" ("id");
alter table "public"."actor_catalog_fetch_event"
  add constraint "actor_catalog_fetch_event_actor_catalog_id_fkey"
    foreign key ("actor_catalog_id")
    references "public"."actor_catalog" ("id");
alter table "public"."actor_catalog_fetch_event"
  add constraint "actor_catalog_fetch_event_actor_id_fkey"
    foreign key ("actor_id")
    references "public"."actor" ("id");
alter table "public"."actor_definition_workspace_grant"
  add constraint "actor_definition_workspace_grant_actor_definition_id_fkey"
    foreign key ("actor_definition_id")
    references "public"."actor_definition" ("id");
alter table "public"."actor_definition_workspace_grant"
  add constraint "actor_definition_workspace_grant_workspace_id_fkey"
    foreign key ("workspace_id")
    references "public"."workspace" ("id");
alter table "public"."actor_oauth_parameter"
  add constraint "actor_oauth_parameter_actor_definition_id_fkey"
    foreign key ("actor_definition_id")
    references "public"."actor_definition" ("id");
alter table "public"."connection"
  add constraint "connection_actor_catalog_id_fk"
    foreign key ("source_catalog_id")
    references "public"."actor_catalog" ("id");
alter table "public"."connection"
  add constraint "connection_destination_id_fkey"
    foreign key ("destination_id")
    references "public"."actor" ("id");
alter table "public"."connection"
  add constraint "connection_source_id_fkey"
    foreign key ("source_id")
    references "public"."actor" ("id");
alter table "public"."connection_operation"
  add constraint "connection_operation_connection_id_fkey"
    foreign key ("connection_id")
    references "public"."connection" ("id");
alter table "public"."connection_operation"
  add constraint "connection_operation_operation_id_fkey"
    foreign key ("operation_id")
    references "public"."operation" ("id");
alter table "public"."operation"
  add constraint "operation_workspace_id_fkey"
    foreign key ("workspace_id")
    references "public"."workspace" ("id");
alter table "public"."state"
  add constraint "state_connection_id_fkey"
    foreign key ("connection_id")
    references "public"."connection" ("id");
alter table "public"."workspace_service_account"
  add constraint "workspace_service_account_workspace_id_fkey"
    foreign key ("workspace_id")
    references "public"."workspace" ("id");
create index "actor_actor_definition_id_idx" on "public"."actor"("actor_definition_id" asc);
create unique index "actor_pkey" on "public"."actor"("id" asc);
create index "actor_workspace_id_idx" on "public"."actor"("workspace_id" asc);
create index "actor_catalog_catalog_hash_id_idx" on "public"."actor_catalog"("catalog_hash" asc);
create unique index "actor_catalog_pkey" on "public"."actor_catalog"("id" asc);
create index "actor_catalog_fetch_event_actor_catalog_id_idx" on "public"."actor_catalog_fetch_event"("actor_catalog_id" asc);
create index "actor_catalog_fetch_event_actor_id_idx" on "public"."actor_catalog_fetch_event"("actor_id" asc);
create unique index "actor_catalog_fetch_event_pkey" on "public"."actor_catalog_fetch_event"("id" asc);
create unique index "actor_definition_pkey" on "public"."actor_definition"("id" asc);
create unique index "actor_definition_workspace_gr_workspace_id_actor_definition_key" on "public"."actor_definition_workspace_grant"(
  "workspace_id" asc, 
  "actor_definition_id" asc
);
create unique index "actor_oauth_parameter_pkey" on "public"."actor_oauth_parameter"("id" asc);
create index "actor_oauth_parameter_workspace_definition_idx" on "public"."actor_oauth_parameter"(
  "workspace_id" asc, 
  "actor_definition_id" asc
);
create unique index "airbyte_configs_migrations_pk" on "public"."airbyte_configs_migrations"("installed_rank" asc);
create index "airbyte_configs_migrations_s_idx" on "public"."airbyte_configs_migrations"("success" asc);
create index "connection_destination_id_idx" on "public"."connection"("destination_id" asc);
create unique index "connection_pkey" on "public"."connection"("id" asc);
create index "connection_source_id_idx" on "public"."connection"("source_id" asc);
create index "connection_operation_connection_id_idx" on "public"."connection_operation"("connection_id" asc);
create unique index "connection_operation_pkey" on "public"."connection_operation"(
  "id" asc, 
  "connection_id" asc, 
  "operation_id" asc
);
create unique index "operation_pkey" on "public"."operation"("id" asc);
create unique index "state_pkey" on "public"."state"(
  "id" asc, 
  "connection_id" asc
);
create unique index "workspace_pkey" on "public"."workspace"("id" asc);
create unique index "workspace_service_account_pkey" on "public"."workspace_service_account"(
  "workspace_id" asc, 
  "service_account_id" asc
);
