CREATE TABLE "AspNetRoles"
(
    "Id"               text NOT NULL,
    "Name"             character varying(256) NULL,
    "NormalizedName"   character varying(256) NULL,
    "ConcurrencyStamp" text NULL,
    CONSTRAINT "PK_AspNetRoles" PRIMARY KEY ("Id")
);

CREATE TABLE "AspNetUsers"
(
    "Id"                   text    NOT NULL,
    "UserName"             character varying(256) NULL,
    "NormalizedUserName"   character varying(256) NULL,
    "Email"                character varying(256) NULL,
    "NormalizedEmail"      character varying(256) NULL,
    "EmailConfirmed"       boolean NOT NULL,
    "PasswordHash"         text NULL,
    "SecurityStamp"        text NULL,
    "ConcurrencyStamp"     text NULL,
    "PhoneNumber"          text NULL,
    "PhoneNumberConfirmed" boolean NOT NULL,
    "TwoFactorEnabled"     boolean NOT NULL,
    "LockoutEnd"           timestamp with time zone NULL,
    "LockoutEnabled"       boolean NOT NULL,
    "AccessFailedCount"    integer NOT NULL,
    CONSTRAINT "PK_AspNetUsers" PRIMARY KEY ("Id")
);

CREATE TABLE "AspNetRoleClaims"
(
    "Id"         integer GENERATED BY DEFAULT AS IDENTITY,
    "RoleId"     text NOT NULL,
    "ClaimType"  text NULL,
    "ClaimValue" text NULL,
    CONSTRAINT "PK_AspNetRoleClaims" PRIMARY KEY ("Id"),
    CONSTRAINT "FK_AspNetRoleClaims_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE
);

CREATE TABLE "AspNetUserClaims"
(
    "Id"         integer GENERATED BY DEFAULT AS IDENTITY,
    "UserId"     text NOT NULL,
    "ClaimType"  text NULL,
    "ClaimValue" text NULL,
    CONSTRAINT "PK_AspNetUserClaims" PRIMARY KEY ("Id"),
    CONSTRAINT "FK_AspNetUserClaims_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
);

CREATE TABLE "AspNetUserLogins"
(
    "LoginProvider"       character varying(128) NOT NULL,
    "ProviderKey"         character varying(128) NOT NULL,
    "ProviderDisplayName" text NULL,
    "UserId"              text                   NOT NULL,
    CONSTRAINT "PK_AspNetUserLogins" PRIMARY KEY ("LoginProvider", "ProviderKey"),
    CONSTRAINT "FK_AspNetUserLogins_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
);

CREATE TABLE "AspNetUserRoles"
(
    "UserId" text NOT NULL,
    "RoleId" text NOT NULL,
    CONSTRAINT "PK_AspNetUserRoles" PRIMARY KEY ("UserId", "RoleId"),
    CONSTRAINT "FK_AspNetUserRoles_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_AspNetUserRoles_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
);

CREATE TABLE "AspNetUserTokens"
(
    "UserId"        text                   NOT NULL,
    "LoginProvider" character varying(128) NOT NULL,
    "Name"          character varying(128) NOT NULL,
    "Value"         text NULL,
    CONSTRAINT "PK_AspNetUserTokens" PRIMARY KEY ("UserId", "LoginProvider", "Name"),
    CONSTRAINT "FK_AspNetUserTokens_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
);

CREATE INDEX "IX_AspNetRoleClaims_RoleId" ON "AspNetRoleClaims" ("RoleId");

CREATE UNIQUE INDEX "RoleNameIndex" ON "AspNetRoles" ("NormalizedName");

CREATE INDEX "IX_AspNetUserClaims_UserId" ON "AspNetUserClaims" ("UserId");

CREATE INDEX "IX_AspNetUserLogins_UserId" ON "AspNetUserLogins" ("UserId");

CREATE INDEX "IX_AspNetUserRoles_RoleId" ON "AspNetUserRoles" ("RoleId");

CREATE INDEX "EmailIndex" ON "AspNetUsers" ("NormalizedEmail");

CREATE UNIQUE INDEX "UserNameIndex" ON "AspNetUsers" ("NormalizedUserName");
