feat(lagoon): per-query collation for OrderBy, drop the database locale check

- lagoon.OrderBy takes variadic lagoon.OrderOption values; lagoon.Collate(name)
  emits a validated, double-quoted COLLATE clause (e.g. "pl-x-icu")
- remove the exported CheckLocale and the ICU pl-PL check from Open and Use
- framework test containers and per-test databases are plain PostgreSQL
- lagoon README, root README and docs pages drop the locale requirement;
  queries-and-pagination gains a "Sorting with a collation" section
  backed by ExampleCollate
This commit is contained in:
Jakub Zych
2026-10-01 09:51:03 +02:00
parent 565ce982d9
commit 037dc53030
22 changed files with 344 additions and 168 deletions

View File

@@ -21,13 +21,6 @@ func TestUseRejectsNilSQL(t *testing.T) {
}
}
func TestCheckLocaleRejectsNilSQL(t *testing.T) {
err := CheckLocale(t.Context(), nil)
if err == nil || !strings.Contains(err.Error(), "sql db is nil") {
t.Fatalf("got %v", err)
}
}
func TestPublishRejectsNilHandles(t *testing.T) {
app := backpack.New(nil)
if err := Publish(nil, nil, nil); err == nil {
@@ -105,31 +98,6 @@ func TestSharedSQLPoolUsedByGORMAndClosed(t *testing.T) {
}
}
func TestWrongICULocaleFailsOpen(t *testing.T) {
admin := lagoonDB(t)
ctx := t.Context()
if _, err := admin.ExecContext(ctx, `CREATE DATABASE lagoon_locale_fail TEMPLATE template0 ENCODING 'UTF8' LOCALE_PROVIDER libc LOCALE 'C'`); err != nil && !strings.Contains(err.Error(), "already exists") {
t.Fatalf("create libc database: %v", err)
}
t.Cleanup(func() {
_, _ = admin.ExecContext(ctx, `DROP DATABASE IF EXISTS lagoon_locale_fail WITH (FORCE)`)
})
failDSN, err := dsnWithDB(lagoonDSN, "lagoon_locale_fail")
if err != nil {
t.Fatal(err)
}
_, _, err = Open(ctx, failDSN)
if err == nil {
t.Fatal("wrong locale must fail boot")
}
msg := err.Error()
for _, want := range []string{"ICU", "pl-PL", "CREATE DATABASE", "LOCALE_PROVIDER icu"} {
if !strings.Contains(msg, want) {
t.Fatalf("missing %q in %s", want, msg)
}
}
}
func TestOpenFromAppReadsDSN(t *testing.T) {
_, dsn := dedicatedDB(t, "lagoon_from_app")
dir := t.TempDir()