DROP TABLE IF EXISTS "public"."t_user";
CREATE TABLE "public"."t_user" (
  "id" serial,
  "name" varchar(64) NOT NULL,
  "username" varchar(64) NOT NULL,
  "password" varchar(255) NOT NULL,
  "delete" bool NOT NULL DEFAULT false,
  PRIMARY KEY ("id")
);
COMMENT ON COLUMN "public"."t_user"."username" IS '用户名 账号';


DROP TABLE IF EXISTS "public"."t_resource";
CREATE TABLE "public"."t_resource" (
  "code" varchar(128) NOT NULL,
  "name" varchar(128) NOT NULL,
  "parent_code" varchar(128),
  PRIMARY KEY ("code")
);


DROP TABLE IF EXISTS "public"."t_user_resource";
CREATE TABLE "public"."t_user_resource" (
  "id" serial,
  "user_id" int4 NOT NULL,
  "resource_code" varchar(128) NOT NULL,
  PRIMARY KEY ("id"),
  CONSTRAINT "user_resource_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."t_user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT "user_resource_resource_code_fk" FOREIGN KEY ("resource_code") REFERENCES "public"."t_resource" ("code") ON DELETE NO ACTION ON UPDATE NO ACTION
);