feat: sqlite.go create tables
This commit is contained in:
parent
f042a74869
commit
12650c9965
|
@ -1,6 +1,8 @@
|
|||
package infrastructure
|
||||
|
||||
import (
|
||||
"bill-go-fiber/internal/bill"
|
||||
"bill-go-fiber/internal/label"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
@ -13,5 +15,16 @@ func ConnectToSqlite() (*gorm.DB, error) {
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user