File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package repo
3
3
import (
4
4
"errors"
5
5
"log"
6
+ "strings"
6
7
7
8
"github.com/0x2e/fusion/conf"
8
9
"github.com/0x2e/fusion/model"
@@ -32,6 +33,11 @@ func migrage() {
32
33
// We must delete any duplicate feeds before AutoMigrate applies the
33
34
// new unique constraint.
34
35
err := DB .Transaction (func (tx * gorm.DB ) error {
36
+ // skip if it's the first launch
37
+ if ! tableExist (& model.Feed {}) || ! tableExist (& model.Feed {}) {
38
+ return nil
39
+ }
40
+
35
41
// query duplicate feeds
36
42
dupFeeds := make ([]model.Feed , 0 )
37
43
err := tx .Model (& model.Feed {}).Where (
@@ -82,6 +88,17 @@ func migrage() {
82
88
}
83
89
}
84
90
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
+
85
102
func registerCallback () {
86
103
if err := DB .Callback ().Query ().After ("*" ).Register ("convert_error" , func (db * gorm.DB ) {
87
104
if errors .Is (db .Error , gorm .ErrRecordNotFound ) {
You can’t perform that action at this time.
0 commit comments