Skip to content

Commit d65fcaa

Browse files
committed
🎨 Add db index
1 parent 01e7095 commit d65fcaa

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎model/article.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Article struct {
2828
Title string `gorm:"size:128" json:"title"`
2929
Tags string `gorm:"size:128" json:"tags"`
3030
Content string `gorm:"type:text" json:"content"`
31-
Path string `gorm:"size:255" json:"path"`
31+
Path string `sql:"index" gorm:"size:255" json:"path"`
3232
Status int `json:"status"`
3333
Topped bool `json:"topped"`
3434
Commentable bool `json:"commentable"`

‎service/db.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ func ConnectDB() {
5656

5757
if err = db.AutoMigrate(tables...).Error; nil != err {
5858
logger.Fatal("auto migrate tables failed: " + err.Error())
59+
os.Exit(-1)
5960
}
6061

61-
if err = db.Model(&model.Article{}).AddIndex("idx_article_path", "path").Error; nil != err {
62+
if err = db.Model(&model.Article{}).AddIndex("idx_b3_pipe_articles_created_at", "created_at").Error; nil != err {
6263
logger.Fatal("adds index failed: " + err.Error())
64+
os.Exit(-1)
6365
}
6466
}
6567

0 commit comments

Comments
 (0)