Cleanup use statements
This commit is contained in:
parent
d09b280061
commit
c5100f31e5
|
|
@ -1,11 +1,10 @@
|
|||
use askama::Template;
|
||||
use axum::{
|
||||
body::Body, extract::{Path, Query, Request, State}, response::{Html, IntoResponse, Redirect, Response}, Extension
|
||||
extract::{Path, Query, State}, response::{Html, IntoResponse, Redirect, Response}, Extension
|
||||
};
|
||||
use http::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::{types::Json, PgPool, Row};
|
||||
use sqlx::{PgPool, Row};
|
||||
|
||||
use crate::{
|
||||
middlewares::is_authorized,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use axum::{
|
|||
};
|
||||
use dotenvy::var;
|
||||
use secret_gift_exchange::{giftexchange, giftexchange_save, giftexchanges};
|
||||
use sqlx::{migrate::Migrator, sqlite::SqlitePoolOptions, sqlite::SqliteRow, Row, SqlitePool};
|
||||
use sqlx::{migrate::Migrator, sqlite::SqlitePoolOptions, Row, SqlitePool};
|
||||
use sqlx::{postgres::PgPoolOptions, PgPool};
|
||||
use std::net::SocketAddr;
|
||||
use tower_http::services::ServeDir;
|
||||
|
|
@ -25,7 +25,7 @@ use error_handling::AppError;
|
|||
use google_oauth::{google_auth_return, login, logout};
|
||||
use middlewares::inject_user_data;
|
||||
use routes::{about, contact, dashboard, index, profile, user_profile, user_profile_account, useradmin};
|
||||
use user::{add_user_role, delete_user_role, user_account, UserData};
|
||||
use user::{add_user_role, delete_user_role, UserData};
|
||||
use wishlist::{
|
||||
user_wishlist, user_wishlist_add, user_wishlist_add_item, user_wishlist_bought_item,
|
||||
user_wishlist_delete_item, user_wishlist_edit_item, user_wishlist_received_item,
|
||||
|
|
@ -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") {
|
||||
|
|
@ -315,4 +315,45 @@ async fn copy_database(sdb_pool: &SqlitePool, db_pool: &PgPool) {
|
|||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Run migration scripts again
|
||||
// Copy accounts(users) to profiles(people)
|
||||
let result =sqlx::query(r#"insert into people (created_by, updated_by, email, name, family_name, given_name)
|
||||
select created_by, updated_by, email, name, family_name, given_name from users
|
||||
on conflict do nothing;"#)
|
||||
.execute(db_pool)
|
||||
.await;
|
||||
|
||||
if let Err(e) = result {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
|
||||
// Link accounts to profiles
|
||||
let result = sqlx::query(r#"update users u set person_id = p.id from people p where p.email = u.email;"#)
|
||||
.execute(db_pool)
|
||||
.await;
|
||||
|
||||
if let Err(e) = result {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
|
||||
// Move wishlist items from accounts to profiles
|
||||
let result = sqlx::query(r#"update wishlist_items wi set user_id = p.person_id from users p where p.id = wi.user_id;"#)
|
||||
.execute(db_pool)
|
||||
.await;
|
||||
|
||||
if let Err(e) = result {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
|
||||
// Copy normal role from accounts to profiles
|
||||
let result = sqlx::query(r#"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;"#)
|
||||
.execute(db_pool)
|
||||
.await;
|
||||
|
||||
if let Err(e) = result {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use axum::{
|
|||
Extension,
|
||||
};
|
||||
use http::StatusCode;
|
||||
use reqwest::redirect;
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use askama::Template;
|
||||
use axum::{
|
||||
body::{self, Body},
|
||||
extract::{FromRequest, Path, Request, State},
|
||||
extract::{Path, Request, State},
|
||||
response::{Html, IntoResponse, Redirect, Response},
|
||||
Extension, Form, Json, RequestExt,
|
||||
Extension,
|
||||
};
|
||||
use http::{header::CONTENT_TYPE, StatusCode};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
|||
Loading…
Reference in New Issue