mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
Phase 0 cleanup verified end-to-end:
- Delete vendored APwhy runtime (cmd/apwhy, internal/apwhy) and the
unwired copy (internal/api/server.go + static bundle + cloned
internal/{storage,analytics,auth,rbac}) — ~7.5k lines of dead code.
- Keep Containr's native internal/gateway; move APwhy management
routes under /api/v1/gateway/* so they stop colliding with the
native /services paths. Fix handlers against the real schema:
UUID ids via RETURNING, integer enabled flags, plan validation,
service validate endpoint, unique-violation mapping.
- Port agents.go off GORM onto sqlc (sqlc/queries/agents.sql);
drop gorm dependencies; fix sqlc schema drift (services.environment_id).
- Replace the SELECT 1 goose baseline with the real consolidated
schema (52 tables) minus APwhy's parallel auth/RBAC objects;
idempotent via IF NOT EXISTS / OR REPLACE / guarded DO blocks so it
replays cleanly over legacy installs. Add a drop migration for the
dead objects and delete the legacy filename-tracked migrations/
loader, directory, and Dockerfile copy. Verified via cmd/migrate:
fresh install 53 tables, legacy upgrade clean to 20260917000000.
- Canvas: add invisible React Flow handles to ServiceNode so inferred
auto-connections stop emitting warning #008.
- Remove reactflow dep (superseded by @xyflow/react), test harness
cmds, and legacy 0001_init.sql backups.
Authored By: TDvorak <[email protected]>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
|
|
"containr/internal/config"
|
|
"containr/internal/database"
|
|
|
|
"github.com/pressly/goose/v3"
|
|
)
|
|
|
|
func main() {
|
|
cfg := config.Load()
|
|
|
|
db, err := database.NewConnectionWithConfig(cfg.DatabaseURL, database.DBConfig{
|
|
MaxOpenConns: cfg.MaxConnections,
|
|
MaxIdleConns: cfg.MaxIdleConnections,
|
|
ConnMaxLifetime: cfg.ConnMaxLifetime,
|
|
ConnMaxIdleTime: cfg.ConnMaxIdleTime,
|
|
})
|
|
if err != nil {
|
|
log.Fatalf("Failed to connect to database: %v", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
gooseDir := os.Getenv("GOOSE_MIGRATIONS_DIR")
|
|
if gooseDir == "" {
|
|
gooseDir = "migrations_goose"
|
|
}
|
|
|
|
command := "up"
|
|
if len(os.Args) > 1 {
|
|
command = os.Args[1]
|
|
}
|
|
|
|
switch command {
|
|
case "up", "goose-up":
|
|
migrationCtx, migrationCancel := context.WithTimeout(context.Background(), cfg.MigrationLockTimeout)
|
|
if err := db.MigrateAllWithLock(migrationCtx, gooseDir); err != nil {
|
|
migrationCancel()
|
|
log.Fatalf("Migration failed: %v", err)
|
|
}
|
|
migrationCancel()
|
|
log.Println("Migrations completed successfully")
|
|
case "goose-status":
|
|
if err := db.GooseStatus(gooseDir); err != nil {
|
|
log.Fatalf("Goose status failed: %v", err)
|
|
}
|
|
case "goose-create":
|
|
if len(os.Args) < 3 {
|
|
log.Fatalf("Missing migration name. Usage: go run cmd/migrate/main.go goose-create <name>")
|
|
}
|
|
name := os.Args[2]
|
|
if err := goose.Create(nil, gooseDir, name, "sql"); err != nil {
|
|
log.Fatalf("Goose create failed: %v", err)
|
|
}
|
|
log.Printf("Created goose migration %q in %q", name, gooseDir)
|
|
default:
|
|
log.Fatalf("Unknown command %q. Supported commands: up | goose-status | goose-create", command)
|
|
}
|
|
}
|