From 74f05254700ee1741eb9bfaddfcbb3e36d544981 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 5 Sep 2025 08:40:03 -0700 Subject: [PATCH] Add `frontend` column to networks & network_memberships tables so the controller knows which system owns the networks & members --- .../migrations/0003_frontend_down.sql | 5 +++++ .../migrations/0003_frontend_up.sql | 5 +++++ nonfree/controller/CentralDB.cpp | 9 ++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 ext/central-controller-docker/migrations/0003_frontend_down.sql create mode 100644 ext/central-controller-docker/migrations/0003_frontend_up.sql diff --git a/ext/central-controller-docker/migrations/0003_frontend_down.sql b/ext/central-controller-docker/migrations/0003_frontend_down.sql new file mode 100644 index 000000000..870eeaa42 --- /dev/null +++ b/ext/central-controller-docker/migrations/0003_frontend_down.sql @@ -0,0 +1,5 @@ +ALTER TABLE network_memberships_ctl + DROP COLUMN frontend; + +ALTER TABLE networks_ctl + DROP COLUMN frontend; \ No newline at end of file diff --git a/ext/central-controller-docker/migrations/0003_frontend_up.sql b/ext/central-controller-docker/migrations/0003_frontend_up.sql new file mode 100644 index 000000000..cb9824496 --- /dev/null +++ b/ext/central-controller-docker/migrations/0003_frontend_up.sql @@ -0,0 +1,5 @@ +ALTER TABLE networks_ctl + ADD COLUMN frontend TEXT NOT NULL DEFAULT 'cv2'; + +ALTER TABLE network_memberships_ctl + ADD COLUMN frontend TEXT NOT NULL DEFAULT 'cv2'; \ No newline at end of file diff --git a/nonfree/controller/CentralDB.cpp b/nonfree/controller/CentralDB.cpp index 04ee52f44..1eb591f2a 100644 --- a/nonfree/controller/CentralDB.cpp +++ b/nonfree/controller/CentralDB.cpp @@ -615,7 +615,7 @@ void CentralDB::initializeNetworks() sprintf( qbuf, "SELECT id, name, configuration , (EXTRACT(EPOCH FROM creation_time AT TIME ZONE 'UTC')*1000)::bigint, " - "(EXTRACT(EPOCH FROM last_modified AT TIME ZONE 'UTC')*1000)::bigint, revision " + "(EXTRACT(EPOCH FROM last_modified AT TIME ZONE 'UTC')*1000)::bigint, revision, frontend " "FROM networks_ctl WHERE controller_id = '%s'", _myAddressStr.c_str()); @@ -636,6 +636,8 @@ void CentralDB::initializeNetworks() std::optional // last_modified , std::optional // revision + , + std::string // frontend > row; uint64_t count = 0; @@ -708,6 +710,7 @@ void CentralDB::initializeNetworks() } config["ipAssignmentPools"] = cfgtmp["ipAssignmentPools"].is_array() ? cfgtmp["ipAssignmentPools"] : json::array(); + config["frontend"] = std::get<6>(row); Metrics::network_count++; @@ -806,6 +809,7 @@ void CentralDB::initializeMembers() "(EXTRACT(EPOCH FROM nm.last_authorized_time AT TIME ZONE 'UTC')*1000)::bigint, " "(EXTRACT(EPOCH FROM nm.last_deauthorized_time AT TIME ZONE 'UTC')*1000)::bigint, " "nm.remote_trace_level, nm.remote_trace_target, nm.revision, nm.capabilities, nm.tags " + "nm.frontend " "FROM network_memberships_ctl nm " "INNER JOIN networks_ctl n " " ON nm.network_id = n.id " @@ -850,6 +854,8 @@ void CentralDB::initializeMembers() std::optional // capabilities , std::optional // tags + , + std::string // frontend > row; @@ -909,6 +915,7 @@ void CentralDB::initializeMembers() config["authenticationExpiryTime"] = authentication_expiry_time.value_or(0); config["tags"] = json::parse(tags.value_or("[]")); config["ipAssignments"] = json::array(); + config["frontend"] = std::get<17>(row); Metrics::member_count++;