58 lines
2.2 KiB
SQL
58 lines
2.2 KiB
SQL
-- Create "users" table
|
|
CREATE TABLE "public"."users" (
|
|
"id" uuid NOT NULL,
|
|
"first_name" text NOT NULL,
|
|
"last_name" text NOT NULL,
|
|
"display_name" text NOT NULL,
|
|
"email" text NOT NULL,
|
|
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
"updated_at" timestamptz NULL DEFAULT now(),
|
|
"deleted_at" timestamptz NULL,
|
|
PRIMARY KEY ("id"),
|
|
CONSTRAINT "users_email_unique" UNIQUE ("email")
|
|
);
|
|
-- Create "accounts" table
|
|
CREATE TABLE "public"."accounts" (
|
|
"id" uuid NOT NULL,
|
|
"user_id" uuid NOT NULL,
|
|
"password" text NULL,
|
|
"access_token" text NULL,
|
|
"refresh_token" text NULL,
|
|
"scope" text NULL,
|
|
"meta" jsonb NULL,
|
|
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
"updated_at" timestamptz NULL DEFAULT now(),
|
|
"deleted_at" timestamptz NULL,
|
|
PRIMARY KEY ("id"),
|
|
CONSTRAINT "accounts_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON UPDATE CASCADE ON DELETE CASCADE
|
|
);
|
|
-- Create index "accounts_user_id_idx" to table: "accounts"
|
|
CREATE INDEX "accounts_user_id_idx" ON "public"."accounts" ("user_id");
|
|
-- Create "roles" table
|
|
CREATE TABLE "public"."roles" (
|
|
"id" uuid NOT NULL,
|
|
"name" text NOT NULL,
|
|
"description" text NULL,
|
|
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
"updated_at" timestamptz NULL DEFAULT now(),
|
|
"deleted_at" timestamptz NULL,
|
|
PRIMARY KEY ("id"),
|
|
CONSTRAINT "roles_name_unique" UNIQUE ("name")
|
|
);
|
|
-- Create "user_roles" table
|
|
CREATE TABLE "public"."user_roles" (
|
|
"id" uuid NOT NULL,
|
|
"user_id" uuid NOT NULL,
|
|
"role_id" uuid NOT NULL,
|
|
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
"updated_at" timestamptz NULL DEFAULT now(),
|
|
"deleted_at" timestamptz NULL,
|
|
PRIMARY KEY ("id"),
|
|
CONSTRAINT "user_roles_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "public"."roles" ("id") ON UPDATE CASCADE ON DELETE CASCADE,
|
|
CONSTRAINT "user_roles_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON UPDATE CASCADE ON DELETE CASCADE
|
|
);
|
|
-- Create index "user_roles_role_id_idx" to table: "user_roles"
|
|
CREATE INDEX "user_roles_role_id_idx" ON "public"."user_roles" ("role_id");
|
|
-- Create index "user_roles_user_id_idx" to table: "user_roles"
|
|
CREATE INDEX "user_roles_user_id_idx" ON "public"."user_roles" ("user_id");
|