From a8ca9bfafe1d4b889b89603bd924fa7d82d916dc Mon Sep 17 00:00:00 2001 From: Chris Jean-Marie Date: Wed, 26 Mar 2025 13:35:51 +0000 Subject: [PATCH] Move wishlists to the profile --- backend/migrations/20241221174355_add-person-level.up.sql | 7 ++++++- backend/src/main.rs | 4 ++-- backend/src/wishlist.rs | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/migrations/20241221174355_add-person-level.up.sql b/backend/migrations/20241221174355_add-person-level.up.sql index c19df92..08ee4f6 100644 --- a/backend/migrations/20241221174355_add-person-level.up.sql +++ b/backend/migrations/20241221174355_add-person-level.up.sql @@ -27,4 +27,9 @@ select created_by, updated_by, email, name, family_name, given_name from users; update users u set person_id = p.id from people p where p.email = u.email; -- Move wishlist items from accounts to profiles -update wishlist_items wi set user_id = p.person_id from users p where p.id = wi.user_id; \ No newline at end of file +update wishlist_items wi set user_id = p.person_id from users p where p.id = wi.user_id; + +-- Copy normal role from accounts to profiles +insert into user_roles (created_at, created_by, updated_at, updated_by, user_id, role_id) +select ur.created_at, ur.created_by, ur.updated_at, ur.updated_by, u.person_id, ur.role_id from user_roles ur join roles r on r.id = ur.role_id join users u on u.id = ur.user_id where r.name = 'normal' +on conflict do nothing; diff --git a/backend/src/main.rs b/backend/src/main.rs index 94af0a0..4d427dd 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -51,10 +51,10 @@ async fn main() { static MIGRATOR: Migrator = sqlx::migrate!(); - MIGRATOR +/* MIGRATOR .run(&app_state.db_pool) .await - .expect("Failed to run migrations"); + .expect("Failed to run migrations"); */ // Copy from old sqlite database if it exists if let Ok(source_db_url) = var("SOURCE_DB_URL") { diff --git a/backend/src/wishlist.rs b/backend/src/wishlist.rs index 48fdb79..b119e0c 100644 --- a/backend/src/wishlist.rs +++ b/backend/src/wishlist.rs @@ -57,7 +57,10 @@ pub async fn wishlists( let user = user_data.as_ref().unwrap().clone(); let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default(); - let users = sqlx::query_as::<_, UserData>("SELECT * FROM people order by name") + let users = sqlx::query_as::<_, UserData>(r#"SELECT p.* FROM people p + left join user_roles ur on ur.user_id = p.id + left join roles r on r.id = ur.role_id + where r.name = 'normal' order by p.name;"#) .fetch_all(&db_pool) .await .unwrap();