Move wishlists to the profile

This commit is contained in:
Chris Jean-Marie 2025-03-26 13:35:51 +00:00
parent 1589ebfd37
commit a8ca9bfafe
3 changed files with 12 additions and 4 deletions

View File

@ -28,3 +28,8 @@ 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;
-- 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;

View File

@ -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") {

View File

@ -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();