Skip to content

Commit

Permalink
Add policy to the db
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Oct 14, 2024
1 parent 6fb91c6 commit 2189eb2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod physical_disk_state;
mod probe;
mod producer_endpoint;
mod project;
mod reconfigurator_policy;
mod semver_version;
mod switch_interface;
mod switch_port;
Expand Down
16 changes: 16 additions & 0 deletions nexus/db-model/src/reconfigurator_policy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::schema::reconfigurator_policy;
use crate::SqlU32;
use chrono::{DateTime, Utc};

#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = reconfigurator_policy)]
pub struct ReconfiguratorPolicy {
pub version: SqlU32,
pub clickhouse_cluster_enabled: bool,
pub clickhouse_single_node_enabled: bool,
pub time_created: DateTime<Utc>,
}
9 changes: 9 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,15 @@ table! {
}
}

table! {
reconfigurator_policy (version) {
version -> Int8,
clickhouse_cluster_enabled -> Bool,
clickhouse_single_node_enabled -> Bool,
time_created -> Timestamptz
}
}

table! {
rack (id) {
id -> Uuid,
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::BTreeMap;
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(109, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(110, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = Lazy::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(110, "reconfigurator-policy"),
KnownVersion::new(109, "inv-clickhouse-keeper-membership"),
KnownVersion::new(108, "internet-gateway"),
KnownVersion::new(107, "add-instance-boot-disk"),
Expand Down
21 changes: 20 additions & 1 deletion schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ ALTER DEFAULT PRIVILEGES GRANT INSERT, SELECT, UPDATE, DELETE ON TABLES to omicr
*/
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 5;

/*
* A reconfigurator planning policy for a single multirack setup
*
* We currently tie this policy to a rack, as we don't yet support multirack.
* Multiple parts of this database schema are going to have to change to support
* multirack, so we add one more for now.
*/
CREATE TABLE IF NOT EXISTS omicron.public.reconfigurator_policy (
-- Monotonically increasing version for all policies
--
-- This is similar to `bp_target` which will also require being changed for
-- multirack to associate with some sort of rack group ID.
version INT8 PRIMARY KEY,

clickhouse_cluster_enabled BOOL NOT NULL
clickhouse_single_node_enabled BOOL NOT NULL
time_created TIMESTAMPTZ NOT NULL,
);

/*
* Racks
*/
Expand Down Expand Up @@ -4498,7 +4517,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
(TRUE, NOW(), NOW(), '109.0.0', NULL)
(TRUE, NOW(), NOW(), '110.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;
6 changes: 6 additions & 0 deletions schema/crdb/reconfigurator-policy/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS omicron.public.reconfigurator_policy (
version INT8 PRIMARY KEY,
clickhouse_cluster_enabled BOOL NOT NULL
clickhouse_single_node_enabled BOOL NOT NULL
time_created TIMESTAMPTZ NOT NULL,
);

0 comments on commit 2189eb2

Please sign in to comment.