feat(03-01): add shared postgres pool and plugin migrations

Open one pgx stdlib *sql.DB, hand it to GORM, and run per-plugin
gormigrate sets with isolated history tables after an ICU pl-PL check.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-09-17 19:55:33 +02:00
parent 15a8389e46
commit d0d845052b
18 changed files with 700 additions and 22 deletions

View File

@@ -6,6 +6,7 @@ import (
"testing/fstest"
"git.golem15.com/golem15/summercms/bonfire"
"github.com/go-gormigrate/gormigrate/v2"
)
type configOnly struct{}
@@ -27,14 +28,21 @@ type bothCaps struct {
type neither struct{}
func TestOptionalCapabilitiesDiscoveredByTypeAssertion(t *testing.T) {
plugins := []any{configOnly{}, commandsOnly{}, bothCaps{}, neither{}, extraMessage{}}
type migrationsOnly struct{}
var configs, commands, messages, none int
func (migrationsOnly) Migrations() []*gormigrate.Migration {
return []*gormigrate.Migration{{ID: "202609170001_create_users"}}
}
func TestOptionalCapabilitiesDiscoveredByTypeAssertion(t *testing.T) {
plugins := []any{configOnly{}, commandsOnly{}, bothCaps{}, neither{}, extraMessage{}, migrationsOnly{}}
var configs, commands, messages, migrations, none int
for _, p := range plugins {
_, hasCfg := p.(HasConfig)
_, hasCmd := p.(HasCommands)
_, hasMsg := p.(OptionalMessage)
_, hasMig := p.(HasMigrations)
if hasCfg {
configs++
}
@@ -44,7 +52,10 @@ func TestOptionalCapabilitiesDiscoveredByTypeAssertion(t *testing.T) {
if hasMsg {
messages++
}
if !hasCfg && !hasCmd && !hasMsg {
if hasMig {
migrations++
}
if !hasCfg && !hasCmd && !hasMsg && !hasMig {
none++
}
}
@@ -57,11 +68,22 @@ func TestOptionalCapabilitiesDiscoveredByTypeAssertion(t *testing.T) {
if messages != 1 {
t.Fatalf("OptionalMessage count = %d, want 1", messages)
}
if migrations != 1 {
t.Fatalf("HasMigrations count = %d, want 1", migrations)
}
if none != 1 {
t.Fatalf("neither count = %d, want 1", none)
}
}
func TestHasMigrationsReturnsOrderedSet(t *testing.T) {
var p HasMigrations = migrationsOnly{}
set := p.Migrations()
if len(set) != 1 || set[0].ID != "202609170001_create_users" {
t.Fatalf("Migrations = %+v", set)
}
}
func TestHasConfigReturnsFilesystem(t *testing.T) {
var p HasConfig = configOnly{}
fsys := p.ConfigFS()