-- Schema: bird__financial
CREATE SCHEMA IF NOT EXISTS "bird__financial";

-- Table: account
CREATE TABLE "bird__financial"."account" (
    "account_id" BIGINT NOT NULL DEFAULT 0,
    "district_id" BIGINT NOT NULL DEFAULT 0,
    "frequency" TEXT NOT NULL,
    "date" DATE NOT NULL,
    CONSTRAINT "account_pkey" PRIMARY KEY ("account_id")
);

-- Table: card
CREATE TABLE "bird__financial"."card" (
    "card_id" BIGINT NOT NULL DEFAULT 0,
    "disp_id" BIGINT NOT NULL,
    "type" TEXT NOT NULL,
    "issued" DATE NOT NULL,
    CONSTRAINT "card_pkey" PRIMARY KEY ("card_id")
);

-- Table: client
CREATE TABLE "bird__financial"."client" (
    "client_id" BIGINT NOT NULL,
    "gender" TEXT NOT NULL,
    "birth_date" DATE NOT NULL,
    "district_id" BIGINT NOT NULL,
    CONSTRAINT "client_pkey" PRIMARY KEY ("client_id")
);

-- Table: disp
CREATE TABLE "bird__financial"."disp" (
    "disp_id" BIGINT NOT NULL,
    "client_id" BIGINT NOT NULL,
    "account_id" BIGINT NOT NULL,
    "type" TEXT NOT NULL,
    CONSTRAINT "disp_pkey" PRIMARY KEY ("disp_id")
);

-- Table: district
CREATE TABLE "bird__financial"."district" (
    "district_id" BIGINT NOT NULL DEFAULT 0,
    "A2" TEXT NOT NULL,
    "A3" TEXT NOT NULL,
    "A4" TEXT NOT NULL,
    "A5" TEXT NOT NULL,
    "A6" TEXT NOT NULL,
    "A7" TEXT NOT NULL,
    "A8" BIGINT NOT NULL,
    "A9" BIGINT NOT NULL,
    "A10" DOUBLE PRECISION NOT NULL,
    "A11" BIGINT NOT NULL,
    "A12" DOUBLE PRECISION,
    "A13" DOUBLE PRECISION NOT NULL,
    "A14" BIGINT NOT NULL,
    "A15" BIGINT,
    "A16" BIGINT NOT NULL,
    CONSTRAINT "district_pkey" PRIMARY KEY ("district_id")
);

-- Table: loan
CREATE TABLE "bird__financial"."loan" (
    "loan_id" BIGINT NOT NULL DEFAULT 0,
    "account_id" BIGINT NOT NULL,
    "date" DATE NOT NULL,
    "amount" BIGINT NOT NULL,
    "duration" BIGINT NOT NULL,
    "payments" DOUBLE PRECISION NOT NULL,
    "status" TEXT NOT NULL,
    CONSTRAINT "loan_pkey" PRIMARY KEY ("loan_id")
);

-- Table: order
CREATE TABLE "bird__financial"."order" (
    "order_id" BIGINT NOT NULL DEFAULT 0,
    "account_id" BIGINT NOT NULL,
    "bank_to" TEXT NOT NULL,
    "account_to" BIGINT NOT NULL,
    "amount" DOUBLE PRECISION NOT NULL,
    "k_symbol" TEXT NOT NULL,
    CONSTRAINT "order_pkey" PRIMARY KEY ("order_id")
);

-- Table: trans
CREATE TABLE "bird__financial"."trans" (
    "trans_id" BIGINT NOT NULL DEFAULT 0,
    "account_id" BIGINT NOT NULL DEFAULT 0,
    "date" DATE NOT NULL,
    "type" TEXT NOT NULL,
    "operation" TEXT,
    "amount" BIGINT NOT NULL,
    "balance" BIGINT NOT NULL,
    "k_symbol" TEXT,
    "bank" TEXT,
    "account" BIGINT,
    CONSTRAINT "trans_pkey" PRIMARY KEY ("trans_id")
);

-- Foreign Keys
ALTER TABLE "bird__financial"."account" ADD CONSTRAINT "fk_account_0" FOREIGN KEY ("district_id") REFERENCES "bird__financial"."district" ("district_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__financial"."card" ADD CONSTRAINT "fk_card_0" FOREIGN KEY ("disp_id") REFERENCES "bird__financial"."disp" ("disp_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__financial"."client" ADD CONSTRAINT "fk_client_0" FOREIGN KEY ("district_id") REFERENCES "bird__financial"."district" ("district_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__financial"."disp" ADD CONSTRAINT "fk_disp_0" FOREIGN KEY ("client_id") REFERENCES "bird__financial"."client" ("client_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__financial"."disp" ADD CONSTRAINT "fk_disp_1" FOREIGN KEY ("account_id") REFERENCES "bird__financial"."account" ("account_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__financial"."loan" ADD CONSTRAINT "fk_loan_0" FOREIGN KEY ("account_id") REFERENCES "bird__financial"."account" ("account_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__financial"."order" ADD CONSTRAINT "fk_order_0" FOREIGN KEY ("account_id") REFERENCES "bird__financial"."account" ("account_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__financial"."trans" ADD CONSTRAINT "fk_trans_0" FOREIGN KEY ("account_id") REFERENCES "bird__financial"."account" ("account_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
