feat: sqlite.go create tables

This commit is contained in:
Liangzhao Che 2023-06-01 19:38:07 +08:00
parent f042a74869
commit 12650c9965

View File

@ -1,6 +1,8 @@
package infrastructure package infrastructure
import ( import (
"bill-go-fiber/internal/bill"
"bill-go-fiber/internal/label"
"gorm.io/driver/sqlite" "gorm.io/driver/sqlite"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -13,5 +15,16 @@ func ConnectToSqlite() (*gorm.DB, error) {
panic("failed to connect database.\n") panic("failed to connect database.\n")
} }
err = db.AutoMigrate(&label.Label{})
if err != nil {
panic("failed to migrate database.\n")
}
err = db.AutoMigrate(&bill.Bill{})
if err != nil {
panic("failed to migrate database.\n")
}
db.Create(&label.Label{ID: 1, Name: "bill"})
return db, nil return db, nil
} }