support migration feature

pull/147/head
alimy 2 years ago
parent 2531ed940f
commit 3ac2be59ab

@ -107,6 +107,23 @@ PaoPao主要由以下优秀的开源项目/工具构建
```
提示: 如果需要内嵌web前端ui请先构建web前端(建议设置web/.env为VITE_HOST="")。
5. 使用内置的Migrate机制自动升级维护SQL DDL:
```sh
# 添加 Migration 功能到 Features 中 开启migrate功能
vim config.yaml
# file: config.yaml
# Features:
# Default: ["Base", "MySQL", "Zinc", "MinIO", "LoggerZinc", "Migration"]
# 编译时加入migration tag编译出支持migrate功能的可执行文件
make build TAGS='migration'
release/paopao-ce
# 或者 带上migration tag直接运行
make run TAGS='migration'
```
> 注意默认编译出来的执行文件是不内置migrate功能的需要编译时带上migration tag才能内置支持migrage功能。
#### 前端
@ -219,7 +236,7 @@ docker compose up --build
....
```
> 注意:默认提供的 docker-compose.yaml 仅用于搭建本机开发调试环境paopao-ce/phpMysqlAdmin 默认只能本机访问,如果需要产品部署供外网访问,请自行修改配置参数或使用其他方式部署。
> 注意:默认提供的 docker-compose.yaml 初衷是搭建本机开发调试环境,如果需要产品部署供外网访问,请自行调优配置参数或使用其他方式部署。
### API 文档
构建时将 `docs` 添加到TAGS中:
@ -300,7 +317,7 @@ release/paopao-ce --no-default-features --features sqlite3,localoss,loggerfile,r
* 日志: LoggerFile/LoggerZinc/LoggerMeili
`LoggerFile` 使用文件写日志(目前状态: 稳定);
`LoggerZinc` 使用[Zinc](https://github.com/zinclabs/zinc)写日志(目前状态: 稳定,推荐使用);
`LoggerMeili` 使用[Meilisearch](https://github.com/meilisearch/meilisearch)写日志(目前状态: 内测阶段);
`LoggerMeili` 使用[Meilisearch](https://github.com/meilisearch/meilisearch)写日志(目前状态: 稳定,推荐使用);
* 支付: Alipay
* 短信验证码: SmsJuhe(需要开启sms)
`Sms`功能如果没有开启,任意短信验证码都可以绑定手机;

@ -20,6 +20,7 @@ require (
github.com/go-resty/resty/v2 v2.7.0
github.com/goccy/go-json v0.9.7
github.com/gofrs/uuid v4.0.0+incompatible
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/google/go-cmp v0.5.7 // indirect
github.com/json-iterator/go v1.1.12
github.com/meilisearch/meilisearch-go v0.19.1
@ -31,7 +32,6 @@ require (
github.com/yinheli/mahonia v0.0.0-20131226213531-0eef680515cc
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
google.golang.org/protobuf v1.27.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/resty.v1 v1.12.0

929
go.sum

File diff suppressed because it is too large Load Diff

@ -11,13 +11,13 @@ var (
loggerFileSetting *LoggerFileSettingS
loggerZincSetting *LoggerZincSettingS
loggerMeiliSetting *LoggerMeiliSettingS
databaseSetting *DatabaseSetingS
mysqlSetting *MySQLSettingS
postgresSetting *PostgresSettingS
sqlite3Setting *Sqlite3SettingS
redisSetting *RedisSettingS
features *FeaturesSettingS
DatabaseSetting *DatabaseSetingS
MysqlSetting *MySQLSettingS
PostgresSetting *PostgresSettingS
Sqlite3Setting *Sqlite3SettingS
ServerSetting *ServerSettingS
AppSetting *AppSettingS
CacheIndexSetting *CacheIndexSettingS
@ -61,10 +61,10 @@ func setupSetting(suite []string, noDefault bool) error {
"LoggerFile": &loggerFileSetting,
"LoggerZinc": &loggerZincSetting,
"LoggerMeili": &loggerMeiliSetting,
"Database": &databaseSetting,
"MySQL": &mysqlSetting,
"Postgres": &postgresSetting,
"Sqlite3": &sqlite3Setting,
"Database": &DatabaseSetting,
"MySQL": &MysqlSetting,
"Postgres": &PostgresSetting,
"Sqlite3": &Sqlite3Setting,
"TweetSearch": &TweetSearchSetting,
"Zinc": &ZincSetting,
"Meili": &MeiliSetting,

@ -24,7 +24,7 @@ func newDBEngine() (*gorm.DB, error) {
logrus.StandardLogger(), // io writer日志输出的目标前缀和日志包含的内容
logger.Config{
SlowThreshold: time.Second, // 慢 SQL 阈值
LogLevel: databaseSetting.logLevel(), // 日志级别
LogLevel: DatabaseSetting.logLevel(), // 日志级别
IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound记录未找到错误
Colorful: false, // 禁用彩色打印
},
@ -33,7 +33,7 @@ func newDBEngine() (*gorm.DB, error) {
config := &gorm.Config{
Logger: newLogger,
NamingStrategy: schema.NamingStrategy{
TablePrefix: databaseSetting.TablePrefix,
TablePrefix: DatabaseSetting.TablePrefix,
SingularTable: true,
},
}
@ -41,27 +41,27 @@ func newDBEngine() (*gorm.DB, error) {
plugin := dbresolver.Register(dbresolver.Config{}).
SetConnMaxIdleTime(time.Hour).
SetConnMaxLifetime(24 * time.Hour).
SetMaxIdleConns(mysqlSetting.MaxIdleConns).
SetMaxOpenConns(mysqlSetting.MaxOpenConns)
SetMaxIdleConns(MysqlSetting.MaxIdleConns).
SetMaxOpenConns(MysqlSetting.MaxOpenConns)
var (
db *gorm.DB
err error
)
if CfgIf("MySQL") {
logrus.Debugf("use MySQL as db dsn: %s", mysqlSetting.Dsn())
if db, err = gorm.Open(mysql.Open(mysqlSetting.Dsn()), config); err == nil {
logrus.Debugln("use MySQL as db")
if db, err = gorm.Open(mysql.Open(MysqlSetting.Dsn()), config); err == nil {
db.Use(plugin)
}
} else if CfgIf("Postgres") {
logrus.Debugf("use PostgreSQL as db dsn: %s", postgresSetting.Dsn())
db, err = gorm.Open(postgres.Open(postgresSetting.Dsn()), config)
logrus.Debugln("use PostgreSQL as db")
db, err = gorm.Open(postgres.Open(PostgresSetting.Dsn()), config)
} else if CfgIf("Sqlite3") {
logrus.Debugf("use Sqlite3 as db path: %s", sqlite3Setting.Path)
db, err = gorm.Open(sqlite.Open(sqlite3Setting.Path), config)
logrus.Debugf("use Sqlite3 as db dsn: %s", Sqlite3Setting.Dsn())
db, err = gorm.Open(sqlite.Open(Sqlite3Setting.Dsn()), config)
} else {
logrus.Debugf("use default of MySQL as db dsn: %s", mysqlSetting.Dsn())
if db, err = gorm.Open(mysql.Open(mysqlSetting.Dsn()), config); err == nil {
logrus.Debugln("use default of MySQL as db")
if db, err = gorm.Open(mysql.Open(MysqlSetting.Dsn()), config); err == nil {
db.Use(plugin)
}
}

@ -319,6 +319,10 @@ func (s PostgresSettingS) Dsn() string {
return strings.Join(params, " ")
}
func (s *Sqlite3SettingS) Dsn() string {
return "file:" + s.Path + "?cache=shared&mode=rwc"
}
func (s *DatabaseSetingS) logLevel() logger.LogLevel {
switch strings.ToLower(s.LogLevel) {
case "silent":

@ -1,11 +1,16 @@
package internal
import (
"github.com/rocboss/paopao-ce/internal/migration"
"github.com/rocboss/paopao-ce/internal/routers/api"
"github.com/rocboss/paopao-ce/internal/service"
)
func Initialize() {
// migrate database if needed
migration.Run()
// initialize service
service.Initialize()
api.Initialize()
}

@ -0,0 +1,15 @@
//go:build !migration
// +build !migration
package migration
import (
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/sirupsen/logrus"
)
func Run() {
if conf.CfgIf("Migration") {
logrus.Infoln("want migrate feature but not support in this compile version")
}
}

@ -0,0 +1,88 @@
//go:build migration
// +build migration
package migration
import (
"database/sql"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/golang-migrate/migrate/v4/database/mysql"
"github.com/golang-migrate/migrate/v4/database/postgres"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
"github.com/golang-migrate/migrate/v4/source"
"github.com/golang-migrate/migrate/v4/source/iofs"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/scripts/migration"
"github.com/sirupsen/logrus"
)
func Run() {
if !conf.CfgIf("Migration") {
logrus.Infoln("skip migrate because not add Migration feature in config.yaml")
return
}
var (
db *sql.DB
dbName string
dbDriver database.Driver
srcDriver source.Driver
err, err2 error
)
if conf.CfgIf("MySQL") {
dbName = conf.MysqlSetting.DBName
db, err = sql.Open("mysql", conf.MysqlSetting.Dsn()+"&multiStatements=true")
} else if conf.CfgIf("PostgreSQL") || conf.CfgIf("Postgres") {
dbName = (*conf.PostgresSetting)["DBName"]
db, err = sql.Open("postgres", conf.PostgresSetting.Dsn())
} else if conf.CfgIf("Sqlite3") {
db, err = sql.Open("sqlite3", conf.Sqlite3Setting.Dsn())
} else {
dbName = conf.MysqlSetting.DBName
db, err = sql.Open("mysql", conf.MysqlSetting.Dsn())
}
if err != nil {
logrus.Errorf("initial db for migration failed: %s", err)
return
}
if conf.CfgIf("MySQL") {
srcDriver, err = iofs.New(migration.Files, "mysql")
dbDriver, err2 = mysql.WithInstance(db, &mysql.Config{})
} else if conf.CfgIf("PostgreSQL") || conf.CfgIf("Postgres") {
srcDriver, err = iofs.New(migration.Files, "postgres")
dbDriver, err2 = postgres.WithInstance(db, &postgres.Config{})
} else if conf.CfgIf("Sqlite3") {
srcDriver, err = iofs.New(migration.Files, "sqlite3")
dbDriver, err2 = sqlite3.WithInstance(db, &sqlite3.Config{})
} else {
srcDriver, err = iofs.New(migration.Files, "mysql")
dbDriver, err2 = mysql.WithInstance(db, &mysql.Config{})
}
if err2 != nil {
logrus.Errorf("new database driver failed: %s", err)
return
} else {
defer dbDriver.Close()
}
if err != nil {
logrus.Errorf("new source driver failed: %s", err)
return
}
m, err := migrate.NewWithInstance("iofs", srcDriver, dbName, dbDriver)
if err != nil {
logrus.Errorf("new migrate instance failed: %s", err)
return
}
if err = m.Up(); err != nil && err != migrate.ErrNoChange {
logrus.Errorf("migrate up failed: %s", err)
return
}
logrus.Infoln("migrate up success")
}

@ -0,0 +1,11 @@
//go:build migration
// +build migration
package migration
import (
"embed"
)
//go:embed **/*
var Files embed.FS

@ -1,9 +0,0 @@
-- ----------------------------
-- Table p_post alter add visibility column
-- ----------------------------
ALTER TABLE `p_post` ADD COLUMN `visibility` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '可见性 0公开 1私密 2好友可见';
-- ----------------------------
-- Indexes structure for table p_post
-- ----------------------------
CREATE INDEX `idx_visibility` ON `p_post` ( `visibility` ) USING BTREE;

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS `p_attachment`;
DROP TABLE IF EXISTS `p_captcha`;
DROP TABLE IF EXISTS `p_comment`;
DROP TABLE IF EXISTS `p_comment_content`;
DROP TABLE IF EXISTS `p_comment_reply`;
DROP TABLE IF EXISTS `p_message`;
DROP TABLE IF EXISTS `p_post`;
DROP TABLE IF EXISTS `p_post_attachment_bill`;
DROP TABLE IF EXISTS `p_post_collection`;
DROP TABLE IF EXISTS `p_post_content`;
DROP TABLE IF EXISTS `p_post_star`;
DROP TABLE IF EXISTS `p_tag`;
DROP TABLE IF EXISTS `p_user`;
DROP TABLE IF EXISTS `p_wallet_recharge`;
DROP TABLE IF EXISTS `p_wallet_statement`;

@ -1,10 +1,6 @@
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for p_attachment
-- ----------------------------
DROP TABLE IF EXISTS `p_attachment`;
CREATE TABLE `p_attachment` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint unsigned NOT NULL DEFAULT '0',
@ -21,10 +17,6 @@ CREATE TABLE `p_attachment` (
KEY `idx_user` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=100041 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='附件';
-- ----------------------------
-- Table structure for p_captcha
-- ----------------------------
DROP TABLE IF EXISTS `p_captcha`;
CREATE TABLE `p_captcha` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '验证码ID',
`phone` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '手机号',
@ -41,10 +33,6 @@ CREATE TABLE `p_captcha` (
KEY `idx_use_times` (`use_times`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1021 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='手机验证码';
-- ----------------------------
-- Table structure for p_comment
-- ----------------------------
DROP TABLE IF EXISTS `p_comment`;
CREATE TABLE `p_comment` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '评论ID',
`post_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'POST ID',
@ -60,10 +48,6 @@ CREATE TABLE `p_comment` (
KEY `idx_user` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=6001736 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='评论';
-- ----------------------------
-- Table structure for p_comment_content
-- ----------------------------
DROP TABLE IF EXISTS `p_comment_content`;
CREATE TABLE `p_comment_content` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '内容ID',
`comment_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '评论ID',
@ -82,10 +66,6 @@ CREATE TABLE `p_comment_content` (
KEY `idx_sort` (`sort`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=11001738 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='评论内容';
-- ----------------------------
-- Table structure for p_comment_reply
-- ----------------------------
DROP TABLE IF EXISTS `p_comment_reply`;
CREATE TABLE `p_comment_reply` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '回复ID',
`comment_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '评论ID',
@ -102,10 +82,6 @@ CREATE TABLE `p_comment_reply` (
KEY `idx_comment` (`comment_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=12000015 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='评论回复';
-- ----------------------------
-- Table structure for p_message
-- ----------------------------
DROP TABLE IF EXISTS `p_message`;
CREATE TABLE `p_message` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '消息通知ID',
`sender_user_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '发送方用户ID',
@ -127,10 +103,6 @@ CREATE TABLE `p_message` (
KEY `idx_type` (`type`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=16000033 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='消息通知';
-- ----------------------------
-- Table structure for p_post
-- ----------------------------
DROP TABLE IF EXISTS `p_post`;
CREATE TABLE `p_post` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主题ID',
`user_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
@ -153,10 +125,6 @@ CREATE TABLE `p_post` (
KEY `idx_user` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1080017989 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='冒泡/文章';
-- ----------------------------
-- Table structure for p_post_attachment_bill
-- ----------------------------
DROP TABLE IF EXISTS `p_post_attachment_bill`;
CREATE TABLE `p_post_attachment_bill` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '购买记录ID',
`post_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'POST ID',
@ -171,10 +139,6 @@ CREATE TABLE `p_post_attachment_bill` (
KEY `idx_user` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=5000002 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='冒泡/文章附件账单';
-- ----------------------------
-- Table structure for p_post_collection
-- ----------------------------
DROP TABLE IF EXISTS `p_post_collection`;
CREATE TABLE `p_post_collection` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '收藏ID',
`post_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'POST ID',
@ -188,10 +152,6 @@ CREATE TABLE `p_post_collection` (
KEY `idx_user` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=6000012 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='冒泡/文章收藏';
-- ----------------------------
-- Table structure for p_post_content
-- ----------------------------
DROP TABLE IF EXISTS `p_post_content`;
CREATE TABLE `p_post_content` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '内容ID',
`post_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'POST ID',
@ -208,10 +168,6 @@ CREATE TABLE `p_post_content` (
KEY `idx_user` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=180022546 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='冒泡/文章内容';
-- ----------------------------
-- Table structure for p_post_star
-- ----------------------------
DROP TABLE IF EXISTS `p_post_star`;
CREATE TABLE `p_post_star` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '收藏ID',
`post_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'POST ID',
@ -225,10 +181,6 @@ CREATE TABLE `p_post_star` (
KEY `idx_user` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=6000028 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='冒泡/文章点赞';
-- ----------------------------
-- Table structure for p_tag
-- ----------------------------
DROP TABLE IF EXISTS `p_tag`;
CREATE TABLE `p_tag` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '标签ID',
`user_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '创建者ID',
@ -244,10 +196,6 @@ CREATE TABLE `p_tag` (
KEY `idx_num` (`quote_num`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=9000065 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='标签';
-- ----------------------------
-- Table structure for p_user
-- ----------------------------
DROP TABLE IF EXISTS `p_user`;
CREATE TABLE `p_user` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`nickname` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '昵称',
@ -268,10 +216,6 @@ 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_wallet_recharge
-- ----------------------------
DROP TABLE IF EXISTS `p_wallet_recharge`;
CREATE TABLE `p_wallet_recharge` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '充值ID',
`user_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
@ -288,10 +232,6 @@ CREATE TABLE `p_wallet_recharge` (
KEY `idx_trade_status` (`trade_status`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=10023 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='钱包流水';
-- ----------------------------
-- Table structure for p_wallet_statement
-- ----------------------------
DROP TABLE IF EXISTS `p_wallet_statement`;
CREATE TABLE `p_wallet_statement` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '账单ID',
`user_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',

@ -0,0 +1,3 @@
ALTER TABLE `p_post` DROP COLUMN `visibility`;
DROP INDEX `idx_visibility` ON `p_post`;

@ -0,0 +1,3 @@
ALTER TABLE `p_post` ADD COLUMN `visibility` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '可见性 0公开 1私密 2好友可见';
CREATE INDEX `idx_visibility` ON `p_post` ( `visibility` ) USING BTREE;

@ -1,12 +0,0 @@
-- ----------------------------
-- Table p_post alter add visibility column
-- ----------------------------
ALTER TABLE `p_post` ADD COLUMN `visibility` integer NOT NULL DEFAULT '0';
-- ----------------------------
-- Indexes structure for table p_post
-- ----------------------------
CREATE INDEX "main"."idx_visibility"
ON "p_post" (
"visibility" ASC
);

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS "p_attachment";
DROP TABLE IF EXISTS "p_captcha";
DROP TABLE IF EXISTS "p_comment";
DROP TABLE IF EXISTS "p_comment_content";
DROP TABLE IF EXISTS "p_comment_reply";
DROP TABLE IF EXISTS "p_message";
DROP TABLE IF EXISTS "p_post";
DROP TABLE IF EXISTS "p_post_attachment_bill";
DROP TABLE IF EXISTS "p_post_collection";
DROP TABLE IF EXISTS "p_post_content";
DROP TABLE IF EXISTS "p_post_star";
DROP TABLE IF EXISTS "p_tag";
DROP TABLE IF EXISTS "p_user";
DROP TABLE IF EXISTS "p_wallet_recharge";
DROP TABLE IF EXISTS "p_wallet_statement";

@ -1,9 +1,3 @@
PRAGMA foreign_keys = false;
-- ----------------------------
-- Table structure for p_attachment
-- ----------------------------
DROP TABLE IF EXISTS "p_attachment";
CREATE TABLE "p_attachment" (
"id" integer NOT NULL,
"user_id" integer NOT NULL,
@ -19,10 +13,6 @@ CREATE TABLE "p_attachment" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_captcha
-- ----------------------------
DROP TABLE IF EXISTS "p_captcha";
CREATE TABLE "p_captcha" (
"id" integer NOT NULL,
"phone" text(16) NOT NULL,
@ -36,10 +26,6 @@ CREATE TABLE "p_captcha" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_comment
-- ----------------------------
DROP TABLE IF EXISTS "p_comment";
CREATE TABLE "p_comment" (
"id" integer NOT NULL,
"post_id" integer NOT NULL,
@ -53,10 +39,6 @@ CREATE TABLE "p_comment" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_comment_content
-- ----------------------------
DROP TABLE IF EXISTS "p_comment_content";
CREATE TABLE "p_comment_content" (
"id" integer NOT NULL,
"comment_id" integer NOT NULL,
@ -71,10 +53,6 @@ CREATE TABLE "p_comment_content" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_comment_reply
-- ----------------------------
DROP TABLE IF EXISTS "p_comment_reply";
CREATE TABLE "p_comment_reply" (
"id" integer NOT NULL,
"comment_id" integer NOT NULL,
@ -90,10 +68,6 @@ CREATE TABLE "p_comment_reply" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_message
-- ----------------------------
DROP TABLE IF EXISTS "p_message";
CREATE TABLE "p_message" (
"id" integer NOT NULL,
"sender_user_id" integer NOT NULL,
@ -112,10 +86,6 @@ CREATE TABLE "p_message" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_post
-- ----------------------------
DROP TABLE IF EXISTS "p_post";
CREATE TABLE "p_post" (
"id" integer NOT NULL,
"user_id" integer NOT NULL,
@ -137,10 +107,6 @@ CREATE TABLE "p_post" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_post_attachment_bill
-- ----------------------------
DROP TABLE IF EXISTS "p_post_attachment_bill";
CREATE TABLE "p_post_attachment_bill" (
"id" integer NOT NULL,
"post_id" integer NOT NULL,
@ -153,10 +119,6 @@ CREATE TABLE "p_post_attachment_bill" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_post_collection
-- ----------------------------
DROP TABLE IF EXISTS "p_post_collection";
CREATE TABLE "p_post_collection" (
"id" integer NOT NULL,
"post_id" integer NOT NULL,
@ -168,10 +130,6 @@ CREATE TABLE "p_post_collection" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_post_content
-- ----------------------------
DROP TABLE IF EXISTS "p_post_content";
CREATE TABLE "p_post_content" (
"id" integer NOT NULL,
"post_id" integer NOT NULL,
@ -186,10 +144,6 @@ CREATE TABLE "p_post_content" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_post_star
-- ----------------------------
DROP TABLE IF EXISTS "p_post_star";
CREATE TABLE "p_post_star" (
"id" integer NOT NULL,
"post_id" integer NOT NULL,
@ -201,10 +155,6 @@ CREATE TABLE "p_post_star" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_tag
-- ----------------------------
DROP TABLE IF EXISTS "p_tag";
CREATE TABLE "p_tag" (
"id" integer NOT NULL,
"user_id" integer NOT NULL,
@ -217,10 +167,6 @@ CREATE TABLE "p_tag" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_user
-- ----------------------------
DROP TABLE IF EXISTS "p_user";
CREATE TABLE "p_user" (
"id" integer NOT NULL,
"nickname" text(32) NOT NULL,
@ -239,10 +185,6 @@ CREATE TABLE "p_user" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_wallet_recharge
-- ----------------------------
DROP TABLE IF EXISTS "p_wallet_recharge";
CREATE TABLE "p_wallet_recharge" (
"id" integer NOT NULL,
"user_id" integer NOT NULL,
@ -256,10 +198,6 @@ CREATE TABLE "p_wallet_recharge" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Table structure for p_wallet_statement
-- ----------------------------
DROP TABLE IF EXISTS "p_wallet_statement";
CREATE TABLE "p_wallet_statement" (
"id" integer NOT NULL,
"user_id" integer NOT NULL,
@ -274,36 +212,27 @@ CREATE TABLE "p_wallet_statement" (
PRIMARY KEY ("id")
);
-- ----------------------------
-- Indexes structure for table p_attachment
-- ----------------------------
CREATE INDEX "main"."idx_user"
ON "p_attachment" (
"user_id" ASC
);
-- ----------------------------
-- Indexes structure for table p_captcha
-- ----------------------------
CREATE INDEX "main"."idx_expired_on"
ON "p_captcha" (
"expired_on" ASC
);
CREATE INDEX "main"."idx_phone"
ON "p_captcha" (
"phone" ASC
);
CREATE INDEX "main"."idx_use_times"
ON "p_captcha" (
"use_times" ASC
);
-- ----------------------------
-- Indexes structure for table p_comment
-- ----------------------------
CREATE INDEX "main"."idx_post"
ON "p_comment" (
"post_id" ASC
);
PRAGMA foreign_keys = true;

@ -0,0 +1,3 @@
ALTER TABLE `p_post` DROP COLUMN `visibility` integer NOT NULL DEFAULT '0';
DROP INDEX "main"."idx_visibility" ON "p_post"

@ -0,0 +1,6 @@
ALTER TABLE `p_post` ADD COLUMN `visibility` integer NOT NULL DEFAULT '0';
CREATE INDEX "main"."idx_visibility"
ON "p_post" (
"visibility" ASC
);
Loading…
Cancel
Save