Initial commit

This commit is contained in:
mats committed 2026-10-19 16:04:17 +02:00
commit afed023152
8152 files changed
+2086461

No files matched your search

@@ -0,0 +1,31 @@
package migrations
import (
"context"
"github.com/uptrace/bun"
"git.k6n.net/mats/fullstack-template/internal/items"
)
func init() {
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
_, err := db.NewCreateTable().
Model((*items.Item)(nil)).
IfNotExists().
Exec(ctx)
if err != nil {
return err
}
_, err = db.NewCreateIndex().
Model((*items.Item)(nil)).
IfNotExists().
Index("items_status_idx").
Column("status").
Exec(ctx)
return err
}, func(ctx context.Context, db *bun.DB) error {
_, err := db.NewDropTable().Model((*items.Item)(nil)).IfExists().Exec(ctx)
return err
})
}
@@ -0,0 +1,18 @@
// Package migrations holds the schema migrations: one Go file per
// migration, named <YYYYMMDDHHMMSS>_<snake_name>.go, each registering
// itself into Migrations via init(). `make migrate-new` scaffolds the next
// one with a fresh timestamp.
//
// Prefer model-driven DDL (db.NewCreateTable().Model((*pkg.Thing)(nil))) —
// bun emits dialect-correct SQL for both sqlite and postgres, so migrations
// stay portable. Reach for db.Exec with dialect-specific SQL only when a
// model can't express it.
package migrations
import "github.com/uptrace/bun/migrate"
// Migrations is the registry consumed by internal/database.NewMigrator.
// The directory option tells `migrate new` where to write (from backend/).
var Migrations = migrate.NewMigrations(
migrate.WithMigrationsDirectory("internal/database/migrations"),
)