Skip to content

Commit

Permalink
Fix schema migration and definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMcFelix committed Nov 22, 2023
1 parent b430952 commit 4db9048
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nexus/db-model/src/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub struct ExternalIp {
pub time_created: DateTime<Utc>,
pub time_modified: DateTime<Utc>,
pub time_deleted: Option<DateTime<Utc>>,
pub project_id: Option<Uuid>,
pub ip_pool_id: Option<Uuid>,
pub ip_pool_range_id: Option<Uuid>,
pub is_service: bool,
Expand All @@ -70,6 +69,7 @@ pub struct ExternalIp {
pub ip: IpNetwork,
pub first_port: SqlU16,
pub last_port: SqlU16,
pub project_id: Option<Uuid>,
}

impl From<ExternalIp> for sled_agent_client::types::SourceNatConfig {
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ table! {
time_created -> Timestamptz,
time_modified -> Timestamptz,
time_deleted -> Nullable<Timestamptz>,
project_id -> Nullable<Uuid>,
ip_pool_id -> Nullable<Uuid>,
ip_pool_range_id -> Nullable<Uuid>,
is_service -> Bool,
Expand All @@ -533,6 +532,7 @@ table! {
ip -> Inet,
first_port -> Int4,
last_port -> Int4,
project_id -> Nullable<Uuid>,
}
}

Expand Down
10 changes: 5 additions & 5 deletions nexus/db-queries/src/db/datastore/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ impl DataStore {
pub async fn attach_floating_ip_to_instance(
&self,
opctx: &OpContext,
instance_id: Uuid,
ip_id: &NameOrId,
project: &authz::Project,
_instance_id: Uuid,
_ip_id: &NameOrId,
_project: &authz::Project,
) -> UpdateResult<ExternalIp> {
use db::schema::external_ip::dsl;
// use db::schema::external_ip::dsl;
// TODO: scope by project
// opctx.authorize(authz::Action::CreateChild, authz_project).await?;
let conn = self.pool_connection_authorized(opctx).await?;
let _conn = self.pool_connection_authorized(opctx).await?;

// let ip_id = match ip_id {
// NameOrId::Id(id) => *id,
Expand Down
4 changes: 2 additions & 2 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,10 +1563,10 @@ async fn floating_ip_create(
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;
let project_lookup =
nexus.project_lookup(&opctx, query_params.into_inner())?;
let pool = nexus
let ip = nexus
.create_floating_ip(&opctx, &project_lookup, &floating_params)
.await?;
Ok(HttpResponseCreated(views::ExternalIp::from(pool)))
Ok(HttpResponseCreated(views::ExternalIp::from(ip)))
};
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
}
Expand Down
2 changes: 1 addition & 1 deletion schema/crdb/14.0.0/up02.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE omicron.public.external_ip ADD CONSTRAINT null_project_id IF NOT EXISTS CHECK (
ALTER TABLE omicron.public.external_ip ADD CONSTRAINT IF NOT EXISTS null_project_id CHECK (
kind = 'floating' OR project_id IS NULL
);
2 changes: 1 addition & 1 deletion schema/crdb/14.0.0/up03.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE omicron.public.external_ip ADD CONSTRAINT null_non_fip_pool_id IF NOT EXISTS CHECK (
ALTER TABLE omicron.public.external_ip ADD CONSTRAINT IF NOT EXISTS null_non_fip_pool_id CHECK (
kind = 'floating' OR (ip_pool_id IS NOT NULL AND ip_pool_range_id IS NOT NULL)
);
2 changes: 1 addition & 1 deletion schema/crdb/14.0.0/up04.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ALTER TABLE omicron.public.external_ip ADD CONSTRAINT null_pool_range_id IF NOT EXISTS CHECK (
ALTER TABLE omicron.public.external_ip ADD CONSTRAINT IF NOT EXISTS null_pool_range_id CHECK (
(ip_pool_id IS NULL AND ip_pool_range_id IS NULL) OR
(ip_pool_id IS NOT NULL AND ip_pool_range_id IS NOT NULL)
);
6 changes: 3 additions & 3 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1578,9 +1578,6 @@ CREATE TABLE IF NOT EXISTS omicron.public.external_ip (
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,

/* FK to the `ip_pool` table. */
project_id UUID,

/* FK to the `ip_pool` table. */
ip_pool_id UUID,

Expand All @@ -1605,6 +1602,9 @@ CREATE TABLE IF NOT EXISTS omicron.public.external_ip (
/* The last port in the allowed range, also inclusive. */
last_port INT4 NOT NULL,

/* FK to the `ip_pool` table. */
project_id UUID,

/* The name must be non-NULL iff this is a floating IP. */
CONSTRAINT null_fip_name CHECK (
(kind != 'floating' AND name IS NULL) OR
Expand Down

0 comments on commit 4db9048

Please sign in to comment.