From f5942e6e8c108035ae4792d5570c8d41b643e2c6 Mon Sep 17 00:00:00 2001 From: kevin-zhangzh Date: Fri, 25 Nov 2022 17:07:01 +0800 Subject: [PATCH] upgrade(): support sqlite --- schema/manifest.go | 2 +- wdb.go | 2 ++ wdb_test.go | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/schema/manifest.go b/schema/manifest.go index c3abd51..ca2b6a2 100644 --- a/schema/manifest.go +++ b/schema/manifest.go @@ -49,6 +49,6 @@ type Resource struct { type Manifest struct { ID uint `gorm:"primarykey" json:"-"` - ManifestUrl string `gorm:"index:idx1,unique" json:"manifestUrl"` + ManifestUrl string `gorm:"index:idxMani0,unique" json:"manifestUrl"` ManifestId string `json:"manifestId"` // arId } diff --git a/wdb.go b/wdb.go index 7b2d688..1ca3193 100644 --- a/wdb.go +++ b/wdb.go @@ -50,6 +50,8 @@ func NewSqliteDb(dbDir string) *Wdb { } +// when use sqlite,same index name in different table will lead to migrate failed, + func (w *Wdb) Migrate(noFee, enableManifest bool) error { err := w.Db.AutoMigrate(&schema.Order{}, &schema.OnChainTx{}) if err != nil { diff --git a/wdb_test.go b/wdb_test.go index d6ce145..0ea70fd 100644 --- a/wdb_test.go +++ b/wdb_test.go @@ -20,9 +20,10 @@ func TestNewWdb(t *testing.T) { } func TestSqlite(t *testing.T) { - db := NewMysqlDb("testSqlite") - - err := db.InsertOrder(schema.Order{ID: 1, Fee: "123"}) + db := NewSqliteDb("testSqlite") + err := db.Migrate(true, true) + assert.NoError(t, err) + err = db.InsertOrder(schema.Order{ID: 2, Fee: "123"}) assert.NoError(t, err) ord := &schema.Order{} err = db.Db.First(ord).Error