mirror of https://gitee.com/answerdev/answer.git
feat: remove database field comments for support multiple databases
This commit is contained in:
parent
18d1688363
commit
cb03804f09
|
@ -9,16 +9,16 @@ const (
|
|||
|
||||
// Activity activity
|
||||
type Activity struct {
|
||||
ID string `xorm:"not null pk autoincr comment('activity id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null comment('the user ID that generated the activity or affected by the activity') index BIGINT(20) user_id"`
|
||||
TriggerUserID int64 `xorm:"not null default 0 comment('the trigger user ID that generated the activity or affected by the activity') index BIGINT(20) trigger_user_id"`
|
||||
ObjectID string `xorm:"not null default 0 comment('the object ID that affected by the activity') index BIGINT(20) object_id"`
|
||||
ActivityType int `xorm:"not null comment('activity type, correspond to config id') INT(11) activity_type"`
|
||||
Cancelled int `xorm:"not null default 0 comment('mark this activity if cancelled or not,default 0(not cancelled)') TINYINT(4) cancelled"`
|
||||
Rank int `xorm:"not null default 0 comment('rank of current operating user affected') INT(11) rank"`
|
||||
HasRank int `xorm:"not null default 0 comment('this activity has rank or not') TINYINT(4) has_rank"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null index BIGINT(20) user_id"`
|
||||
TriggerUserID int64 `xorm:"not null default 0 index BIGINT(20) trigger_user_id"`
|
||||
ObjectID string `xorm:"not null default 0 index BIGINT(20) object_id"`
|
||||
ActivityType int `xorm:"not null INT(11) activity_type"`
|
||||
Cancelled int `xorm:"not null default 0 TINYINT(4) cancelled"`
|
||||
Rank int `xorm:"not null default 0 INT(11) rank"`
|
||||
HasRank int `xorm:"not null default 0 TINYINT(4) has_rank"`
|
||||
}
|
||||
|
||||
type ActivityRunkSum struct {
|
||||
|
|
|
@ -18,18 +18,18 @@ var CmsAnswerSearchStatus = map[string]int{
|
|||
|
||||
// Answer answer
|
||||
type Answer struct {
|
||||
ID string `xorm:"not null pk autoincr comment('answer id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP comment('update time') TIMESTAMP updated_at"`
|
||||
QuestionID string `xorm:"not null default 0 comment('question id') BIGINT(20) question_id"`
|
||||
UserID string `xorm:"not null default 0 comment('answer user id') BIGINT(20) INDEX user_id"`
|
||||
OriginalText string `xorm:"not null comment('original text') MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null comment('parsed text') MEDIUMTEXT parsed_text"`
|
||||
Status int `xorm:"not null default 1 comment('answer status(available: 1; deleted: 10)') INT(11) status"`
|
||||
Adopted int `xorm:"not null default 1 comment('adopted (1 failed 2 adopted)') INT(11) adopted"`
|
||||
CommentCount int `xorm:"not null default 0 comment('comment count') INT(11) comment_count"`
|
||||
VoteCount int `xorm:"not null default 0 comment('vote count') INT(11) vote_count"`
|
||||
RevisionID string `xorm:"not null default 0 comment('revision id') BIGINT(20) revision_id"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP updated_at"`
|
||||
QuestionID string `xorm:"not null default 0 BIGINT(20) question_id"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`
|
||||
OriginalText string `xorm:"not null MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
Adopted int `xorm:"not null default 1 INT(11) adopted"`
|
||||
CommentCount int `xorm:"not null default 0 INT(11) comment_count"`
|
||||
VoteCount int `xorm:"not null default 0 INT(11) vote_count"`
|
||||
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
|
||||
}
|
||||
|
||||
type AnswerSearch struct {
|
||||
|
|
|
@ -4,12 +4,12 @@ import "time"
|
|||
|
||||
// Collection collection
|
||||
type Collection struct {
|
||||
ID string `xorm:"not null pk default 0 comment('collection id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP comment('created time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated not null default CURRENT_TIMESTAMP comment('updated time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 comment('user id') BIGINT(20) INDEX user_id"`
|
||||
ObjectID string `xorm:"not null default 0 comment('object id') BIGINT(20) object_id"`
|
||||
UserCollectionGroupID string `xorm:"not null default 0 comment('user collection group id') BIGINT(20) user_collection_group_id"`
|
||||
ID string `xorm:"not null pk default 0 BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated not null default CURRENT_TIMESTAMP TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`
|
||||
ObjectID string `xorm:"not null default 0 BIGINT(20) object_id"`
|
||||
UserCollectionGroupID string `xorm:"not null default 0 BIGINT(20) user_collection_group_id"`
|
||||
}
|
||||
|
||||
type CollectionSearch struct {
|
||||
|
|
|
@ -4,12 +4,12 @@ import "time"
|
|||
|
||||
// CollectionGroup collection group
|
||||
type CollectionGroup struct {
|
||||
ID string `xorm:"not null pk autoincr comment('id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP comment('created time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated not null default CURRENT_TIMESTAMP comment('updated time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) comment('user id') INDEX user_id"`
|
||||
Name string `xorm:"not null default '' comment('the collection group name') VARCHAR(50) name"`
|
||||
DefaultGroup int `xorm:"not null default 1 comment('mark this group is default, default 1') INT(11) default_group"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated not null default CURRENT_TIMESTAMP TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`
|
||||
Name string `xorm:"not null default '' VARCHAR(50) name"`
|
||||
DefaultGroup int `xorm:"not null default 1 INT(11) default_group"`
|
||||
}
|
||||
|
||||
// TableName collection group table name
|
||||
|
|
|
@ -15,18 +15,18 @@ const (
|
|||
|
||||
// Comment comment
|
||||
type Comment struct {
|
||||
ID string `xorm:"not null pk autoincr comment('comment id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 comment('user id') BIGINT(20) user_id"`
|
||||
ReplyUserID sql.NullInt64 `xorm:"comment('reply user id') BIGINT(20) reply_user_id"`
|
||||
ReplyCommentID sql.NullInt64 `xorm:"comment('reply comment id') BIGINT(20) reply_comment_id"`
|
||||
ObjectID string `xorm:"not null default 0 comment('object id') BIGINT(20) INDEX object_id"`
|
||||
QuestionID string `xorm:"not null default 0 comment('question id') BIGINT(20) question_id"`
|
||||
VoteCount int `xorm:"not null default 0 comment('user vote amount') INT(11) vote_count"`
|
||||
Status int `xorm:"not null default 0 comment('comment status(available: 1; deleted: 10)') TINYINT(4) status"`
|
||||
OriginalText string `xorm:"not null comment('original comment content') MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null comment('parsed comment content') MEDIUMTEXT parsed_text"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) user_id"`
|
||||
ReplyUserID sql.NullInt64 `xorm:"BIGINT(20) reply_user_id"`
|
||||
ReplyCommentID sql.NullInt64 `xorm:"BIGINT(20) reply_comment_id"`
|
||||
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
|
||||
QuestionID string `xorm:"not null default 0 BIGINT(20) question_id"`
|
||||
VoteCount int `xorm:"not null default 0 INT(11) vote_count"`
|
||||
Status int `xorm:"not null default 0 TINYINT(4) status"`
|
||||
OriginalText string `xorm:"not null MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`
|
||||
}
|
||||
|
||||
// TableName comment table name
|
||||
|
|
|
@ -2,9 +2,9 @@ package entity
|
|||
|
||||
// Config config
|
||||
type Config struct {
|
||||
ID int `xorm:"not null pk autoincr comment('config id') INT(11) id"`
|
||||
Key string `xorm:"comment('the config key') unique VARCHAR(32) key"`
|
||||
Value string `xorm:"comment('the config value, custom data structures and types') TEXT value"`
|
||||
ID int `xorm:"not null pk autoincr INT(11) id"`
|
||||
Key string `xorm:"unique VARCHAR(32) key"`
|
||||
Value string `xorm:"TEXT value"`
|
||||
}
|
||||
|
||||
// TableName config table name
|
||||
|
|
|
@ -11,12 +11,12 @@ const (
|
|||
|
||||
// Meta meta
|
||||
type Meta struct {
|
||||
ID int `xorm:"not null pk autoincr comment('id') INT(10) id"`
|
||||
CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP created comment('created time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP updated comment('updated time') TIMESTAMP updated_at"`
|
||||
ObjectID string `xorm:"not null default 0 comment('object id') INDEX BIGINT(20) object_id"`
|
||||
Key string `xorm:"not null comment('key') VARCHAR(100) key"`
|
||||
Value string `xorm:"not null comment('value') MEDIUMTEXT value"`
|
||||
ID int `xorm:"not null pk autoincr INT(10) id"`
|
||||
CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP updated TIMESTAMP updated_at"`
|
||||
ObjectID string `xorm:"not null default 0 INDEX BIGINT(20) object_id"`
|
||||
Key string `xorm:"not null VARCHAR(100) key"`
|
||||
Value string `xorm:"not null MEDIUMTEXT value"`
|
||||
}
|
||||
|
||||
// TableName meta table name
|
||||
|
|
|
@ -4,15 +4,15 @@ import "time"
|
|||
|
||||
// Notification notification
|
||||
type Notification struct {
|
||||
ID string `xorm:"not null pk autoincr comment('notification id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"comment('update time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 comment('user id') BIGINT(20) INDEX user_id"`
|
||||
ObjectID string `xorm:"not null default 0 comment('object id') INDEX BIGINT(20) object_id"`
|
||||
Content string `xorm:"not null comment('notification content') TEXT content"`
|
||||
Type int `xorm:"not null default 0 comment('notification type(1:inbox; 2:achievement)') INT(11) type"`
|
||||
IsRead int `xorm:"not null default 1 comment('read status(unread: 1; read 2)') INT(11) is_read"`
|
||||
Status int `xorm:"not null default 1 comment('notification status(normal: 1; delete 2)') INT(11) status"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`
|
||||
ObjectID string `xorm:"not null default 0 INDEX BIGINT(20) object_id"`
|
||||
Content string `xorm:"not null TEXT content"`
|
||||
Type int `xorm:"not null default 0 INT(11) type"`
|
||||
IsRead int `xorm:"not null default 1 INT(11) is_read"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
}
|
||||
|
||||
// TableName notification table name
|
||||
|
|
|
@ -29,24 +29,24 @@ type QuestionTag struct {
|
|||
|
||||
// Question question
|
||||
type Question struct {
|
||||
ID string `xorm:"not null pk comment('question id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP comment('update time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 comment('user id') BIGINT(20) INDEX user_id"`
|
||||
Title string `xorm:"not null default '' comment('question title') VARCHAR(150) title"`
|
||||
OriginalText string `xorm:"not null comment('original text') MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null comment('parsed text') MEDIUMTEXT parsed_text"`
|
||||
Status int `xorm:"not null default 1 comment('question status(available: 1; deleted: 10)') INT(11) status"`
|
||||
ViewCount int `xorm:"not null default 0 comment('view count') INT(11) view_count"`
|
||||
UniqueViewCount int `xorm:"not null default 0 comment('unique view count') INT(11) unique_view_count"`
|
||||
VoteCount int `xorm:"not null default 0 comment('vote count') INT(11) vote_count"`
|
||||
AnswerCount int `xorm:"not null default 0 comment('answer count') INT(11) answer_count"`
|
||||
CollectionCount int `xorm:"not null default 0 comment('collection count') INT(11) collection_count"`
|
||||
FollowCount int `xorm:"not null default 0 comment('follow count') INT(11) follow_count"`
|
||||
AcceptedAnswerID string `xorm:"not null default 0 comment('accepted answer id') BIGINT(20) accepted_answer_id"`
|
||||
LastAnswerID string `xorm:"not null default 0 comment('last answer id') BIGINT(20) last_answer_id"`
|
||||
PostUpdateTime time.Time `xorm:"default CURRENT_TIMESTAMP comment('answer the last update time') TIMESTAMP post_update_time"`
|
||||
RevisionID string `xorm:"not null default 0 comment('revision id') BIGINT(20) revision_id"`
|
||||
ID string `xorm:"not null pk BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`
|
||||
Title string `xorm:"not null default '' VARCHAR(150) title"`
|
||||
OriginalText string `xorm:"not null MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
ViewCount int `xorm:"not null default 0 INT(11) view_count"`
|
||||
UniqueViewCount int `xorm:"not null default 0 INT(11) unique_view_count"`
|
||||
VoteCount int `xorm:"not null default 0 INT(11) vote_count"`
|
||||
AnswerCount int `xorm:"not null default 0 INT(11) answer_count"`
|
||||
CollectionCount int `xorm:"not null default 0 INT(11) collection_count"`
|
||||
FollowCount int `xorm:"not null default 0 INT(11) follow_count"`
|
||||
AcceptedAnswerID string `xorm:"not null default 0 BIGINT(20) accepted_answer_id"`
|
||||
LastAnswerID string `xorm:"not null default 0 BIGINT(20) last_answer_id"`
|
||||
PostUpdateTime time.Time `xorm:"default CURRENT_TIMESTAMP TIMESTAMP post_update_time"`
|
||||
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
|
||||
}
|
||||
|
||||
// TableName question table name
|
||||
|
|
|
@ -18,18 +18,18 @@ var (
|
|||
|
||||
// Report report
|
||||
type Report struct {
|
||||
ID string `xorm:"not null pk autoincr comment('id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null comment('reporter user id') BIGINT(20) user_id"`
|
||||
ObjectID string `xorm:"not null comment('object id') BIGINT(20) object_id"`
|
||||
ReportedUserID string `xorm:"not null default 0 comment('reported user id') BIGINT(20) reported_user_id"`
|
||||
ObjectType int `xorm:"not null default 0 comment('revision type') INT(11) object_type"`
|
||||
ReportType int `xorm:"not null default 0 comment('report type') INT(11) report_type"`
|
||||
Content string `xorm:"not null comment('report content') TEXT content"`
|
||||
FlaggedType int `xorm:"not null default 0 comment('flagged type') INT(11) flagged_type"`
|
||||
FlaggedContent string `xorm:"comment('flagged content') TEXT flagged_content"`
|
||||
Status int `xorm:"not null default 1 comment('status(normal: 1; pending:2; delete: 10)') INT(11) status"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null BIGINT(20) user_id"`
|
||||
ObjectID string `xorm:"not null BIGINT(20) object_id"`
|
||||
ReportedUserID string `xorm:"not null default 0 BIGINT(20) reported_user_id"`
|
||||
ObjectType int `xorm:"not null default 0 INT(11) object_type"`
|
||||
ReportType int `xorm:"not null default 0 INT(11) report_type"`
|
||||
Content string `xorm:"not null TEXT content"`
|
||||
FlaggedType int `xorm:"not null default 0 INT(11) flagged_type"`
|
||||
FlaggedContent string `xorm:"TEXT flagged_content"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
}
|
||||
|
||||
// TableName report table name
|
||||
|
|
|
@ -4,16 +4,16 @@ import "time"
|
|||
|
||||
// Revision revision
|
||||
type Revision struct {
|
||||
ID string `xorm:"not null pk autoincr comment('id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 comment('user id') BIGINT(20) user_id"`
|
||||
ObjectType int `xorm:"not null default 0 comment('revision type(question: 1; answer 2; tag 3)') INT(11) object_type"`
|
||||
ObjectID string `xorm:"not null default 0 comment('object id') BIGINT(20) INDEX object_id"`
|
||||
Title string `xorm:"not null default '' comment('title') VARCHAR(255) title"`
|
||||
Content string `xorm:"not null comment('content') TEXT content"`
|
||||
Log string `xorm:"comment('log') VARCHAR(255) log"`
|
||||
Status int `xorm:"not null default 1 comment('revision status(normal: 1; delete 2)') INT(11) status"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
UserID string `xorm:"not null default 0 BIGINT(20) user_id"`
|
||||
ObjectType int `xorm:"not null default 0 ) INT(11) object_type"`
|
||||
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
|
||||
Title string `xorm:"not null default '' VARCHAR(255) title"`
|
||||
Content string `xorm:"not null TEXT content"`
|
||||
Log string `xorm:"VARCHAR(255) log"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
}
|
||||
|
||||
// TableName revision table name
|
||||
|
|
|
@ -4,12 +4,12 @@ import "time"
|
|||
|
||||
// SiteInfo site information setting
|
||||
type SiteInfo struct {
|
||||
ID string `xorm:"not null pk autoincr comment('id') INT(11) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
Type string `xorm:"not null comment('type') VARCHAR(64) type"`
|
||||
Content string `xorm:"not null comment('content') MEDIUMTEXT content"`
|
||||
Status int `xorm:"not null default 1 comment('site info status(available: 1; deleted: 10)') INT(11) status"`
|
||||
ID string `xorm:"not null pk autoincr INT(11) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
Type string `xorm:"not null VARCHAR(64) type"`
|
||||
Content string `xorm:"not null MEDIUMTEXT content"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
}
|
||||
|
||||
// TableName table name
|
||||
|
|
|
@ -10,18 +10,18 @@ const (
|
|||
// Tag tag
|
||||
type Tag struct {
|
||||
ID string `xorm:"not null pk comment('tag_id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
MainTagID int64 `xorm:"not null default 0 comment('main tag id') BIGINT(20) main_tag_id"`
|
||||
MainTagSlugName string `xorm:"not null default '' comment('main tag slug name') VARCHAR(35) main_tag_slug_name"`
|
||||
SlugName string `xorm:"not null default '' comment('slug name') unique VARCHAR(35) slug_name"`
|
||||
DisplayName string `xorm:"not null default '' comment('display name') VARCHAR(35) display_name"`
|
||||
OriginalText string `xorm:"not null comment('original comment content') MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null comment('parsed comment content') MEDIUMTEXT parsed_text"`
|
||||
FollowCount int `xorm:"not null default 0 comment('associated follow count') INT(11) follow_count"`
|
||||
QuestionCount int `xorm:"not null default 0 comment('associated question count') INT(11) question_count"`
|
||||
Status int `xorm:"not null default 1 comment('tag status(available: 1; deleted: 10)') INT(11) status"`
|
||||
RevisionID string `xorm:"not null default 0 comment('revision id') BIGINT(20) revision_id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
MainTagID int64 `xorm:"not null default 0 BIGINT(20) main_tag_id"`
|
||||
MainTagSlugName string `xorm:"not null default '' VARCHAR(35) main_tag_slug_name"`
|
||||
SlugName string `xorm:"not null default '' unique VARCHAR(35) slug_name"`
|
||||
DisplayName string `xorm:"not null default '' VARCHAR(35) display_name"`
|
||||
OriginalText string `xorm:"not null MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`
|
||||
FollowCount int `xorm:"not null default 0 INT(11) follow_count"`
|
||||
QuestionCount int `xorm:"not null default 0 INT(11) question_count"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
|
||||
}
|
||||
|
||||
// TableName tag table name
|
||||
|
|
|
@ -9,12 +9,12 @@ const (
|
|||
|
||||
// TagRel tag relation
|
||||
type TagRel struct {
|
||||
ID int64 `xorm:"not null pk autoincr comment('tag_list_id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
ObjectID string `xorm:"not null comment('object_id') INDEX UNIQUE(s) BIGINT(20) object_id"`
|
||||
TagID string `xorm:"not null comment('tag_id') INDEX UNIQUE(s) BIGINT(20) tag_id"`
|
||||
Status int `xorm:"not null default 1 comment('tag_list_status(available: 1; deleted: 10)') INT(11) status"`
|
||||
ID int64 `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
ObjectID string `xorm:"not null INDEX UNIQUE(s) BIGINT(20) object_id"`
|
||||
TagID string `xorm:"not null INDEX UNIQUE(s) BIGINT(20) tag_id"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
}
|
||||
|
||||
// TableName tag list table name
|
||||
|
|
|
@ -2,8 +2,8 @@ package entity
|
|||
|
||||
// Uniqid uniqid
|
||||
type Uniqid struct {
|
||||
ID int64 `xorm:"not null pk autoincr comment('uniqid_id') BIGINT(20) id"`
|
||||
UniqidType int `xorm:"not null default 0 comment('uniqid_type') INT(11) uniqid_type"`
|
||||
ID int64 `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
UniqidType int `xorm:"not null default 0 INT(11) uniqid_type"`
|
||||
}
|
||||
|
||||
// TableName uniqid table name
|
||||
|
|
|
@ -19,32 +19,32 @@ const (
|
|||
|
||||
// User user
|
||||
type User struct {
|
||||
ID string `xorm:"not null pk autoincr comment('user id') BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created comment('create time') TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated comment('update time') TIMESTAMP updated_at"`
|
||||
SuspendedAt time.Time `xorm:"comment('suspended time') TIMESTAMP suspended_at"`
|
||||
DeletedAt time.Time `xorm:"comment('delete time') TIMESTAMP deleted_at"`
|
||||
LastLoginDate time.Time `xorm:"comment('last login date') TIMESTAMP last_login_date"`
|
||||
Username string `xorm:"not null default '' comment('username') VARCHAR(50) UNIQUE username"`
|
||||
Pass string `xorm:"not null default '' comment('password') VARCHAR(255) pass"`
|
||||
EMail string `xorm:"not null comment('email') VARCHAR(100) e_mail"`
|
||||
MailStatus int `xorm:"not null default 2 comment('mail status(1 pass 2 to be verified)') TINYINT(4) mail_status"`
|
||||
NoticeStatus int `xorm:"not null default 2 comment('notice status(1 on 2off)') INT(11) notice_status"`
|
||||
FollowCount int `xorm:"not null default 0 comment('follow count') INT(11) follow_count"`
|
||||
AnswerCount int `xorm:"not null default 0 comment('answer count') INT(11) answer_count"`
|
||||
QuestionCount int `xorm:"not null default 0 comment('question count') INT(11) question_count"`
|
||||
Rank int `xorm:"not null default 0 comment('rank') INT(11) rank"`
|
||||
Status int `xorm:"not null default 1 comment('user status(available: 1; deleted: 10)') INT(11) status"`
|
||||
AuthorityGroup int `xorm:"not null default 1 comment('authority group') INT(11) authority_group"`
|
||||
DisplayName string `xorm:"not null default '' comment('display name') VARCHAR(30) display_name"`
|
||||
Avatar string `xorm:"not null default '' comment('avatar') VARCHAR(255) avatar"`
|
||||
Mobile string `xorm:"not null comment('mobile') VARCHAR(20) mobile"`
|
||||
Bio string `xorm:"not null comment('bio markdown') TEXT bio"`
|
||||
BioHtml string `xorm:"not null comment('bio html') TEXT bio_html"`
|
||||
Website string `xorm:"not null default '' comment('website') VARCHAR(255) website"`
|
||||
Location string `xorm:"not null default '' comment('location') VARCHAR(100) location"`
|
||||
IPInfo string `xorm:"not null default '' comment('ip info') VARCHAR(255) ip_info"`
|
||||
IsAdmin bool `xorm:"not null default 0 comment('admin flag') INT(11) is_admin"`
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||
SuspendedAt time.Time `xorm:"TIMESTAMP suspended_at"`
|
||||
DeletedAt time.Time `xorm:"TIMESTAMP deleted_at"`
|
||||
LastLoginDate time.Time `xorm:"TIMESTAMP last_login_date"`
|
||||
Username string `xorm:"not null default '' VARCHAR(50) UNIQUE username"`
|
||||
Pass string `xorm:"not null default '' VARCHAR(255) pass"`
|
||||
EMail string `xorm:"not null VARCHAR(100) e_mail"`
|
||||
MailStatus int `xorm:"not null default 2 TINYINT(4) mail_status"`
|
||||
NoticeStatus int `xorm:"not null default 2 INT(11) notice_status"`
|
||||
FollowCount int `xorm:"not null default 0 INT(11) follow_count"`
|
||||
AnswerCount int `xorm:"not null default 0 INT(11) answer_count"`
|
||||
QuestionCount int `xorm:"not null default 0 INT(11) question_count"`
|
||||
Rank int `xorm:"not null default 0 INT(11) rank"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
AuthorityGroup int `xorm:"not null default 1 INT(11) authority_group"`
|
||||
DisplayName string `xorm:"not null default '' VARCHAR(30) display_name"`
|
||||
Avatar string `xorm:"not null default '' VARCHAR(255) avatar"`
|
||||
Mobile string `xorm:"not null VARCHAR(20) mobile"`
|
||||
Bio string `xorm:"not null TEXT bio"`
|
||||
BioHtml string `xorm:"not null TEXT bio_html"`
|
||||
Website string `xorm:"not null default '' VARCHAR(255) website"`
|
||||
Location string `xorm:"not null default '' VARCHAR(100) location"`
|
||||
IPInfo string `xorm:"not null default '' VARCHAR(255) ip_info"`
|
||||
IsAdmin bool `xorm:"not null default false BOOL is_admin"`
|
||||
}
|
||||
|
||||
// TableName user table name
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package entity
|
||||
|
||||
// Version version
|
||||
type Version struct {
|
||||
ID int `xorm:"not null pk autoincr INT(11) id"`
|
||||
VersionNumber int64 `xorm:"not null default 0 INT(11) version_number"`
|
||||
}
|
||||
|
||||
// TableName config table name
|
||||
func (Version) TableName() string {
|
||||
return "version"
|
||||
}
|
|
@ -26,7 +26,7 @@ var (
|
|||
&entity.TagRel{},
|
||||
&entity.Uniqid{},
|
||||
&entity.User{},
|
||||
&Version{},
|
||||
&entity.Version{},
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -38,7 +38,7 @@ func InitDB(dataConf *data.Database) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
exist, err := engine.IsTableExist(&Version{})
|
||||
exist, err := engine.IsTableExist(&entity.Version{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("check table exists failed: %s", err)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/segmentfault/answer/internal/base/data"
|
||||
"github.com/segmentfault/answer/internal/entity"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
@ -36,17 +37,6 @@ func NewMigration(desc string, fn func(*xorm.Engine) error) Migration {
|
|||
return &migration{description: desc, migrate: fn}
|
||||
}
|
||||
|
||||
// Version version
|
||||
type Version struct {
|
||||
ID int `xorm:"not null pk autoincr comment('id') INT(11) id"`
|
||||
VersionNumber int64 `xorm:"not null default 0 comment('version_number') INT(11) version_number"`
|
||||
}
|
||||
|
||||
// TableName config table name
|
||||
func (Version) TableName() string {
|
||||
return "version"
|
||||
}
|
||||
|
||||
// Use noopMigration when there is a migration that has been no-oped
|
||||
var noopMigration = func(_ *xorm.Engine) error { return nil }
|
||||
|
||||
|
@ -57,17 +47,17 @@ var migrations = []Migration{
|
|||
|
||||
// GetCurrentDBVersion returns the current db version
|
||||
func GetCurrentDBVersion(engine *xorm.Engine) (int64, error) {
|
||||
if err := engine.Sync(new(Version)); err != nil {
|
||||
if err := engine.Sync(new(entity.Version)); err != nil {
|
||||
return -1, fmt.Errorf("sync version failed: %v", err)
|
||||
}
|
||||
|
||||
currentVersion := &Version{ID: 1}
|
||||
currentVersion := &entity.Version{ID: 1}
|
||||
has, err := engine.Get(currentVersion)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("get first version failed: %v", err)
|
||||
}
|
||||
if !has {
|
||||
_, err := engine.InsertOne(&Version{ID: 1, VersionNumber: 0})
|
||||
_, err := engine.InsertOne(&entity.Version{ID: 1, VersionNumber: 0})
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("insert first version failed: %v", err)
|
||||
}
|
||||
|
@ -105,7 +95,7 @@ func Migrate(dataConf *data.Database) error {
|
|||
return err
|
||||
}
|
||||
log.Infof("[migrate] migrate to db version %d success", currentDBVersion+1)
|
||||
if _, err := engine.Update(&Version{ID: 1, VersionNumber: currentDBVersion + 1}); err != nil {
|
||||
if _, err := engine.Update(&entity.Version{ID: 1, VersionNumber: currentDBVersion + 1}); err != nil {
|
||||
log.Errorf("[migrate] migrate to db version %d, update failed: %s", currentDBVersion+1, err.Error())
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue