From 82091bdb0a0dd595fc185071bc870b9069cf21fe Mon Sep 17 00:00:00 2001 From: MFijak Date: Mon, 1 Aug 2022 10:08:44 +0200 Subject: [PATCH] fixes for mysql, sqlite --- .../up.sql | 8 ++--- .../up.sql | 2 +- src/db/models/group.rs | 32 +++++++++---------- src/db/schemas/mysql/schema.rs | 6 ++-- src/db/schemas/sqlite/schema.rs | 6 ++-- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/migrations/mysql/2022-07-27-110000_add_group_support/up.sql b/migrations/mysql/2022-07-27-110000_add_group_support/up.sql index ff81b589..ce0622fa 100644 --- a/migrations/mysql/2022-07-27-110000_add_group_support/up.sql +++ b/migrations/mysql/2022-07-27-110000_add_group_support/up.sql @@ -1,4 +1,4 @@ -CREATE TABLE ´groups´ ( +CREATE TABLE `groups` ( uuid CHAR(36) NOT NULL PRIMARY KEY, organizations_uuid VARCHAR(40) NOT NULL REFERENCES organizations (uuid), name VARCHAR(100) NOT NULL, @@ -9,14 +9,14 @@ CREATE TABLE ´groups´ ( ); CREATE TABLE groups_users ( - groups_uuid CHAR(36) NOT NULL REFERENCES ´groups´ (uuid), + groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid), users_organizations_uuid VARCHAR(36) NOT NULL REFERENCES users_organizations (uuid), - UNIQUE (group_uuid, users_organizations_uuid) + UNIQUE (groups_uuid, users_organizations_uuid) ); CREATE TABLE collection_groups ( collections_uuid VARCHAR(40) NOT NULL REFERENCES collections (uuid), - groups_uuid CHAR(36) NOT NULL REFERENCES ´groups´ (uuid), + groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid), read_only BOOLEAN NOT NULL, hide_passwords BOOLEAN NOT NULL, UNIQUE (collections_uuid, groups_uuid) diff --git a/migrations/sqlite/2022-07-27-110000_add_group_support/up.sql b/migrations/sqlite/2022-07-27-110000_add_group_support/up.sql index b4b90d11..3f285b94 100644 --- a/migrations/sqlite/2022-07-27-110000_add_group_support/up.sql +++ b/migrations/sqlite/2022-07-27-110000_add_group_support/up.sql @@ -11,7 +11,7 @@ CREATE TABLE groups ( CREATE TABLE groups_users ( groups_uuid TEXT NOT NULL REFERENCES groups (uuid), users_organizations_uuid TEXT NOT NULL REFERENCES users_organizations (uuid), - UNIQUE (group_uuid, users_organizations_uuid) + UNIQUE (groups_uuid, users_organizations_uuid) ); CREATE TABLE collection_groups ( diff --git a/src/db/models/group.rs b/src/db/models/group.rs index 4702ebc9..a9ed9ad9 100644 --- a/src/db/models/group.rs +++ b/src/db/models/group.rs @@ -188,10 +188,10 @@ impl CollectionGroup { sqlite, mysql { match diesel::replace_into(collection_groups::table) .values(( - collection_groups::collections_uuid.eq(collections_uuid), - collection_groups::groups_uuid.eq(groups_uuid), - collection_groups::read_only.eq(read_only), - collection_groups::hide_passwords.eq(hide_passwords), + collection_groups::collections_uuid.eq(&self.collections_uuid), + collection_groups::groups_uuid.eq(&self.groups_uuid), + collection_groups::read_only.eq(&self.read_only), + collection_groups::hide_passwords.eq(&self.hide_passwords), )) .execute(conn) { @@ -199,13 +199,13 @@ impl CollectionGroup { // Record already exists and causes a Foreign Key Violation because replace_into() wants to delete the record first. Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => { diesel::update(collection_groups::table) - .filter(collection_groups::collections_uuid.eq(self.collections_uuid)) - .filter(collection_groups::groups_uuid.eq(self.groups_uuid)) + .filter(collection_groups::collections_uuid.eq(&self.collections_uuid)) + .filter(collection_groups::groups_uuid.eq(&self.groups_uuid)) .set(( - collection_groups::collections_uuid.eq(self.collections_uuid), - collection_groups::groups_uuid.eq(self.groups_uuid), - collection_groups::read_only.eq(self.read_only), - collection_groups::hide_passwords.eq(self.hide_passwords), + collection_groups::collections_uuid.eq(&self.collections_uuid), + collection_groups::groups_uuid.eq(&self.groups_uuid), + collection_groups::read_only.eq(&self.read_only), + collection_groups::hide_passwords.eq(&self.hide_passwords), )) .execute(conn) .map_res("Error adding group to collection") @@ -281,8 +281,8 @@ impl GroupUser { sqlite, mysql { match diesel::replace_into(groups_users::table) .values(( - groups_users::users_organizations_uuid.eq(users_organizations_uuid), - groups_users::groups_uuid.eq(groups_uuid), + groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid), + groups_users::groups_uuid.eq(&self.groups_uuid), )) .execute(conn) { @@ -290,11 +290,11 @@ impl GroupUser { // Record already exists and causes a Foreign Key Violation because replace_into() wants to delete the record first. Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => { diesel::update(groups_users::table) - .filter(groups_users::users_organizations_uuid.eq(self.users_organizations_uuid)) - .filter(groups_users::groups_uuid.eq(self.groups_uuid)) + .filter(groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid)) + .filter(groups_users::groups_uuid.eq(&self.groups_uuid)) .set(( - groups_users::users_organizations_uuid.eq(self.users_organizations_uuid), - groups_users::groups_uuid.eq(self.groups_uuid), + groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid), + groups_users::groups_uuid.eq(&self.groups_uuid), )) .execute(conn) .map_res("Error adding user to group") diff --git a/src/db/schemas/mysql/schema.rs b/src/db/schemas/mysql/schema.rs index b1ba25fe..b388e864 100644 --- a/src/db/schemas/mysql/schema.rs +++ b/src/db/schemas/mysql/schema.rs @@ -228,14 +228,14 @@ table! { access_all -> Bool, external_id -> Text, creation_date -> Timestamp, - revision_date -> Timestamp + revision_date -> Timestamp, } } table! { groups_users (groups_uuid, users_organizations_uuid) { groups_uuid -> Text, - users_organizations_uuid -> Text + users_organizations_uuid -> Text, } } @@ -244,7 +244,7 @@ table! { collections_uuid -> Text, groups_uuid -> Text, read_only -> Bool, - hide_passwords -> Bool + hide_passwords -> Bool, } } diff --git a/src/db/schemas/sqlite/schema.rs b/src/db/schemas/sqlite/schema.rs index 3657f00b..5ff0d60b 100644 --- a/src/db/schemas/sqlite/schema.rs +++ b/src/db/schemas/sqlite/schema.rs @@ -228,14 +228,14 @@ table! { access_all -> Bool, external_id -> Text, creation_date -> Timestamp, - revision_date -> Timestamp + revision_date -> Timestamp, } } table! { groups_users (groups_uuid, users_organizations_uuid) { groups_uuid -> Text, - users_organizations_uuid -> Text + users_organizations_uuid -> Text, } } @@ -244,7 +244,7 @@ table! { collections_uuid -> Text, groups_uuid -> Text, read_only -> Bool, - hide_passwords -> Bool + hide_passwords -> Bool, } }