From 12650c99653a46d66a481c7fea2b617b4d2d844a Mon Sep 17 00:00:00 2001 From: Liangzhao Che Date: Thu, 1 Jun 2023 19:38:07 +0800 Subject: [PATCH] feat: sqlite.go create tables --- internal/infrastructure/sqlite.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/infrastructure/sqlite.go b/internal/infrastructure/sqlite.go index a195968..841c8fb 100644 --- a/internal/infrastructure/sqlite.go +++ b/internal/infrastructure/sqlite.go @@ -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 }