Skip to content

Commit ef1b4b4

Browse files
committed
store db version in place of application version
1 parent cf766a8 commit ef1b4b4

File tree

5 files changed

+105
-85
lines changed

5 files changed

+105
-85
lines changed

mithril-aggregator/src/command_args.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tokio::time::Duration;
1212
use mithril_common::certificate_chain::MithrilCertificateVerifier;
1313
use mithril_common::chain_observer::{CardanoCliRunner, ChainObserver};
1414
use mithril_common::crypto_helper::ProtocolGenesisVerifier;
15-
use mithril_common::database::{ApplicationNodeType, ApplicationVersionChecker};
15+
use mithril_common::database::{ApplicationNodeType, DatabaseVersionChecker};
1616
use mithril_common::digesters::{CardanoImmutableDigester, ImmutableFileSystemObserver};
1717
use mithril_common::entities::{Epoch, HexEncodedGenesisSecretKey};
1818
use mithril_common::store::adapter::SQLiteAdapter;
@@ -37,7 +37,7 @@ fn setup_genesis_dependencies(
3737
config: &GenesisConfiguration,
3838
) -> Result<GenesisToolsDependency, Box<dyn std::error::Error>> {
3939
let sqlite_db_path = Some(config.get_sqlite_file());
40-
ApplicationVersionChecker::new(
40+
DatabaseVersionChecker::new(
4141
slog_scope::logger(),
4242
ApplicationNodeType::Aggregator,
4343
config.get_sqlite_file(),
@@ -304,7 +304,7 @@ impl ServeCommand {
304304
.map_err(|e| format!("configuration deserialize error: {}", e))?;
305305
debug!("SERVE command"; "config" => format!("{:?}", config));
306306
let sqlite_db_path = Some(config.get_sqlite_file());
307-
ApplicationVersionChecker::new(
307+
DatabaseVersionChecker::new(
308308
slog_scope::logger(),
309309
ApplicationNodeType::Aggregator,
310310
config.get_sqlite_file(),

mithril-common/src/database/db_version.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Display for ApplicationNodeType {
4343

4444
/// Entity related to the `app_version` database table.
4545
#[derive(Debug, PartialEq, Eq, Clone)]
46-
pub struct ApplicationVersion {
46+
pub struct DatabaseVersion {
4747
/// Semver of the database structure.
4848
pub semver: Version,
4949

@@ -55,7 +55,7 @@ pub struct ApplicationVersion {
5555
pub updated_at: NaiveDateTime,
5656
}
5757

58-
impl SqLiteEntity for ApplicationVersion {
58+
impl SqLiteEntity for DatabaseVersion {
5959
fn hydrate(row: Row) -> Result<Self, HydrationError> {
6060
Ok(Self {
6161
semver: Version::parse(&row.get::<String, _>(0))
@@ -71,7 +71,7 @@ impl SqLiteEntity for ApplicationVersion {
7171
}
7272
}
7373

74-
impl PartialOrd for ApplicationVersion {
74+
impl PartialOrd for DatabaseVersion {
7575
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
7676
if self.application_type != other.application_type {
7777
None
@@ -81,12 +81,12 @@ impl PartialOrd for ApplicationVersion {
8181
}
8282
}
8383

84-
/// Projection dedicated to [ApplicationVersion] entities.
85-
struct ApplicationVersionProjection {
84+
/// Projection dedicated to [DatabaseVersion] entities.
85+
struct DatabaseVersionProjection {
8686
fields: Vec<ProjectionField>,
8787
}
8888

89-
impl Projection for ApplicationVersionProjection {
89+
impl Projection for DatabaseVersionProjection {
9090
fn set_field(&mut self, field: ProjectionField) {
9191
self.fields.push(field);
9292
}
@@ -95,7 +95,7 @@ impl Projection for ApplicationVersionProjection {
9595
&self.fields
9696
}
9797
}
98-
impl ApplicationVersionProjection {
98+
impl DatabaseVersionProjection {
9999
pub fn new() -> Self {
100100
let mut projection = Self { fields: Vec::new() };
101101
projection.add_field("semver", "{:app_version:}.semver", "text");
@@ -110,18 +110,18 @@ impl ApplicationVersionProjection {
110110
}
111111
}
112112

113-
/// Provider for the [ApplicationVersion] entities using the `ApplicationVersionProjection`.
114-
pub struct VersionProvider<'conn> {
113+
/// Provider for the [DatabaseVersion] entities using the `DatabaseVersionProjection`.
114+
pub struct DatabaseVersionProvider<'conn> {
115115
connection: &'conn Connection,
116-
projection: ApplicationVersionProjection,
116+
projection: DatabaseVersionProjection,
117117
}
118118

119-
impl<'conn> VersionProvider<'conn> {
120-
/// [VersionProvider] constructor.
119+
impl<'conn> DatabaseVersionProvider<'conn> {
120+
/// [DatabaseVersionProvider] constructor.
121121
pub fn new(connection: &'conn Connection) -> Self {
122122
Self {
123123
connection,
124-
projection: ApplicationVersionProjection::new(),
124+
projection: DatabaseVersionProjection::new(),
125125
}
126126
}
127127

@@ -153,7 +153,7 @@ create table app_version (application_type text not null primary key, semver tex
153153
pub fn get_application_version(
154154
&self,
155155
application_type: &ApplicationNodeType,
156-
) -> Result<Option<ApplicationVersion>, Box<dyn Error>> {
156+
) -> Result<Option<DatabaseVersion>, Box<dyn Error>> {
157157
let condition = "application_type = ?";
158158
let params = [Value::String(format!("{}", application_type))];
159159
let result = self.find(Some(condition), &params)?.next();
@@ -162,8 +162,8 @@ create table app_version (application_type text not null primary key, semver tex
162162
}
163163
}
164164

165-
impl<'conn> Provider<'conn> for VersionProvider<'conn> {
166-
type Entity = ApplicationVersion;
165+
impl<'conn> Provider<'conn> for DatabaseVersionProvider<'conn> {
166+
type Entity = DatabaseVersion;
167167

168168
fn get_projection(&self) -> &dyn Projection {
169169
&self.projection
@@ -189,24 +189,24 @@ where {where_clause}
189189
}
190190
}
191191

192-
/// Write [Provider] for the [ApplicationVersion] entities.
192+
/// Write [Provider] for the [DatabaseVersion] entities.
193193
/// This will perform an UPSERT and return the updated entity.
194-
pub struct VersionUpdaterProvider<'conn> {
194+
pub struct DatabaseVersionUpdater<'conn> {
195195
connection: &'conn Connection,
196-
projection: ApplicationVersionProjection,
196+
projection: DatabaseVersionProjection,
197197
}
198198

199-
impl<'conn> VersionUpdaterProvider<'conn> {
200-
/// [VersionUpdaterProvider] constructor.
199+
impl<'conn> DatabaseVersionUpdater<'conn> {
200+
/// [DatabaseVersionUpdater] constructor.
201201
pub fn new(connection: &'conn Connection) -> Self {
202202
Self {
203203
connection,
204-
projection: ApplicationVersionProjection::new(),
204+
projection: DatabaseVersionProjection::new(),
205205
}
206206
}
207207

208208
/// Persist the given entity and return the projection of the saved entity.
209-
pub fn save(&self, version: ApplicationVersion) -> Result<ApplicationVersion, Box<dyn Error>> {
209+
pub fn save(&self, version: DatabaseVersion) -> Result<DatabaseVersion, Box<dyn Error>> {
210210
let params = [
211211
Value::String(format!("{}", version.application_type)),
212212
Value::String(version.semver.to_string()),
@@ -220,8 +220,8 @@ impl<'conn> VersionUpdaterProvider<'conn> {
220220
}
221221
}
222222

223-
impl<'conn> Provider<'conn> for VersionUpdaterProvider<'conn> {
224-
type Entity = ApplicationVersion;
223+
impl<'conn> Provider<'conn> for DatabaseVersionUpdater<'conn> {
224+
type Entity = DatabaseVersion;
225225

226226
fn get_projection(&self) -> &dyn Projection {
227227
&self.projection
@@ -253,7 +253,7 @@ mod tests {
253253

254254
#[test]
255255
fn test_projection() {
256-
let projection = ApplicationVersionProjection::new();
256+
let projection = DatabaseVersionProjection::new();
257257
let mut aliases: HashMap<String, String> = HashMap::new();
258258
let _ = aliases.insert("{:app_version:}".to_string(), "whatever".to_string());
259259

@@ -267,7 +267,7 @@ mod tests {
267267
#[test]
268268
fn test_definition() {
269269
let connection = Connection::open(":memory:").unwrap();
270-
let provider = VersionProvider::new(&connection);
270+
let provider = DatabaseVersionProvider::new(&connection);
271271

272272
assert_eq!(
273273
r#"
@@ -282,7 +282,7 @@ where true
282282
#[test]
283283
fn test_updated_entity() {
284284
let connection = Connection::open(":memory:").unwrap();
285-
let provider = VersionUpdaterProvider::new(&connection);
285+
let provider = DatabaseVersionUpdater::new(&connection);
286286

287287
assert_eq!(
288288
r#"

mithril-common/src/database/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ mod db_version;
55
mod version_checker;
66

77
pub use db_version::*;
8-
pub use version_checker::{ApplicationVersionChecker, SqlMigration};
8+
pub use version_checker::{DatabaseVersionChecker, SqlMigration};

0 commit comments

Comments
 (0)