Skip to content

Commit

Permalink
Add schema change
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Jun 24, 2024
1 parent 1270098 commit f48fba3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
10 changes: 5 additions & 5 deletions nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ pub struct BpOmicronZone {
pub sled_id: DbTypedUuid<SledKind>,
pub id: Uuid,
pub underlay_address: ipv6::Ipv6Addr,
pub filesystem_pool: Option<DbTypedUuid<ZpoolKind>>,
pub zone_type: ZoneType,
pub primary_service_ip: ipv6::Ipv6Addr,
pub primary_service_port: SqlU16,
Expand All @@ -249,6 +248,7 @@ pub struct BpOmicronZone {
disposition: DbBpZoneDisposition,

pub external_ip_id: Option<DbTypedUuid<ExternalIpKind>>,
pub filesystem_pool: Option<DbTypedUuid<ZpoolKind>>,
}

impl BpOmicronZone {
Expand All @@ -274,10 +274,6 @@ impl BpOmicronZone {
sled_id: zone.sled_id.into(),
id: zone.id,
underlay_address: zone.underlay_address,
filesystem_pool: blueprint_zone
.filesystem_pool
.as_ref()
.map(|pool| pool.id().into()),
zone_type: zone.zone_type,
primary_service_ip: zone.primary_service_ip,
primary_service_port: zone.primary_service_port,
Expand All @@ -297,6 +293,10 @@ impl BpOmicronZone {
snat_last_port: zone.snat_last_port,
disposition: to_db_bp_zone_disposition(blueprint_zone.disposition),
external_ip_id: zone.external_ip_id.map(From::from),
filesystem_pool: blueprint_zone
.filesystem_pool
.as_ref()
.map(|pool| pool.id().into()),
})
}

Expand Down
4 changes: 2 additions & 2 deletions nexus/db-model/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,6 @@ pub struct InvOmicronZone {
pub sled_id: DbTypedUuid<SledKind>,
pub id: Uuid,
pub underlay_address: ipv6::Ipv6Addr,
pub filesystem_pool: Option<DbTypedUuid<ZpoolKind>>,
pub zone_type: ZoneType,
pub primary_service_ip: ipv6::Ipv6Addr,
pub primary_service_port: SqlU16,
Expand All @@ -1027,6 +1026,7 @@ pub struct InvOmicronZone {
pub snat_ip: Option<IpNetwork>,
pub snat_first_port: Option<SqlU16>,
pub snat_last_port: Option<SqlU16>,
pub filesystem_pool: Option<DbTypedUuid<ZpoolKind>>,
}

impl InvOmicronZone {
Expand All @@ -1050,7 +1050,6 @@ impl InvOmicronZone {
sled_id: zone.sled_id.into(),
id: zone.id,
underlay_address: zone.underlay_address,
filesystem_pool: zone.filesystem_pool.map(|id| id.into()),
zone_type: zone.zone_type,
primary_service_ip: zone.primary_service_ip,
primary_service_port: zone.primary_service_port,
Expand All @@ -1068,6 +1067,7 @@ impl InvOmicronZone {
snat_ip: zone.snat_ip,
snat_first_port: zone.snat_first_port,
snat_last_port: zone.snat_last_port,
filesystem_pool: zone.filesystem_pool.map(|id| id.into()),
})
}

Expand Down
4 changes: 2 additions & 2 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,6 @@ table! {

id -> Uuid,
underlay_address -> Inet,
filesystem_pool -> Nullable<Uuid>,
zone_type -> crate::ZoneTypeEnum,

primary_service_ip -> Inet,
Expand All @@ -1473,6 +1472,7 @@ table! {
snat_ip -> Nullable<Inet>,
snat_first_port -> Nullable<Int4>,
snat_last_port -> Nullable<Int4>,
filesystem_pool -> Nullable<Uuid>,
}
}

Expand Down Expand Up @@ -1569,7 +1569,6 @@ table! {

id -> Uuid,
underlay_address -> Inet,
filesystem_pool -> Nullable<Uuid>,
zone_type -> crate::ZoneTypeEnum,

primary_service_ip -> Inet,
Expand All @@ -1590,6 +1589,7 @@ table! {
snat_last_port -> Nullable<Int4>,
disposition -> crate::DbBpZoneDispositionEnum,
external_ip_id -> Nullable<Uuid>,
filesystem_pool -> Nullable<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(77, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(78, 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(78, "add-nullable-filesystem-pool"),
KnownVersion::new(77, "remove-view-for-v2p-mappings"),
KnownVersion::new(76, "lookup-region-snapshot-by-snapshot-id"),
KnownVersion::new(75, "add-cockroach-zone-id-to-node-id"),
Expand Down
1 change: 1 addition & 0 deletions schema/crdb/add-nullable-filesystem-pool/up1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE omicron.public.inv_omicron_zone ADD COLUMN IF NOT EXISTS filesystem_pool UUID;
1 change: 1 addition & 0 deletions schema/crdb/add-nullable-filesystem-pool/up2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE omicron.public.bp_omicron_zone ADD COLUMN IF NOT EXISTS filesystem_pool UUID;
16 changes: 9 additions & 7 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3178,9 +3178,6 @@ CREATE TABLE IF NOT EXISTS omicron.public.inv_omicron_zone (
-- unique id for this zone
id UUID NOT NULL,
underlay_address INET NOT NULL,
-- TODO: This is nullable for backwards compatibility.
-- Eventually, that nullability should be removed.
filesystem_pool UUID,
zone_type omicron.public.zone_type NOT NULL,

-- SocketAddr of the "primary" service for this zone
Expand Down Expand Up @@ -3233,6 +3230,10 @@ CREATE TABLE IF NOT EXISTS omicron.public.inv_omicron_zone (
snat_last_port INT4
CHECK (snat_last_port IS NULL OR snat_last_port BETWEEN 0 AND 65535),

-- TODO: This is nullable for backwards compatibility.
-- Eventually, that nullability should be removed.
filesystem_pool UUID,

PRIMARY KEY (inv_collection_id, id)
);

Expand Down Expand Up @@ -3415,9 +3416,6 @@ CREATE TABLE IF NOT EXISTS omicron.public.bp_omicron_zone (
-- unique id for this zone
id UUID NOT NULL,
underlay_address INET NOT NULL,
-- TODO: This is nullable for backwards compatibility.
-- Eventually, that nullability should be removed.
filesystem_pool UUID,
zone_type omicron.public.zone_type NOT NULL,

-- SocketAddr of the "primary" service for this zone
Expand Down Expand Up @@ -3482,6 +3480,10 @@ CREATE TABLE IF NOT EXISTS omicron.public.bp_omicron_zone (
-- created yet.
external_ip_id UUID,

-- TODO: This is nullable for backwards compatibility.
-- Eventually, that nullability should be removed.
filesystem_pool UUID,

PRIMARY KEY (blueprint_id, id)
);

Expand Down Expand Up @@ -4104,7 +4106,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
(TRUE, NOW(), NOW(), '77.0.0', NULL)
(TRUE, NOW(), NOW(), '78.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;

0 comments on commit f48fba3

Please sign in to comment.