Skip to content

Commit

Permalink
upgrade(): support sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-zhangzh committed Nov 25, 2022
1 parent eafac41 commit f5942e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion schema/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions wdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions wdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5942e6

Please sign in to comment.