Explorar o código

Use new inline unique index creation from microrm 0.3.12.

Kestrel hai 1 ano
pai
achega
48e8fbb847
Modificáronse 4 ficheiros con 37 adicións e 61 borrados
  1. 5 5
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 4 1
      src/cli.rs
  4. 27 54
      src/schema.rs

+ 5 - 5
Cargo.lock

@@ -1184,9 +1184,9 @@ checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
 
 [[package]]
 name = "microrm"
-version = "0.3.11"
+version = "0.3.12"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2aaa7a6fcb8423617eb742a58270fdce45b0002ad640559965a61dfa54ba11b"
+checksum = "0a480d8dcd5e02d54fd226c23232f42d4a11f80257a2b6cdb7eb971e7a26fb6b"
 dependencies = [
  "base64 0.13.1",
  "lazy_static",
@@ -1201,9 +1201,9 @@ dependencies = [
 
 [[package]]
 name = "microrm-macros"
-version = "0.2.5"
+version = "0.2.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dba04dd721306ec7e301be005366b2e1b7f8562fc0396f914861d890923357fc"
+checksum = "a320ac45baf47907282dfc5de25a26b396b69eaeaede3de20fd7ba9b50838917"
 dependencies = [
  "convert_case",
  "proc-macro2",
@@ -2276,7 +2276,7 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
 
 [[package]]
 name = "uidc"
-version = "0.1.0"
+version = "0.0.1"
 dependencies = [
  "base32",
  "base64 0.13.1",

+ 1 - 1
Cargo.toml

@@ -25,7 +25,7 @@ hmac = { version = "0.12" }
 toml = "0.8.2"
 
 # Data storage dependencies
-microrm = { version = "0.3.11" }
+microrm = { version = "0.3.12" }
 serde_bytes = { version = "0.11.6" }
 
 # Public API/server dependencies

+ 4 - 1
src/cli.rs

@@ -184,7 +184,10 @@ impl ConfigArgs {
             }
             ConfigCommand::Set { key, value } => {
                 qi.delete().by(schema::PersistentConfig::Key, &key).exec()?;
-                qi.insert(&schema::PersistentConfig { key: key.clone(), value: value.clone() })?;
+                qi.insert(&schema::PersistentConfig {
+                    key: key.clone(),
+                    value: value.clone(),
+                })?;
             }
             ConfigCommand::Load { toml_path } => {
                 let config = config::Config::build_from(&qi, Some(toml_path));

+ 27 - 54
src/schema.rs

@@ -5,48 +5,41 @@ use serde::{Deserialize, Serialize};
 /// Simple key-value store for persistent configuration
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct PersistentConfig {
+    #[microrm_unique]
     pub key: String,
     pub value: String,
 }
 
-make_index!(!PersistentConfigIndex, PersistentConfig::Key);
-
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct Session {
+    #[microrm_unique]
     pub key: String,
     // TODO: add expiry here
 }
 
-microrm::make_index!(!SessionKeyIndex, Session::Key);
-
 /// Authentication state for a session. If no challenges are left, it's considered authorized.
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct SessionAuthentication {
     #[microrm_foreign]
+    #[microrm_unique]
     pub realm: RealmID,
     #[microrm_foreign]
+    #[microrm_unique]
     pub session: SessionID,
     #[microrm_foreign]
+    #[microrm_unique]
     pub user: UserID,
 
     pub challenges_left: Vec<AuthChallengeType>,
 }
 
-make_index!(
-    !SessionAuthenticationIndex,
-    SessionAuthentication::Realm,
-    SessionAuthentication::Session,
-    SessionAuthentication::User
-);
-
 // **** oauth types ****
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct Realm {
+    #[microrm_unique]
     pub shortname: String,
 }
 
-make_index!(!RealmIndex, Realm::Shortname);
-
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct Key {
     #[microrm_foreign]
@@ -60,12 +53,12 @@ pub struct Key {
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct User {
     #[microrm_foreign]
+    #[microrm_unique]
     pub realm: RealmID,
+    #[microrm_unique]
     pub username: String,
 }
 
-make_index!(!UserIndex, User::Realm, User::Username);
-
 #[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Modelable, Serialize, Deserialize)]
 pub enum AuthChallengeType {
     Username,
@@ -78,6 +71,7 @@ pub enum AuthChallengeType {
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct AuthChallenge {
     #[microrm_foreign]
+    #[microrm_unique]
     pub user: UserID,
     pub challenge_type: AuthChallengeType,
     #[serde(with = "serde_bytes")]
@@ -87,138 +81,117 @@ pub struct AuthChallenge {
     pub enabled: bool,
 }
 
-make_index!(AuthChallengeIndex, AuthChallenge::User);
-
 /// User semantic grouping
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct Group {
     #[microrm_foreign]
+    #[microrm_unique]
     pub realm: RealmID,
+    #[microrm_unique]
     pub shortname: String,
 }
 
-make_index!(!GroupIndex, Group::Realm, Group::Shortname);
-
 /// User membership in group
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct GroupMembership {
     #[microrm_foreign]
+    #[microrm_unique]
     pub group: GroupID,
     #[microrm_foreign]
+    #[microrm_unique]
     pub user: UserID,
 }
 
-make_index!(
-    !GroupMembershipIndex,
-    GroupMembership::Group,
-    GroupMembership::User
-);
-
 /// OAuth2 client representation
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct Client {
     #[microrm_foreign]
+    #[microrm_unique]
     pub realm: RealmID,
+    #[microrm_unique]
     pub shortname: String,
+
     pub secret: String,
 }
 
-make_index!(!ClientNameIndex, Client::Realm, Client::Shortname);
-
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct ClientRedirect {
     #[microrm_foreign]
+    #[microrm_unique]
     pub client: ClientID,
     pub redirect: String,
 }
 
-make_index!(ClientRedirectIndex, ClientRedirect::Client);
-
 /// Requested group of permissions
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct Scope {
     #[microrm_foreign]
+    #[microrm_unique]
     pub realm: RealmID,
+    #[microrm_unique]
     pub shortname: String,
 }
 
-make_index!(!ScopeIndex, Scope::Realm, Scope::Shortname);
-
 /// Specific atomic permission
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct Role {
     #[microrm_foreign]
+    #[microrm_unique]
     pub realm: RealmID,
+    #[microrm_unique]
     pub shortname: String,
 }
 
-make_index!(!RoleIndex, Role::Realm, Role::Shortname);
-
 /// Role membership in scope
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct ScopeRole {
     #[microrm_foreign]
+    #[microrm_unique]
     pub scope: ScopeID,
     #[microrm_foreign]
+    #[microrm_unique]
     pub role: RoleID,
 }
 
-make_index!(!ScopeRoleIndex, ScopeRole::Scope, ScopeRole::Role);
-
 /// Assigned permissions in group
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct GroupRole {
     #[microrm_foreign]
+    #[microrm_unique]
     pub group: GroupID,
     #[microrm_foreign]
+    #[microrm_unique]
     pub role: RoleID,
 }
 
-make_index!(!GroupRoleIndex, GroupRole::Group, GroupRole::Role);
-
 #[derive(Debug, Entity, Serialize, Deserialize)]
 pub struct RevokedToken {
     #[microrm_foreign]
+    #[microrm_unique]
     pub user: UserID,
+    #[microrm_unique]
     pub nonce: String,
 }
 
-make_index!(!RevokedTokenIndex, RevokedToken::User, RevokedToken::Nonce);
-
 pub fn schema() -> Schema {
     Schema::new()
         // global config types
         .entity::<PersistentConfig>()
-        .index::<PersistentConfigIndex>()
         // session types
         .entity::<Session>()
-        .index::<SessionKeyIndex>()
         .entity::<SessionAuthentication>()
-        .index::<SessionAuthenticationIndex>()
         // oauth types
         .entity::<Realm>()
-        .index::<RealmIndex>()
         .entity::<Key>()
         .entity::<User>()
-        .index::<UserIndex>()
         .entity::<AuthChallenge>()
-        .index::<AuthChallengeIndex>()
         .entity::<Group>()
-        .index::<GroupIndex>()
         .entity::<GroupMembership>()
-        .index::<GroupMembershipIndex>()
         .entity::<Client>()
-        .index::<ClientNameIndex>()
         .entity::<ClientRedirect>()
-        .index::<ClientRedirectIndex>()
         .entity::<Scope>()
-        .index::<ScopeIndex>()
         .entity::<Role>()
-        .index::<RoleIndex>()
         .entity::<ScopeRole>()
-        .index::<ScopeRoleIndex>()
         .entity::<GroupRole>()
-        .index::<GroupRoleIndex>()
         .entity::<RevokedToken>()
-        .index::<RevokedTokenIndex>()
 }