File tree Expand file tree Collapse file tree 1 file changed +2
-14
lines changed Expand file tree Collapse file tree 1 file changed +2
-14
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package repo
3
3
import (
4
4
"errors"
5
5
"log"
6
- "strings"
7
6
8
7
"github.com/0x2e/fusion/conf"
9
8
"github.com/0x2e/fusion/model"
@@ -33,8 +32,8 @@ func migrage() {
33
32
// We must delete any duplicate feeds before AutoMigrate applies the
34
33
// new unique constraint.
35
34
err := DB .Transaction (func (tx * gorm.DB ) error {
36
- // skip if it's the first launch
37
- if ! tableExist ( & model.Feed {}) || ! tableExist ( & model.Feed {}) {
35
+ // skip when it's the first launch
36
+ if ! tx . Migrator (). HasTable ( & model.Feed {}) || ! tx . Migrator (). HasTable ( & model.Item {}) {
38
37
return nil
39
38
}
40
39
@@ -88,17 +87,6 @@ func migrage() {
88
87
}
89
88
}
90
89
91
- func tableExist (table interface {}) bool {
92
- err := DB .Model (table ).First (table , "id = 1" ).Error
93
- if err != nil {
94
- if strings .Contains (err .Error (), "no such table" ) {
95
- return false
96
- }
97
- panic (err )
98
- }
99
- return true
100
- }
101
-
102
90
func registerCallback () {
103
91
if err := DB .Callback ().Query ().After ("*" ).Register ("convert_error" , func (db * gorm.DB ) {
104
92
if errors .Is (db .Error , gorm .ErrRecordNotFound ) {
You can’t perform that action at this time.
0 commit comments