Browse Source

fixes for mysql, sqlite

pull/2667/head
MFijak 3 years ago
committed by Maximilian Fijak
parent
commit
82091bdb0a
  1. 8
      migrations/mysql/2022-07-27-110000_add_group_support/up.sql
  2. 2
      migrations/sqlite/2022-07-27-110000_add_group_support/up.sql
  3. 32
      src/db/models/group.rs
  4. 6
      src/db/schemas/mysql/schema.rs
  5. 6
      src/db/schemas/sqlite/schema.rs

8
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, uuid CHAR(36) NOT NULL PRIMARY KEY,
organizations_uuid VARCHAR(40) NOT NULL REFERENCES organizations (uuid), organizations_uuid VARCHAR(40) NOT NULL REFERENCES organizations (uuid),
name VARCHAR(100) NOT NULL, name VARCHAR(100) NOT NULL,
@ -9,14 +9,14 @@ CREATE TABLE ´groups´ (
); );
CREATE TABLE groups_users ( 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), 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 ( CREATE TABLE collection_groups (
collections_uuid VARCHAR(40) NOT NULL REFERENCES collections (uuid), 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, read_only BOOLEAN NOT NULL,
hide_passwords BOOLEAN NOT NULL, hide_passwords BOOLEAN NOT NULL,
UNIQUE (collections_uuid, groups_uuid) UNIQUE (collections_uuid, groups_uuid)

2
migrations/sqlite/2022-07-27-110000_add_group_support/up.sql

@ -11,7 +11,7 @@ CREATE TABLE groups (
CREATE TABLE groups_users ( CREATE TABLE groups_users (
groups_uuid TEXT NOT NULL REFERENCES groups (uuid), groups_uuid TEXT NOT NULL REFERENCES groups (uuid),
users_organizations_uuid TEXT NOT NULL REFERENCES users_organizations (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 ( CREATE TABLE collection_groups (

32
src/db/models/group.rs

@ -188,10 +188,10 @@ impl CollectionGroup {
sqlite, mysql { sqlite, mysql {
match diesel::replace_into(collection_groups::table) match diesel::replace_into(collection_groups::table)
.values(( .values((
collection_groups::collections_uuid.eq(collections_uuid), collection_groups::collections_uuid.eq(&self.collections_uuid),
collection_groups::groups_uuid.eq(groups_uuid), collection_groups::groups_uuid.eq(&self.groups_uuid),
collection_groups::read_only.eq(read_only), collection_groups::read_only.eq(&self.read_only),
collection_groups::hide_passwords.eq(hide_passwords), collection_groups::hide_passwords.eq(&self.hide_passwords),
)) ))
.execute(conn) .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. // 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, _)) => { Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => {
diesel::update(collection_groups::table) diesel::update(collection_groups::table)
.filter(collection_groups::collections_uuid.eq(self.collections_uuid)) .filter(collection_groups::collections_uuid.eq(&self.collections_uuid))
.filter(collection_groups::groups_uuid.eq(self.groups_uuid)) .filter(collection_groups::groups_uuid.eq(&self.groups_uuid))
.set(( .set((
collection_groups::collections_uuid.eq(self.collections_uuid), collection_groups::collections_uuid.eq(&self.collections_uuid),
collection_groups::groups_uuid.eq(self.groups_uuid), collection_groups::groups_uuid.eq(&self.groups_uuid),
collection_groups::read_only.eq(self.read_only), collection_groups::read_only.eq(&self.read_only),
collection_groups::hide_passwords.eq(self.hide_passwords), collection_groups::hide_passwords.eq(&self.hide_passwords),
)) ))
.execute(conn) .execute(conn)
.map_res("Error adding group to collection") .map_res("Error adding group to collection")
@ -281,8 +281,8 @@ impl GroupUser {
sqlite, mysql { sqlite, mysql {
match diesel::replace_into(groups_users::table) match diesel::replace_into(groups_users::table)
.values(( .values((
groups_users::users_organizations_uuid.eq(users_organizations_uuid), groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid),
groups_users::groups_uuid.eq(groups_uuid), groups_users::groups_uuid.eq(&self.groups_uuid),
)) ))
.execute(conn) .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. // 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, _)) => { Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => {
diesel::update(groups_users::table) diesel::update(groups_users::table)
.filter(groups_users::users_organizations_uuid.eq(self.users_organizations_uuid)) .filter(groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid))
.filter(groups_users::groups_uuid.eq(self.groups_uuid)) .filter(groups_users::groups_uuid.eq(&self.groups_uuid))
.set(( .set((
groups_users::users_organizations_uuid.eq(self.users_organizations_uuid), groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid),
groups_users::groups_uuid.eq(self.groups_uuid), groups_users::groups_uuid.eq(&self.groups_uuid),
)) ))
.execute(conn) .execute(conn)
.map_res("Error adding user to group") .map_res("Error adding user to group")

6
src/db/schemas/mysql/schema.rs

@ -228,14 +228,14 @@ table! {
access_all -> Bool, access_all -> Bool,
external_id -> Text, external_id -> Text,
creation_date -> Timestamp, creation_date -> Timestamp,
revision_date -> Timestamp revision_date -> Timestamp,
} }
} }
table! { table! {
groups_users (groups_uuid, users_organizations_uuid) { groups_users (groups_uuid, users_organizations_uuid) {
groups_uuid -> Text, groups_uuid -> Text,
users_organizations_uuid -> Text users_organizations_uuid -> Text,
} }
} }
@ -244,7 +244,7 @@ table! {
collections_uuid -> Text, collections_uuid -> Text,
groups_uuid -> Text, groups_uuid -> Text,
read_only -> Bool, read_only -> Bool,
hide_passwords -> Bool hide_passwords -> Bool,
} }
} }

6
src/db/schemas/sqlite/schema.rs

@ -228,14 +228,14 @@ table! {
access_all -> Bool, access_all -> Bool,
external_id -> Text, external_id -> Text,
creation_date -> Timestamp, creation_date -> Timestamp,
revision_date -> Timestamp revision_date -> Timestamp,
} }
} }
table! { table! {
groups_users (groups_uuid, users_organizations_uuid) { groups_users (groups_uuid, users_organizations_uuid) {
groups_uuid -> Text, groups_uuid -> Text,
users_organizations_uuid -> Text users_organizations_uuid -> Text,
} }
} }
@ -244,7 +244,7 @@ table! {
collections_uuid -> Text, collections_uuid -> Text,
groups_uuid -> Text, groups_uuid -> Text,
read_only -> Bool, read_only -> Bool,
hide_passwords -> Bool hide_passwords -> Bool,
} }
} }

Loading…
Cancel
Save