t-paliad-025 — Phase 1: backend rename.
Migrations 018+019 rewritten from scratch with English table/column
names throughout. Since v2 schema (018/019) has never been applied to
youpc prod DB, this is a clean replacement — not an ALTER RENAME chain.
Pre-existing German tables (parteien, fristen, termine, dokumente,
akten_events, notizen) are renamed inline in 018 via ALTER TABLE … RENAME
TO alongside the akte_id → project_id column rewrite.
Renames applied:
projekte → projects
projekt_teams → project_teams
projekt_events → project_events (via akten_events → project_events)
fristen → deadlines
termine → appointments
parteien → parties
notizen → notes
dezernate → departments
dezernat_mitglieder → department_members
dokumente → documents
can_see_projekt → can_see_project
notiz_is_visible → note_is_visible
akte_id / frist_id / termin_id / akten_event_id → project_id /
deadline_id / appointment_id / project_event_id
termin_type → appointment_type
Go types + services renamed:
Projekt / ProjektService / ProjektEvent / ProjektTeamMember
Frist / FristService / FristWithProjekt
Termin / TerminService / TerminWithProjekt / TerminType
Notiz / NotizService / ChecklistInstanceWithProjekt
Dezernat / DezernatService / DezernatMitglied
Partei / Parteien / ParteienService
Files renamed (git mv):
internal/services/{projekt,frist,termin,notiz,dezernat,parteien}_service.go
→ {project,deadline,appointment,note,department,party}_service.go
internal/handlers/{projekte,fristen,fristen_pages,termine,termine_pages,
notizen,dezernate,akten_pages,gerichte,glossar,checklisten}.go
→ {projects,deadlines,deadlines_pages,appointments,appointments_pages,
notes,departments,projects_pages,courts,glossary,checklists}.go
internal/checklisten/ → internal/checklists/
internal/db/migrations/018_projekte_v2.* → 018_projects_v2.*
internal/db/migrations/019_seed_dezernate_from_user_text.*
→ 019_seed_departments_from_user_text.*
User-facing i18n strings (DE/EN labels) stay untouched. Product names
Fristenrechner / Kostenrechner / Gebührentabellen stay German.
Build + vet + tests clean.
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package db
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
_ "github.com/lib/pq"
|
|
)
|
|
|
|
var (
|
|
poolOnce sync.Once
|
|
poolDB *sqlx.DB
|
|
poolErr error
|
|
)
|
|
|
|
// OpenPool returns a process-wide *sqlx.DB. The first call connects; subsequent
|
|
// calls return the same instance. If the URL is empty, returns (nil, nil) — the
|
|
// caller is expected to handle the no-DB case (existing knowledge-platform
|
|
// endpoints work without a database; Akten/Deadline endpoints return 503).
|
|
//
|
|
// Pool sizing assumes a single Paliad replica behind Dokploy. Tune later if
|
|
// we scale horizontally.
|
|
func OpenPool(databaseURL string) (*sqlx.DB, error) {
|
|
if databaseURL == "" {
|
|
return nil, nil
|
|
}
|
|
poolOnce.Do(func() {
|
|
conn, err := sqlx.Open("postgres", databaseURL)
|
|
if err != nil {
|
|
poolErr = fmt.Errorf("open pool: %w", err)
|
|
return
|
|
}
|
|
conn.SetMaxOpenConns(10)
|
|
conn.SetMaxIdleConns(5)
|
|
conn.SetConnMaxLifetime(5 * time.Minute)
|
|
|
|
if err := conn.Ping(); err != nil {
|
|
poolErr = fmt.Errorf("ping pool: %w", err)
|
|
return
|
|
}
|
|
poolDB = conn
|
|
})
|
|
return poolDB, poolErr
|
|
}
|