Add config profiles with inbound assignment for nodes.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -95,12 +95,47 @@ CREATE TABLE IF NOT EXISTS node_protocols (
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_node_protocols_protocol ON node_protocols(protocol_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS config_profiles (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS inbounds (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
profile_id UUID NOT NULL REFERENCES config_profiles(id) ON DELETE CASCADE,
|
||||
tag TEXT NOT NULL,
|
||||
protocol_id UUID NOT NULL REFERENCES protocols(id) ON DELETE RESTRICT,
|
||||
port INT NOT NULL DEFAULT 443,
|
||||
network TEXT NOT NULL DEFAULT 'tcp',
|
||||
security TEXT NOT NULL DEFAULT 'none',
|
||||
listen TEXT NOT NULL DEFAULT '0.0.0.0',
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
remark TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (profile_id, tag)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_inbounds_profile ON inbounds(profile_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS node_inbounds (
|
||||
node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
|
||||
inbound_id UUID NOT NULL REFERENCES inbounds(id) ON DELETE CASCADE,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
PRIMARY KEY (node_id, inbound_id)
|
||||
);
|
||||
`
|
||||
if _, err := db.Exec(schema); err != nil {
|
||||
return err
|
||||
}
|
||||
// Additive migrations for existing deployments.
|
||||
_, _ = db.Exec(`ALTER TABLE nodes ADD COLUMN IF NOT EXISTS runtime_log TEXT NOT NULL DEFAULT ''`)
|
||||
_, _ = db.Exec(`ALTER TABLE nodes ADD COLUMN IF NOT EXISTS profile_id UUID REFERENCES config_profiles(id) ON DELETE SET NULL`)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -227,5 +262,9 @@ func GetStats(db *sql.DB) (models.DashboardStats, error) {
|
||||
return s, err
|
||||
}
|
||||
err = db.QueryRow(`SELECT COUNT(*) FROM nodes WHERE status = 'online'`).Scan(&s.NodesOnline)
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
err = db.QueryRow(`SELECT COUNT(*) FROM config_profiles`).Scan(&s.ProfilesTotal)
|
||||
return s, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user