Skip to content

Commit 4088961

Browse files
authored
Use Ulid instead of Uuid (#229)
1 parent 98302e5 commit 4088961

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ tokio = { version = "1.13.1", default-features = false, features = [
5656
clokwerk = "0.4.0-rc1"
5757
actix-web-static-files = "4.0"
5858
static-files = "0.2.1"
59+
ulid = { version = "1.0", features = ["serde"] }
5960
ureq = { version = "2.5.0", features = ["json"] }
60-
uuid = { version = "1.2.1", features = ["v4", "fast-rng", "serde"] }
6161

6262
[build-dependencies]
6363
static-files = "0.2.1"

server/src/alerts/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
*/
1818

1919
use serde::{Deserialize, Serialize};
20-
use uuid::Uuid;
2120

2221
pub mod rule;
2322
pub mod target;
2423

24+
use crate::utils::uid::Uid;
25+
2526
pub use self::rule::Rule;
2627
use self::target::Target;
2728

@@ -34,8 +35,8 @@ pub struct Alerts {
3435
#[derive(Debug, Serialize, Deserialize)]
3536
#[serde(rename_all = "camelCase")]
3637
pub struct Alert {
37-
#[serde(default = "crate::utils::uuid::gen")]
38-
pub id: Uuid,
38+
#[serde(default = "crate::utils::uid::gen")]
39+
pub id: Uid,
3940
pub name: String,
4041
pub message: String,
4142
pub rule: Rule,

server/src/storage/store_metadata.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::{
2424
use serde::{Deserialize, Serialize};
2525
use std::io;
2626

27-
use crate::{option::CONFIG, utils::hostname_unchecked};
27+
use crate::{option::CONFIG, utils::uid};
2828

2929
use super::{object_storage::PARSEABLE_METADATA_FILE_NAME, ObjectStorageError};
3030

@@ -34,7 +34,8 @@ pub struct StorageMetadata {
3434
pub mode: String,
3535
pub staging: PathBuf,
3636
pub storage: String,
37-
pub deployment_id: String,
37+
#[serde(default = "crate::utils::uid::gen")]
38+
pub deployment_id: uid::Uid,
3839
pub user: Vec<User>,
3940
pub stream: Vec<String>,
4041
}
@@ -53,7 +54,7 @@ impl StorageMetadata {
5354
mode: CONFIG.storage_name.to_owned(),
5455
staging: CONFIG.staging_dir().canonicalize().unwrap(),
5556
storage: CONFIG.storage().get_endpoint(),
56-
deployment_id: hostname_unchecked(),
57+
deployment_id: uid::gen(),
5758
user: Vec::new(),
5859
stream: Vec::new(),
5960
}

server/src/utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@ pub fn capitalize_ascii(s: &str) -> String {
121121
s[0..1].to_uppercase() + &s[1..]
122122
}
123123

124-
pub mod uuid {
125-
use uuid::Uuid;
124+
pub mod uid {
125+
use ulid::Ulid;
126126

127-
pub fn gen() -> Uuid {
128-
Uuid::new_v4()
127+
pub type Uid = Ulid;
128+
129+
pub fn gen() -> Ulid {
130+
Ulid::new()
129131
}
130132
}
131133

0 commit comments

Comments
 (0)