From 17d5e0f55cb533d42037177d3f3f3ccc4f9fc62f Mon Sep 17 00:00:00 2001 From: Michael Li Date: Fri, 4 Nov 2022 14:08:25 +0800 Subject: [PATCH] add sql scheml define for friendship feature --- .../mysql/3_feature_contact.down.sql | 2 + .../migration/mysql/3_feature_contact.up.sql | 34 +++++++++ .../postgres/3_feature_contact.down.sql | 1 + .../postgres/3_feature_contact.up.sql | 1 + .../sqlite3/3_feature_contact.down.sql | 6 ++ .../sqlite3/3_feature_contact.up.sql | 44 ++++++++++++ scripts/paopao-mysql.sql | 38 ++++++++++ scripts/paopao-sqlite3.sql | 70 ++++++++++++++++--- 8 files changed, 186 insertions(+), 10 deletions(-) create mode 100644 scripts/migration/mysql/3_feature_contact.down.sql create mode 100644 scripts/migration/mysql/3_feature_contact.up.sql create mode 100644 scripts/migration/postgres/3_feature_contact.down.sql create mode 100644 scripts/migration/postgres/3_feature_contact.up.sql create mode 100644 scripts/migration/sqlite3/3_feature_contact.down.sql create mode 100644 scripts/migration/sqlite3/3_feature_contact.up.sql diff --git a/scripts/migration/mysql/3_feature_contact.down.sql b/scripts/migration/mysql/3_feature_contact.down.sql new file mode 100644 index 00000000..02e44706 --- /dev/null +++ b/scripts/migration/mysql/3_feature_contact.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS `p_contact`; +DROP TABLE IF EXISTS `p_contact_group`; diff --git a/scripts/migration/mysql/3_feature_contact.up.sql b/scripts/migration/mysql/3_feature_contact.up.sql new file mode 100644 index 00000000..45fa98ee --- /dev/null +++ b/scripts/migration/mysql/3_feature_contact.up.sql @@ -0,0 +1,34 @@ +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +CREATE TABLE `p_contact` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '联系人ID', + `user_id` bigint unsigned NOT NULL COMMENT '用户ID', + `friend_id` bigint unsigned NOT NULL COMMENT '好友ID', + `group_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '好友分组ID:默认为0无分组', + `remark` varchar(32) NOT NULL DEFAULT '' COMMENT '好友备注', + `status` tinyint NOT NULL DEFAULT '0' COMMENT '好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友', + `notice_enable` tinyint NOT NULL DEFAULT '0' COMMENT '是否有消息提醒, 0否, 1是', + `is_top` tinyint NOT NULL DEFAULT '0' COMMENT '是否置顶, 0否, 1是', + `is_black` tinyint NOT NULL DEFAULT '0' COMMENT '是否为黑名单, 0否, 1是', + `is_del` tinyint NOT NULL DEFAULT '0' COMMENT '是否删除好友, 0否, 1是', + `created_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', + `modified_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '修改时间', + `deleted_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '删除时间', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE KEY `idx_user_friend_id` (`user_id`,`friend_id`) USING BTREE, + KEY `idx_user_friend_status` (`user_id`, `friend_id`, `status`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='联系人'; + +CREATE TABLE `p_contact_group` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '联系人ID', + `user_id` int NOT NULL DEFAULT '0' COMMENT '用户id', + `name` varchar(32) NOT NULL DEFAULT '' COMMENT '分组名称', + `is_del` tinyint NOT NULL DEFAULT '1' COMMENT '是否删除, 0否, 1是', + `created_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', + `modified_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '修改时间', + `deleted_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '删除时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='联系人分组'; + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/scripts/migration/postgres/3_feature_contact.down.sql b/scripts/migration/postgres/3_feature_contact.down.sql new file mode 100644 index 00000000..3ce95155 --- /dev/null +++ b/scripts/migration/postgres/3_feature_contact.down.sql @@ -0,0 +1 @@ +-- TODO: WIP diff --git a/scripts/migration/postgres/3_feature_contact.up.sql b/scripts/migration/postgres/3_feature_contact.up.sql new file mode 100644 index 00000000..3ce95155 --- /dev/null +++ b/scripts/migration/postgres/3_feature_contact.up.sql @@ -0,0 +1 @@ +-- TODO: WIP diff --git a/scripts/migration/sqlite3/3_feature_contact.down.sql b/scripts/migration/sqlite3/3_feature_contact.down.sql new file mode 100644 index 00000000..b9a3543f --- /dev/null +++ b/scripts/migration/sqlite3/3_feature_contact.down.sql @@ -0,0 +1,6 @@ +PRAGMA foreign_keys = false; + +DROP TABLE IF EXISTS "p_contact"; +DROP TABLE IF EXISTS "p_contact_group"; + +PRAGMA foreign_keys = true; diff --git a/scripts/migration/sqlite3/3_feature_contact.up.sql b/scripts/migration/sqlite3/3_feature_contact.up.sql new file mode 100644 index 00000000..cb9d3a6a --- /dev/null +++ b/scripts/migration/sqlite3/3_feature_contact.up.sql @@ -0,0 +1,44 @@ +PRAGMA foreign_keys = false; + +CREATE TABLE "p_contact" ( + "id" integer NOT NULL, + "user_id" integer NOT NULL, + "friend_id" integer NOT NULL, + "group_id" integer NOT NULL, + "remark" text(32) NOT NULL, + "status" integer NOT NULL, + "notice_enable" integer NOT NULL, + "is_top" integer NOT NULL, + "is_black" integer NOT NULL, + "is_del" integer NOT NULL, + "created_on" integer NOT NULL, + "modified_on" integer NOT NULL, + "deleted_on" integer NOT NULL, + PRIMARY KEY ("id") +); + +CREATE TABLE "p_contact_group" ( + "id" integer NOT NULL, + "user_id" integer NOT NULL, + "name" text(32) NOT NULL, + "is_del" integer NOT NULL, + "created_on" integer NOT NULL, + "modified_on" integer NOT NULL, + "deleted_on" integer NOT NULL, + PRIMARY KEY ("id") +); + +CREATE UNIQUE INDEX "main"."idx_user_friend_id" +ON "p_contact" ( + "user_id" ASC, + "friend_id" ASC +); + +CREATE INDEX "main"."idx_user_friend_status" +ON "p_contact" ( + "user_id" ASC, + "friend_id" ASC, + "status" ASC +); + +PRAGMA foreign_keys = true; diff --git a/scripts/paopao-mysql.sql b/scripts/paopao-mysql.sql index 2fb8c258..18525ab3 100644 --- a/scripts/paopao-mysql.sql +++ b/scripts/paopao-mysql.sql @@ -270,6 +270,44 @@ CREATE TABLE `p_user` ( KEY `idx_phone` (`phone`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=100058 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户'; +-- ---------------------------- +-- Table structure for p_contact +-- ---------------------------- +DROP TABLE IF EXISTS `p_contact`; +CREATE TABLE `p_contact` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '联系人ID', + `user_id` bigint unsigned NOT NULL COMMENT '用户ID', + `friend_id` bigint unsigned NOT NULL COMMENT '好友ID', + `group_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '好友分组ID:默认为0无分组', + `remark` varchar(32) NOT NULL DEFAULT '' COMMENT '好友备注', + `status` tinyint NOT NULL DEFAULT '0' COMMENT '好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友', + `is_top` tinyint NOT NULL DEFAULT '0' COMMENT '是否置顶, 0否, 1是', + `is_black` tinyint NOT NULL DEFAULT '0' COMMENT '是否为黑名单, 0否, 1是', + `is_delete` tinyint NOT NULL DEFAULT '0' COMMENT '是否删除好友, 0否, 1是', + `notice_enable` tinyint NOT NULL DEFAULT '0' COMMENT '是否有消息提醒, 0否, 1是', + `created_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', + `modified_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '修改时间', + `deleted_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '删除时间', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE KEY `idx_user_friend_id` (`user_id`,`friend_id`) USING BTREE, + KEY `idx_user_friend_status` (`user_id`, `friend_id`, `status`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='联系人'; + +-- ---------------------------- +-- Table structure for p_contact_group +-- ---------------------------- +DROP TABLE IF EXISTS `p_contact_group`; +CREATE TABLE `p_contact_group` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '联系人ID', + `user_id` int NOT NULL DEFAULT '0' COMMENT '用户id', + `name` varchar(32) NOT NULL DEFAULT '' COMMENT '分组名称', + `is_delete` tinyint NOT NULL DEFAULT '1' COMMENT '是否删除, 0否, 1是', + `created_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', + `modified_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '修改时间', + `deleted_on` bigint unsigned NOT NULL DEFAULT '0' COMMENT '删除时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='联系人分组'; + -- ---------------------------- -- Table structure for p_wallet_recharge -- ---------------------------- diff --git a/scripts/paopao-sqlite3.sql b/scripts/paopao-sqlite3.sql index 685539e7..a82c4a34 100644 --- a/scripts/paopao-sqlite3.sql +++ b/scripts/paopao-sqlite3.sql @@ -90,6 +90,42 @@ CREATE TABLE "p_comment_reply" ( PRIMARY KEY ("id") ); +-- ---------------------------- +-- Table structure for p_contact +-- ---------------------------- +DROP TABLE IF EXISTS "p_contact"; +CREATE TABLE "p_contact" ( + "id" integer NOT NULL, + "user_id" integer NOT NULL, + "friend_id" integer NOT NULL, + "group_id" integer NOT NULL, + "remark" text(32) NOT NULL, + "status" integer NOT NULL, + "is_top" integer NOT NULL, + "is_black" integer NOT NULL, + "is_delete" integer NOT NULL, + "notice_enable" integer NOT NULL, + "created_on" integer NOT NULL, + "modified_on" integer NOT NULL, + "deleted_on" integer NOT NULL, + PRIMARY KEY ("id") +); + +-- ---------------------------- +-- Table structure for p_contact_group +-- ---------------------------- +DROP TABLE IF EXISTS "p_contact_group"; +CREATE TABLE "p_contact_group" ( + "id" integer NOT NULL, + "user_id" integer NOT NULL, + "name" text(32) NOT NULL, + "is_delete" integer NOT NULL, + "created_on" integer NOT NULL, + "modified_on" integer NOT NULL, + "deleted_on" integer NOT NULL, + PRIMARY KEY ("id") +); + -- ---------------------------- -- Table structure for p_message -- ---------------------------- @@ -122,7 +158,6 @@ CREATE TABLE "p_post" ( "comment_count" integer NOT NULL, "collection_count" integer NOT NULL, "upvote_count" integer NOT NULL, - "visibility" integer NOT NULL, "is_top" integer NOT NULL, "is_essence" integer NOT NULL, "is_lock" integer NOT NULL, @@ -134,7 +169,7 @@ CREATE TABLE "p_post" ( "created_on" integer NOT NULL, "modified_on" integer NOT NULL, "deleted_on" integer NOT NULL, - "is_del" integer NOT NULL, + "is_del" integer NOT NULL, `visibility` integer NOT NULL DEFAULT '0', PRIMARY KEY ("id") ); @@ -169,14 +204,6 @@ CREATE TABLE "p_post_collection" ( PRIMARY KEY ("id") ); --- ---------------------------- --- Indexes structure for table p_post --- ---------------------------- -CREATE INDEX "main"."idx_visibility" -ON "p_post" ( - "visibility" ASC -); - -- ---------------------------- -- Table structure for p_post_content -- ---------------------------- @@ -315,4 +342,27 @@ ON "p_comment" ( "post_id" ASC ); +-- ---------------------------- +-- Indexes structure for table p_contact +-- ---------------------------- +CREATE UNIQUE INDEX "main"."idx_user_friend_id" +ON "p_contact" ( + "user_id" ASC, + "friend_id" ASC +); +CREATE INDEX "main"."idx_user_friend_status" +ON "p_contact" ( + "user_id" ASC, + "friend_id" ASC, + "status" ASC +); + +-- ---------------------------- +-- Indexes structure for table p_post +-- ---------------------------- +CREATE INDEX "main"."idx_visibility" +ON "p_post" ( + "visibility" ASC +); + PRAGMA foreign_keys = true;