feat(ctl): edgeguard-ctl migrate + initdb wired into postinst
migrate up|down|check|dump (1:1 nmg-ctl-Pattern, ruft internal/database Migrate/MigrateDown/ValidateMigrations/CopyEmbeddedMigrationsTo). initdb prüft pg_roles/pg_database und legt Role + DB idempotent via sudo -u postgres psql an, mit Identifier-Whitelist gegen Injection. postinst wirt die drei Schritte vor systemd-enable: migrate check (Pre-Flight ohne DB), initdb, migrate up (als edgeguard-User via Socket-Peer-Auth). cluster-join/promote/dump-config bleiben explizit Phase-3-Stubs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
// Command edgeguard-ctl is the admin CLI for setup, migrations and
|
||||
// (later) cluster ops. v1 wires migrate + initdb so postinst can
|
||||
// initialise a fresh node; cluster-* and promote remain stubs until
|
||||
// Phase 3.
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,14 +17,15 @@ Usage:
|
||||
edgeguard-ctl <command> [args]
|
||||
|
||||
Commands:
|
||||
version Print version
|
||||
initdb Initialise PostgreSQL database and user (idempotent)
|
||||
migrate up Apply pending migrations
|
||||
migrate down Roll back last migration (dev only)
|
||||
cluster-join Join an existing cluster (--from URL --token TOKEN)
|
||||
cluster-leave Leave the cluster cleanly
|
||||
promote Promote this node's PG to primary
|
||||
dump-config Print effective config to stdout
|
||||
version Print version and exit
|
||||
migrate up Apply pending migrations
|
||||
migrate down Roll back the most recent migration (dev only)
|
||||
migrate check Validate embedded migrations (no DB connect)
|
||||
migrate dump [dir] Write embedded SQL files to dir (default: ./migrations)
|
||||
initdb Create PostgreSQL role + database (idempotent)
|
||||
cluster-join Join an existing cluster (Phase 3, not yet implemented)
|
||||
promote Promote this node's PG to primary (Phase 3, not yet implemented)
|
||||
dump-config Print effective config (Phase 3, not yet implemented)
|
||||
`
|
||||
|
||||
func main() {
|
||||
@@ -29,12 +34,20 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
switch os.Args[1] {
|
||||
case "version":
|
||||
fmt.Println(version)
|
||||
case "-h", "--help", "help":
|
||||
fmt.Print(usage)
|
||||
case "version", "--version":
|
||||
fmt.Println(version)
|
||||
case "migrate":
|
||||
os.Exit(cmdMigrate(os.Args[2:]))
|
||||
case "initdb":
|
||||
os.Exit(cmdInitDB(os.Args[2:]))
|
||||
case "cluster-join", "cluster-leave", "promote", "dump-config":
|
||||
fmt.Fprintf(os.Stderr, "edgeguard-ctl: %q is a Phase-3 stub — not yet implemented\n", os.Args[1])
|
||||
os.Exit(1)
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "edgeguard-ctl: command %q not yet implemented\n", os.Args[1])
|
||||
fmt.Fprintf(os.Stderr, "edgeguard-ctl: unknown command %q\n", os.Args[1])
|
||||
fmt.Fprint(os.Stderr, usage)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user