CREATE TABLE "account" (
  "id" SERIAL PRIMARY KEY,
  "login" VARCHAR(10) NOT NULL,
  "pswd" VARCHAR(255) NOT NULL,
  "is_block" BOOLEAN,
  "dt_create" DATE,
  "token" VARCHAR(255) NOT NULL,
  "refresh" VARCHAR(255) NOT NULL
);

CREATE TABLE "profile" (
  "id" SERIAL PRIMARY KEY,
  "id_account" INTEGER NOT NULL,
  "name" VARCHAR(100) NOT NULL,
  "surname" VARCHAR(100) NOT NULL,
  "sex" BOOLEAN,
  "dt_birth" TIMESTAMP
);

CREATE INDEX "idx_profile__id_account" ON "profile" ("id_account");

ALTER TABLE "profile" ADD CONSTRAINT "fk_profile__id_account" FOREIGN KEY ("id_account") REFERENCES "account" ("id");

CREATE TABLE "role" (
  "id" SERIAL PRIMARY KEY,
  "name" TEXT NOT NULL
);

CREATE TABLE "role_account" (
  "id_roles" INTEGER NOT NULL,
  "acconts" INTEGER NOT NULL,
  PRIMARY KEY ("id_roles", "acconts")
);

CREATE INDEX "idx_role_account__acconts" ON "role_account" ("acconts");

ALTER TABLE "role_account" ADD CONSTRAINT "fk_role_account__acconts" FOREIGN KEY ("acconts") REFERENCES "account" ("id") ON DELETE CASCADE;

ALTER TABLE "role_account" ADD CONSTRAINT "fk_role_account__id_roles" FOREIGN KEY ("id_roles") REFERENCES "role" ("id") ON DELETE CASCADE;

CREATE TABLE "rules" (
  "id" SERIAL PRIMARY KEY,
  "name" TEXT NOT NULL,
  "body" JSONB NOT NULL
);

CREATE TABLE "role_rules" (
  "id_roles" INTEGER NOT NULL,
  "id_rules" INTEGER NOT NULL,
  PRIMARY KEY ("id_roles", "id_rules")
);

CREATE INDEX "idx_role_rules__id_rules" ON "role_rules" ("id_rules");

ALTER TABLE "role_rules" ADD CONSTRAINT "fk_role_rules__id_roles" FOREIGN KEY ("id_roles") REFERENCES "role" ("id") ON DELETE CASCADE;

ALTER TABLE "role_rules" ADD CONSTRAINT "fk_role_rules__id_rules" FOREIGN KEY ("id_rules") REFERENCES "rules" ("id") ON DELETE CASCADE;

CREATE TABLE "rules_rules" (
  "rules" INTEGER NOT NULL,
  "rules_2" INTEGER NOT NULL,
  PRIMARY KEY ("rules", "rules_2")
);

CREATE INDEX "idx_rules_rules" ON "rules_rules" ("rules_2");

ALTER TABLE "rules_rules" ADD CONSTRAINT "fk_rules_rules__rules" FOREIGN KEY ("rules") REFERENCES "rules" ("id");

ALTER TABLE "rules_rules" ADD CONSTRAINT "fk_rules_rules__rules_2" FOREIGN KEY ("rules_2") REFERENCES "rules" ("id")


1. Александр Козырев 23.11.1958
2. Ян Лаврентьев     16.10.1971
3. Чертков Виталий   04.08.1978
4. Пащенко Антон     26.04.1987
5. Антон Ларин       13.05.2000



2.
3. Александр Козырев 23.11.1958
4.Пащенко Антон: 26.04.1987 год рождения.
