diff --git a/internal/infrastructure/sqlite.go b/internal/infrastructure/sqlite.go index 841c8fb..191f97e 100644 --- a/internal/infrastructure/sqlite.go +++ b/internal/infrastructure/sqlite.go @@ -5,6 +5,7 @@ import ( "bill-go-fiber/internal/label" "gorm.io/driver/sqlite" "gorm.io/gorm" + "os" ) func ConnectToSqlite() (*gorm.DB, error) { @@ -24,7 +25,14 @@ func ConnectToSqlite() (*gorm.DB, error) { panic("failed to migrate database.\n") } - db.Create(&label.Label{ID: 1, Name: "bill"}) + // migrate data + go func() { + sql, err := os.ReadFile("scripts/sqliteMigrations.sql") + if err != nil { + panic("failed to read migration sql file: " + err.Error()) + } + db.Exec(string(sql)) + }() return db, nil } diff --git a/scripts/sqliteMigrations.sql b/scripts/sqliteMigrations.sql new file mode 100644 index 0000000..2b4fc93 --- /dev/null +++ b/scripts/sqliteMigrations.sql @@ -0,0 +1,8 @@ +INSERT INTO labels (id, type, name, count) +VALUES (1, '', 'bill', 0), + (2, '', 'bill', 0), + (3, '', 'bill', 0), + (4, '', 'bill', 0), + (5, '', 'bill', 0), + (6, '', 'bill', 0), + (7, '', 'bill', 0);