sshkeeper: fix migration - route_hops via ensureSchema() to avoid duplicate column error
This commit is contained in:
parent
87f0d90f7b
commit
21444d3826
|
|
@ -44,6 +44,7 @@ func Open(dataDir string) (*DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) ensureSchema() error {
|
func (db *DB) ensureSchema() error {
|
||||||
|
// Add startup_command column
|
||||||
hasStartupCommand, err := db.hasColumn("servers", "startup_command")
|
hasStartupCommand, err := db.hasColumn("servers", "startup_command")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -54,6 +55,21 @@ func (db *DB) ensureSchema() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add route_hops column
|
||||||
|
hasRouteHops, err := db.hasColumn("servers", "route_hops")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !hasRouteHops {
|
||||||
|
if _, err := db.conn.Exec("ALTER TABLE servers ADD COLUMN route_hops TEXT NOT NULL DEFAULT ''"); err != nil {
|
||||||
|
return fmt.Errorf("add route_hops: %w", err)
|
||||||
|
}
|
||||||
|
// Migrate existing ProxyJump values into route_hops
|
||||||
|
if _, err := db.conn.Exec("UPDATE servers SET route_hops = proxy_jump WHERE proxy_jump != ''"); err != nil {
|
||||||
|
return fmt.Errorf("migrate proxy_jump to route_hops: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err = db.conn.Exec(`
|
_, err = db.conn.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS global_command_templates (
|
CREATE TABLE IF NOT EXISTS global_command_templates (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,4 @@
|
||||||
-- v0.2.0: Add route support
|
-- v0.2.0: Add route support
|
||||||
-- Adds route columns to servers table and migrates existing ProxyJump data.
|
-- Note: The route_hops column is now added programmatically in ensureSchema()
|
||||||
|
-- in db.go to handle idempotent migrations. This file is kept for reference.
|
||||||
ALTER TABLE servers ADD COLUMN route_hops TEXT NOT NULL DEFAULT '';
|
-- No SQL operations needed here.
|
||||||
|
|
||||||
-- Migrate existing ProxyJump values into Route.Hops (all as raw addresses).
|
|
||||||
-- ProxyJump format: "host1,host2,host3" → each becomes a RouteHop with IsProfile=false.
|
|
||||||
-- We store as a simple comma-separated list of raw addresses in route_hops for now.
|
|
||||||
-- The application layer will parse this into Route.Hops on read.
|
|
||||||
UPDATE servers SET route_hops = proxy_jump WHERE proxy_jump != '' AND route_hops = '';
|
|
||||||
Loading…
Reference in New Issue