basic logger middleware and formatting
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
@@ -18,6 +19,7 @@ type Migration struct {
|
||||
}
|
||||
|
||||
func Migrate(db *sql.DB) {
|
||||
slog.Info("Running migrations...")
|
||||
migrationTableSql := `
|
||||
CREATE TABLE IF NOT EXISTS migrations(
|
||||
version INTEGER PRIMARY KEY,
|
||||
@@ -35,12 +37,11 @@ func Migrate(db *sql.DB) {
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
fmt.Printf("Checking file: %s\n", file.Name())
|
||||
var migration Migration
|
||||
row := db.QueryRow("SELECT * FROM migrations WHERE name = ?;", file.Name())
|
||||
err = row.Scan(&migration.Version, &migration.Name)
|
||||
if err == sql.ErrNoRows {
|
||||
fmt.Printf("Running migration: %s\n", file.Name())
|
||||
slog.Info(fmt.Sprintf("Running migration: %s", file.Name()))
|
||||
migrationSql, err := migrations.ReadFile(fmt.Sprintf("migrations/%s", file.Name()))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -57,4 +58,5 @@ func Migrate(db *sql.DB) {
|
||||
}
|
||||
}
|
||||
}
|
||||
slog.Info("Migrations completed")
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ func NewInMemoryTodoRepository() InMemoryTodoRepository {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (r *InMemoryTodoRepository) GetById(id int64) (repository.TodoRow, error) {
|
||||
todo, found := r.Db[id]
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ var (
|
||||
)
|
||||
|
||||
type TodoRow struct {
|
||||
Id int64
|
||||
Id int64
|
||||
Name string
|
||||
Done bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user