diff --git a/doc/sql/data.sql b/doc/sql/data.sql new file mode 100644 index 0000000..17d16e1 --- /dev/null +++ b/doc/sql/data.sql @@ -0,0 +1,11 @@ +-- 第一次初始化数据库时,执行这个 sql 文件内的 sql +INSERT INTO "public"."Configs" VALUES (1, 'accesskey_id', '', '阿里 OSS / AWS S3 AccessKey_ID', '2023-12-25 16:45:54.284484', NULL); +INSERT INTO "public"."Configs" VALUES (2, 'accesskey_secret', '', '阿里 OSS / AWS S3 AccessKey_Secret', '2023-12-25 16:46:02.552455', NULL); +INSERT INTO "public"."Configs" VALUES (3, 'region', '', '阿里 OSS / AWS S3 Region 地域,如:oss-cn-hongkong', '2023-12-25 16:46:14.881791', NULL); +INSERT INTO "public"."Configs" VALUES (4, 'endpoint', '', '阿里 OSS / AWS S3 Endpoint 地域节点,如:oss-cn-hongkong.aliyuncs.com', '2023-12-25 16:46:26.247859', NULL); +INSERT INTO "public"."Configs" VALUES (5, 'bucket', '', '阿里 OSS / AWS S3 Bucket 存储桶名称,如:picimpact', '2023-12-25 16:46:38.700241', NULL); +INSERT INTO "public"."Configs" VALUES (6, 'storage_folder', 'picimpact', '存储文件夹(S3),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径', '2023-12-25 16:46:50.732653', NULL); +INSERT INTO "public"."Configs" VALUES (7, 'alist_token', '', 'alist 令牌 ', '2023-12-25 16:45:08.661365', NULL); +INSERT INTO "public"."Configs" VALUES (8, 'alist_url', '', 'AList 地址,如:https://alist.besscroft.com', '2023-12-25 16:44:55.289006', NULL); + +INSERT INTO "public"."User" VALUES (1, 'admin', 'admin@qq.com', '51630b15b0cec2da9926af7015db33b7809f9d24959a0d48665b83e9d19216cd5601d08a622a8b2c48709d5bbb62eef6ae76addce5d18703b28965eef62d491b', null, 'https://bbs-static.miyoushe.com/communityweb/upload/97734c89374997c7c87d5af5f7442171.png'); diff --git a/doc/sql/schema.sql b/doc/sql/schema.sql deleted file mode 100644 index dc758dd..0000000 --- a/doc/sql/schema.sql +++ /dev/null @@ -1,123 +0,0 @@ -CREATE TABLE verification_token -( - identifier TEXT NOT NULL, - expires TIMESTAMPTZ NOT NULL, - token TEXT NOT NULL, - - PRIMARY KEY (identifier, token) -); - -CREATE TABLE accounts -( - id SERIAL, - "userId" INTEGER NOT NULL, - type VARCHAR(255) NOT NULL, - provider VARCHAR(255) NOT NULL, - "providerAccountId" VARCHAR(255) NOT NULL, - refresh_token TEXT, - access_token TEXT, - expires_at BIGINT, - id_token TEXT, - scope TEXT, - session_state TEXT, - token_type TEXT, - - PRIMARY KEY (id) -); - -CREATE TABLE sessions -( - id SERIAL, - "userId" INTEGER NOT NULL, - expires TIMESTAMPTZ NOT NULL, - "sessionToken" VARCHAR(255) NOT NULL, - - PRIMARY KEY (id) -); - -CREATE TABLE users -( - id SERIAL, - name VARCHAR(255), - email VARCHAR(255), - password VARCHAR(255), - "emailVerified" TIMESTAMPTZ, - image TEXT, - - PRIMARY KEY (id) -); - --- ---------------------------- --- Table structure for picimpact_image --- ---------------------------- -CREATE TABLE "public"."picimpact_image" ( - "id" int8 NOT NULL GENERATED BY DEFAULT AS IDENTITY ( - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 1 - CACHE 1 - ), - "type" varchar COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying, - "url" text COLLATE "pg_catalog"."default" DEFAULT ''::text, - "exif" json, - "rating" int2 DEFAULT '0'::smallint, - "detail" varchar COLLATE "pg_catalog"."default" DEFAULT ''::character varying, - "show" int2 DEFAULT '1'::smallint, - "sort" int2 DEFAULT '0'::smallint, - "create_time" timestamp(6) DEFAULT now(), - "update_time" timestamp(6), - "del" int2 DEFAULT '0'::smallint -); -COMMENT ON COLUMN "public"."picimpact_image"."type" IS '图片类型'; -COMMENT ON COLUMN "public"."picimpact_image"."url" IS '图片地址'; -COMMENT ON COLUMN "public"."picimpact_image"."exif" IS '图片 exif 信息'; -COMMENT ON COLUMN "public"."picimpact_image"."rating" IS '图片评分'; -COMMENT ON COLUMN "public"."picimpact_image"."detail" IS '图片描述'; -COMMENT ON COLUMN "public"."picimpact_image"."show" IS '显示状态:0->显示;1->不显示'; -COMMENT ON COLUMN "public"."picimpact_image"."sort" IS '图片排序'; -COMMENT ON COLUMN "public"."picimpact_image"."create_time" IS '创建时间'; -COMMENT ON COLUMN "public"."picimpact_image"."update_time" IS '更新时间'; -COMMENT ON COLUMN "public"."picimpact_image"."del" IS '逻辑删除:0->可用;1->删除'; -COMMENT ON TABLE "public"."picimpact_image" IS '图片信息表'; - -ALTER TABLE "public"."picimpact_image" ADD CONSTRAINT "picimpact_image_pkey" PRIMARY KEY ("id"); - --- ---------------------------- --- Table structure for picimpact_config --- ---------------------------- -CREATE TABLE "public"."picimpact_config" ( - "id" int8 NOT NULL GENERATED BY DEFAULT AS IDENTITY ( - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 1 - CACHE 1 -), - "config_key" varchar(32) NOT NULL, - "config_value" varchar(255), - "detail" varchar(255), - "create_time" timestamp(6) DEFAULT now(), - "update_time" timestamp(6) -); -COMMENT ON COLUMN "public"."picimpact_config"."config_key" IS 'key'; -COMMENT ON COLUMN "public"."picimpact_config"."config_value" IS 'value'; -COMMENT ON COLUMN "public"."picimpact_config"."detail" IS '描述'; -COMMENT ON COLUMN "public"."picimpact_config"."create_time" IS '创建时间'; -COMMENT ON COLUMN "public"."picimpact_config"."update_time" IS '更新时间'; - -ALTER TABLE "public"."picimpact_config" ADD CONSTRAINT "picimpact_config_pkey" PRIMARY KEY ("id"); -ALTER TABLE "public"."picimpact_config" ADD CONSTRAINT "uk_config_key" UNIQUE ("config_key"); - -COMMENT ON CONSTRAINT "uk_config_key" ON "public"."picimpact_config" IS 'key 唯一索引'; - -INSERT INTO "public"."picimpact_config" VALUES (6, 'accesskey_id', '', '阿里 OSS / AWS S3 AccessKey_ID', '2023-12-25 16:45:54.284484', NULL); -INSERT INTO "public"."picimpact_config" VALUES (7, 'accesskey_secret', '', '阿里 OSS / AWS S3 AccessKey_Secret', '2023-12-25 16:46:02.552455', NULL); -INSERT INTO "public"."picimpact_config" VALUES (8, 'region', '', '阿里 OSS / AWS S3 Region 地域,如:oss-cn-hongkong', '2023-12-25 16:46:14.881791', NULL); -INSERT INTO "public"."picimpact_config" VALUES (9, 'endpoint', '', '阿里 OSS / AWS S3 Endpoint 地域节点,如:oss-cn-hongkong.aliyuncs.com', '2023-12-25 16:46:26.247859', NULL); -INSERT INTO "public"."picimpact_config" VALUES (10, 'bucket', '', '阿里 OSS / AWS S3 Bucket 存储桶名称,如:picimpact', '2023-12-25 16:46:38.700241', NULL); -INSERT INTO "public"."picimpact_config" VALUES (11, 'storage_folder', 'picimpact', '存储文件夹(S3),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径', '2023-12-25 16:46:50.732653', NULL); -INSERT INTO "public"."picimpact_config" VALUES (12, 'cdn_url', '', 'CDN 域名(仅 S3),请严格按照 example.com 格式,不需要添加 https:// 会自动补充,如:picimpact-s3-cdn.heming.dev,CDN 以兼容阿里云 OSS 为主,理论上适配大多数存储。', '2023-12-25 16:49:10.434848', NULL); -INSERT INTO "public"."picimpact_config" VALUES (5, 'auth_key', 'picimpact', '权限 key,jwt 和 hash 都需要用到它。如果您更改了它,请自行生成新密码,默认值:picimpact', '2023-12-25 16:45:46.12813', NULL); -INSERT INTO "public"."picimpact_config" VALUES (4, 'alist_token', '', 'alist 令牌 ', '2023-12-25 16:45:08.661365', NULL); -INSERT INTO "public"."picimpact_config" VALUES (3, 'alist_url', '', 'AList 地址,如:https://alist.besscroft.com', '2023-12-25 16:44:55.289006', NULL); diff --git a/prisma/migrations/20240408041827_v1/migration.sql b/prisma/migrations/20240408041827_v1/migration.sql new file mode 100644 index 0000000..f563a98 --- /dev/null +++ b/prisma/migrations/20240408041827_v1/migration.sql @@ -0,0 +1,48 @@ +-- CreateTable +CREATE TABLE "Images" ( + "id" SERIAL NOT NULL, + "tag" TEXT NOT NULL, + "url" TEXT, + "exif" JSON, + "rating" SMALLINT, + "detail" TEXT, + "show" SMALLINT NOT NULL DEFAULT 1, + "sort" SMALLINT NOT NULL DEFAULT 0, + "create_time" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + "update_time" TIMESTAMP, + "del" SMALLINT NOT NULL DEFAULT 0, + + CONSTRAINT "Images_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Configs" ( + "id" SERIAL NOT NULL, + "config_key" TEXT NOT NULL, + "config_value" TEXT, + "detail" TEXT, + "create_time" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + "update_time" TIMESTAMP, + + CONSTRAINT "Configs_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Tags" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "tag_value" TEXT NOT NULL, + "detail" TEXT, + "show" SMALLINT NOT NULL DEFAULT 1, + "create_time" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + "update_time" TIMESTAMP, + "del" SMALLINT NOT NULL DEFAULT 0, + + CONSTRAINT "Tags_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Configs_config_key_key" ON "Configs"("config_key"); + +-- CreateIndex +CREATE UNIQUE INDEX "Tags_tag_value_key" ON "Tags"("tag_value"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 770ccfe..19b4be7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -4,22 +4,22 @@ datasource db { } generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" } model Account { - id String @id @default(cuid()) - userId String - type String - provider String - providerAccountId String - refresh_token String? @db.Text - access_token String? @db.Text - expires_at Int? - token_type String? - scope String? - id_token String? @db.Text - session_state String? + id String @id @default(cuid()) + userId String + type String + provider String + providerAccountId String + refresh_token String? @db.Text + access_token String? @db.Text + expires_at Int? + token_type String? + scope String? + id_token String? @db.Text + session_state String? user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@ -51,4 +51,38 @@ model VerificationToken { expires DateTime @@unique([identifier, token]) -} \ No newline at end of file +} + +model Images { + id Int @id @default(autoincrement()) + tag String + url String? @db.Text + exif Json? @db.Json + rating Int? @db.SmallInt + detail String? @db.Text + show Int @default(1) @db.SmallInt + sort Int @default(0) @db.SmallInt + create_time DateTime? @default(now()) @db.Timestamp() + update_time DateTime? @db.Timestamp() + del Int @default(0) @db.SmallInt +} + +model Configs { + id Int @id @default(autoincrement()) + config_key String @unique + config_value String? @db.Text + detail String? @db.Text + create_time DateTime? @default(now()) @db.Timestamp() + update_time DateTime? @db.Timestamp() +} + +model Tags { + id Int @id @default(autoincrement()) + name String + tag_value String @unique + detail String? @db.Text + show Int @default(1) @db.SmallInt + create_time DateTime? @default(now()) @db.Timestamp() + update_time DateTime? @db.Timestamp() + del Int @default(0) @db.SmallInt +}