Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions nexus/db-model/src/db_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::SemverVersion;
use crate::impl_enum_type;
use crate::typed_uuid::DbTypedUuid;
use chrono::{DateTime, Utc};
use nexus_db_schema::schema::db_metadata;
use nexus_db_schema::schema::db_metadata_nexus;
use omicron_uuid_kinds::{
BlueprintKind, BlueprintUuid, OmicronZoneKind, OmicronZoneUuid,
};
use serde::{Deserialize, Serialize};

/// Internal database metadata
Expand Down Expand Up @@ -33,3 +39,47 @@ impl DbMetadata {
&self.version
}
}

impl_enum_type!(
DbMetadataNexusStateEnum:

#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, PartialEq, Serialize, Deserialize)]
pub enum DbMetadataNexusState;

// Enum values
Active => b"active"
NotYet => b"not_yet"
Quiesced => b"quiesced"
);

#[derive(
Queryable, Insertable, Debug, Clone, Selectable, Serialize, Deserialize,
)]
#[diesel(table_name = db_metadata_nexus)]
pub struct DbMetadataNexus {
nexus_id: DbTypedUuid<OmicronZoneKind>,
last_drained_blueprint_id: Option<DbTypedUuid<BlueprintKind>>,
state: DbMetadataNexusState,
}

impl DbMetadataNexus {
pub fn new(nexus_id: OmicronZoneUuid, state: DbMetadataNexusState) -> Self {
Self {
nexus_id: nexus_id.into(),
last_drained_blueprint_id: None,
state,
}
}

pub fn state(&self) -> DbMetadataNexusState {
self.state
}

pub fn nexus_id(&self) -> OmicronZoneUuid {
self.nexus_id.into()
}

pub fn last_drained_blueprint_id(&self) -> Option<BlueprintUuid> {
self.last_drained_blueprint_id.map(|id| id.into())
}
}
6 changes: 5 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
///
/// 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: Version = Version::new(183, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(184, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::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(184, "populate-db-metadata-nexus"),
KnownVersion::new(183, "add-ip-version-to-pools"),
KnownVersion::new(182, "add-tuf-artifact-board"),
KnownVersion::new(181, "rename-nat-table"),
Expand Down Expand Up @@ -227,6 +228,9 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
/// The earliest supported schema version.
pub const EARLIEST_SUPPORTED_VERSION: Version = Version::new(1, 0, 0);

/// The version where "db_metadata_nexus" was added.
pub const DB_METADATA_NEXUS_SCHEMA_VERSION: Version = Version::new(184, 0, 0);

/// Describes one version of the database schema
#[derive(Debug, Clone)]
struct KnownVersion {
Expand Down
Loading
Loading