Skip to content

Commit 8f36b4b

Browse files
committed
Rename database collection traits for clarity
1 parent 1855275 commit 8f36b4b

24 files changed

+79
-76
lines changed

nexus/db-model/src/collection.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use std::fmt::Debug;
5858
/// type CollectionIdColumn = project::dsl::organization_id;
5959
/// }
6060
/// ```
61-
pub trait DatastoreCollection<ResourceType> {
61+
pub trait DatastoreCollectionConfig<ResourceType> {
6262
/// The Rust type of the collection id (typically Uuid for us)
6363
type CollectionId: Copy + Debug;
6464

@@ -126,7 +126,9 @@ pub trait DatastoreCollection<ResourceType> {
126126
/// type ResourceTimeDeletedColumn = disk::dsl::time_deleted;
127127
/// }
128128
/// ```
129-
pub trait DatastoreAttachTarget<ResourceType>: Selectable<Pg> + Sized {
129+
pub trait DatastoreAttachTargetConfig<ResourceType>:
130+
Selectable<Pg> + Sized
131+
{
130132
/// The Rust type of the collection and resource ids (typically Uuid).
131133
type Id: Copy + Debug + PartialEq + Send + 'static;
132134

nexus/db-model/src/dataset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{DatasetKind, Generation, Region, SqlU16};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::schema::{dataset, region};
88
use chrono::{DateTime, Utc};
99
use db_macros::Asset;
@@ -75,7 +75,7 @@ impl Dataset {
7575
}
7676

7777
// Datasets contain regions
78-
impl DatastoreCollection<Region> for Dataset {
78+
impl DatastoreCollectionConfig<Region> for Dataset {
7979
type CollectionId = Uuid;
8080
type GenerationNumberColumn = dataset::dsl::rcgen;
8181
type CollectionTimeDeletedColumn = dataset::dsl::time_deleted;

nexus/db-model/src/instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{ByteCount, Disk, Generation, InstanceCpuCount, InstanceState};
6-
use crate::collection::DatastoreAttachTarget;
6+
use crate::collection::DatastoreAttachTargetConfig;
77
use crate::schema::{disk, instance};
88
use chrono::{DateTime, Utc};
99
use db_macros::Resource;
@@ -69,7 +69,7 @@ impl Into<external::Instance> for Instance {
6969
}
7070
}
7171

72-
impl DatastoreAttachTarget<Disk> for Instance {
72+
impl DatastoreAttachTargetConfig<Disk> for Instance {
7373
type Id = Uuid;
7474

7575
type CollectionIdColumn = instance::dsl::id;

nexus/db-model/src/ip_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//! Model types for IP Pools and the CIDR blocks therein.
66
7-
use crate::collection::DatastoreCollection;
7+
use crate::collection::DatastoreCollectionConfig;
88
use crate::schema::ip_pool;
99
use crate::schema::ip_pool_range;
1010
use crate::Name;
@@ -162,7 +162,7 @@ impl From<&IpPoolRange> for IpRange {
162162
}
163163
}
164164

165-
impl DatastoreCollection<IpPoolRange> for IpPool {
165+
impl DatastoreCollectionConfig<IpPoolRange> for IpPool {
166166
type CollectionId = uuid::Uuid;
167167
type GenerationNumberColumn = ip_pool::dsl::rcgen;
168168
type CollectionTimeDeletedColumn = ip_pool::dsl::time_deleted;

nexus/db-model/src/organization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{Generation, Name, Project};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::schema::{organization, project};
88
use chrono::{DateTime, Utc};
99
use db_macros::Resource;
@@ -43,7 +43,7 @@ impl From<Organization> for views::Organization {
4343
}
4444
}
4545

46-
impl DatastoreCollection<Project> for Organization {
46+
impl DatastoreCollectionConfig<Project> for Organization {
4747
type CollectionId = Uuid;
4848
type GenerationNumberColumn = organization::dsl::rcgen;
4949
type CollectionTimeDeletedColumn = organization::dsl::time_deleted;

nexus/db-model/src/silo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{Generation, Organization};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::impl_enum_type;
88
use crate::schema::{organization, silo};
99
use db_macros::Resource;
@@ -85,7 +85,7 @@ impl From<Silo> for views::Silo {
8585
}
8686
}
8787

88-
impl DatastoreCollection<Organization> for Silo {
88+
impl DatastoreCollectionConfig<Organization> for Silo {
8989
type CollectionId = Uuid;
9090
type GenerationNumberColumn = silo::dsl::rcgen;
9191
type CollectionTimeDeletedColumn = silo::dsl::time_deleted;

nexus/db-model/src/sled.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{Generation, SqlU16};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::ipv6;
88
use crate::schema::{service, sled, zpool};
99
use chrono::{DateTime, Utc};
@@ -72,14 +72,14 @@ impl From<Sled> for views::Sled {
7272
}
7373
}
7474

75-
impl DatastoreCollection<super::Zpool> for Sled {
75+
impl DatastoreCollectionConfig<super::Zpool> for Sled {
7676
type CollectionId = Uuid;
7777
type GenerationNumberColumn = sled::dsl::rcgen;
7878
type CollectionTimeDeletedColumn = sled::dsl::time_deleted;
7979
type CollectionIdColumn = zpool::dsl::sled_id;
8080
}
8181

82-
impl DatastoreCollection<super::Service> for Sled {
82+
impl DatastoreCollectionConfig<super::Service> for Sled {
8383
type CollectionId = Uuid;
8484
type GenerationNumberColumn = sled::dsl::rcgen;
8585
type CollectionTimeDeletedColumn = sled::dsl::time_deleted;

nexus/db-model/src/volume.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{Generation, Region};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::schema::{region, volume};
88
use chrono::{DateTime, Utc};
99
use db_macros::Asset;
@@ -47,7 +47,7 @@ impl Volume {
4747
}
4848

4949
// Volumes contain regions
50-
impl DatastoreCollection<Region> for Volume {
50+
impl DatastoreCollectionConfig<Region> for Volume {
5151
type CollectionId = Uuid;
5252
type GenerationNumberColumn = volume::dsl::rcgen;
5353
type CollectionTimeDeletedColumn = volume::dsl::time_deleted;

nexus/db-model/src/vpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{Generation, Ipv6Net, Name, VpcFirewallRule};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::schema::{vpc, vpc_firewall_rule};
88
use crate::Vni;
99
use chrono::{DateTime, Utc};
@@ -96,7 +96,7 @@ impl IncompleteVpc {
9696
}
9797
}
9898

99-
impl DatastoreCollection<VpcFirewallRule> for Vpc {
99+
impl DatastoreCollectionConfig<VpcFirewallRule> for Vpc {
100100
type CollectionId = Uuid;
101101
type GenerationNumberColumn = vpc::dsl::firewall_gen;
102102
type CollectionTimeDeletedColumn = vpc::dsl::time_deleted;

nexus/db-model/src/vpc_router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{impl_enum_type, Generation, Name, RouterRoute};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::schema::{router_route, vpc_router};
88
use chrono::{DateTime, Utc};
99
use db_macros::Resource;
@@ -68,7 +68,7 @@ impl From<VpcRouter> for views::VpcRouter {
6868
}
6969
}
7070

71-
impl DatastoreCollection<RouterRoute> for VpcRouter {
71+
impl DatastoreCollectionConfig<RouterRoute> for VpcRouter {
7272
type CollectionId = Uuid;
7373
type GenerationNumberColumn = vpc_router::dsl::rcgen;
7474
type CollectionTimeDeletedColumn = vpc_router::dsl::time_deleted;

nexus/db-model/src/zpool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use super::{ByteCount, Dataset, Generation};
6-
use crate::collection::DatastoreCollection;
6+
use crate::collection::DatastoreCollectionConfig;
77
use crate::schema::{dataset, zpool};
88
use chrono::{DateTime, Utc};
99
use db_macros::Asset;
@@ -46,7 +46,7 @@ impl Zpool {
4646
}
4747
}
4848

49-
impl DatastoreCollection<Dataset> for Zpool {
49+
impl DatastoreCollectionConfig<Dataset> for Zpool {
5050
type CollectionId = Uuid;
5151
type GenerationNumberColumn = zpool::dsl::rcgen;
5252
type CollectionTimeDeletedColumn = zpool::dsl::time_deleted;

nexus/src/db/collection_attach.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ use diesel::query_builder::*;
2727
use diesel::query_dsl::methods as query_methods;
2828
use diesel::query_source::Table;
2929
use diesel::sql_types::{BigInt, Nullable, SingleValue};
30-
use nexus_db_model::DatastoreAttachTarget;
30+
use nexus_db_model::DatastoreAttachTargetConfig;
3131
use std::fmt::Debug;
3232

3333
/// A collection of type aliases particularly relevant to collection-based CTEs.
3434
pub(crate) mod aliases {
3535
use super::{
36-
Column, DatastoreAttachTarget, Table, TableDefaultWhereClause,
36+
Column, DatastoreAttachTargetConfig, Table, TableDefaultWhereClause,
3737
};
3838

3939
/// The table representing the collection. The resource references
4040
/// this table.
41-
pub type CollectionTable<ResourceType, C> = <<C as DatastoreAttachTarget<
41+
pub type CollectionTable<ResourceType, C> = <<C as DatastoreAttachTargetConfig<
4242
ResourceType,
4343
>>::CollectionIdColumn as Column>::Table;
4444
/// The table representing the resource. This table contains an
4545
/// ID acting as a foreign key into the collection table.
46-
pub type ResourceTable<ResourceType, C> = <<C as DatastoreAttachTarget<
46+
pub type ResourceTable<ResourceType, C> = <<C as DatastoreAttachTargetConfig<
4747
ResourceType,
4848
>>::ResourceIdColumn as Column>::Table;
4949

@@ -55,17 +55,17 @@ pub(crate) mod aliases {
5555
TableDefaultWhereClause<ResourceTable<ResourceType, C>>;
5656

5757
pub type CollectionIdColumn<ResourceType, C> =
58-
<C as DatastoreAttachTarget<ResourceType>>::CollectionIdColumn;
58+
<C as DatastoreAttachTargetConfig<ResourceType>>::CollectionIdColumn;
5959
pub type ResourceIdColumn<ResourceType, C> =
60-
<C as DatastoreAttachTarget<ResourceType>>::ResourceIdColumn;
60+
<C as DatastoreAttachTargetConfig<ResourceType>>::ResourceIdColumn;
6161

6262
/// Representation of Primary Key in Rust.
6363
pub type CollectionPrimaryKey<ResourceType, C> =
6464
<CollectionTable<ResourceType, C> as Table>::PrimaryKey;
6565
pub type ResourcePrimaryKey<ResourceType, C> =
6666
<ResourceTable<ResourceType, C> as Table>::PrimaryKey;
6767
pub type ResourceForeignKey<ResourceType, C> =
68-
<C as DatastoreAttachTarget<ResourceType>>::ResourceCollectionIdColumn;
68+
<C as DatastoreAttachTargetConfig<ResourceType>>::ResourceCollectionIdColumn;
6969

7070
/// Representation of Primary Key in SQL.
7171
pub type SerializedCollectionPrimaryKey<ResourceType, C> =
@@ -80,8 +80,8 @@ use aliases::*;
8080

8181
/// Extension trait adding behavior to types that implement
8282
/// `nexus_db_model::DatastoreAttachTarget`.
83-
pub trait DatastoreAttachTargetExt<ResourceType>:
84-
DatastoreAttachTarget<ResourceType>
83+
pub trait DatastoreAttachTarget<ResourceType>:
84+
DatastoreAttachTargetConfig<ResourceType>
8585
{
8686
/// Creates a statement for attaching a resource to the given collection.
8787
///
@@ -256,14 +256,15 @@ pub trait DatastoreAttachTargetExt<ResourceType>:
256256
}
257257
}
258258

259-
impl<T, R> DatastoreAttachTargetExt<R> for T where T: DatastoreAttachTarget<R> {}
259+
impl<T, R> DatastoreAttachTarget<R> for T where T: DatastoreAttachTargetConfig<R>
260+
{}
260261

261262
/// The CTE described in the module docs
262263
#[must_use = "Queries must be executed"]
263264
pub struct AttachToCollectionStatement<ResourceType, V, C>
264265
where
265266
ResourceType: Selectable<Pg>,
266-
C: DatastoreAttachTarget<ResourceType>,
267+
C: DatastoreAttachTargetConfig<ResourceType>,
267268
{
268269
// Query which answers: "Does the collection exist?"
269270
collection_exists_query: Box<dyn QueryFragment<Pg> + Send>,
@@ -290,7 +291,7 @@ impl<ResourceType, V, C> QueryId
290291
for AttachToCollectionStatement<ResourceType, V, C>
291292
where
292293
ResourceType: Selectable<Pg>,
293-
C: DatastoreAttachTarget<ResourceType>,
294+
C: DatastoreAttachTargetConfig<ResourceType>,
294295
{
295296
type QueryId = ();
296297
const HAS_STATIC_QUERY_ID: bool = false;
@@ -331,7 +332,7 @@ pub type RawOutput<ResourceType, C> =
331332
impl<ResourceType, V, C> AttachToCollectionStatement<ResourceType, V, C>
332333
where
333334
ResourceType: 'static + Debug + Send + Selectable<Pg>,
334-
C: 'static + Debug + DatastoreAttachTarget<ResourceType> + Send,
335+
C: 'static + Debug + DatastoreAttachTargetConfig<ResourceType> + Send,
335336
ResourceTable<ResourceType, C>: 'static + Table + Send + Copy + Debug,
336337
V: 'static + Send,
337338
AttachToCollectionStatement<ResourceType, V, C>: Send,
@@ -409,7 +410,7 @@ impl<ResourceType, V, C> Query
409410
for AttachToCollectionStatement<ResourceType, V, C>
410411
where
411412
ResourceType: Selectable<Pg>,
412-
C: DatastoreAttachTarget<ResourceType>,
413+
C: DatastoreAttachTargetConfig<ResourceType>,
413414
{
414415
type SqlType = (
415416
// The number of resources attached to the collection before update.
@@ -427,7 +428,7 @@ impl<ResourceType, V, C> RunQueryDsl<DbConnection>
427428
for AttachToCollectionStatement<ResourceType, V, C>
428429
where
429430
ResourceType: Selectable<Pg>,
430-
C: DatastoreAttachTarget<ResourceType>,
431+
C: DatastoreAttachTargetConfig<ResourceType>,
431432
{
432433
}
433434

@@ -503,7 +504,7 @@ impl<ResourceType, V, C> QueryFragment<Pg>
503504
for AttachToCollectionStatement<ResourceType, V, C>
504505
where
505506
ResourceType: Selectable<Pg>,
506-
C: DatastoreAttachTarget<ResourceType>,
507+
C: DatastoreAttachTargetConfig<ResourceType>,
507508
CollectionPrimaryKey<ResourceType, C>: diesel::Column,
508509
// Necessary to "walk_ast" over "self.update_resource_statement".
509510
BoxedUpdateStatement<'static, Pg, ResourceTable<ResourceType, C>, V>:
@@ -675,7 +676,7 @@ mod test {
675676
pub identity: CollectionIdentity,
676677
}
677678

678-
impl DatastoreAttachTarget<Resource> for Collection {
679+
impl DatastoreAttachTargetConfig<Resource> for Collection {
679680
type Id = uuid::Uuid;
680681

681682
type CollectionIdColumn = collection::dsl::id;

nexus/src/db/collection_detach.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ use diesel::query_builder::*;
2626
use diesel::query_dsl::methods as query_methods;
2727
use diesel::query_source::Table;
2828
use diesel::sql_types::{Nullable, SingleValue};
29-
use nexus_db_model::DatastoreAttachTarget;
29+
use nexus_db_model::DatastoreAttachTargetConfig;
3030
use std::fmt::Debug;
3131

3232
/// Trait to be implemented by structs representing a detachable collection.
3333
///
3434
/// A blanket implementation is provided for traits that implement
3535
/// [`DatastoreAttachTarget`].
3636
pub trait DatastoreDetachTarget<ResourceType>:
37-
DatastoreAttachTarget<ResourceType>
37+
DatastoreAttachTargetConfig<ResourceType>
3838
{
3939
/// Creates a statement for detaching a resource from the given collection.
4040
///
@@ -191,7 +191,7 @@ pub trait DatastoreDetachTarget<ResourceType>:
191191
}
192192

193193
impl<T, ResourceType> DatastoreDetachTarget<ResourceType> for T where
194-
T: DatastoreAttachTarget<ResourceType>
194+
T: DatastoreAttachTargetConfig<ResourceType>
195195
{
196196
}
197197

@@ -501,7 +501,7 @@ where
501501
#[cfg(test)]
502502
mod test {
503503
use super::*;
504-
use crate::db::collection_attach::DatastoreAttachTargetExt;
504+
use crate::db::collection_attach::DatastoreAttachTarget;
505505
use crate::db::{
506506
self, error::TransactionError, identity::Resource as IdentityResource,
507507
};
@@ -592,7 +592,7 @@ mod test {
592592
pub identity: CollectionIdentity,
593593
}
594594

595-
impl DatastoreAttachTarget<Resource> for Collection {
595+
impl DatastoreAttachTargetConfig<Resource> for Collection {
596596
type Id = uuid::Uuid;
597597

598598
type CollectionIdColumn = collection::dsl::id;

0 commit comments

Comments
 (0)