fix: add user to auth user

This commit is contained in:
Zack Fu Zi Xiang 2024-04-09 03:10:12 +08:00
parent 583edfdb72
commit 768d683878
No known key found for this signature in database
2 changed files with 22 additions and 6 deletions

View File

@ -9,11 +9,13 @@ pub async fn setup_db(pool: &PgPool) -> anyhow::Result<()> {
// migration scripts. // migration scripts.
sqlx::query(r#"create schema auth"#).execute(pool).await?; sqlx::query(r#"create schema auth"#).execute(pool).await?;
sqlx::query( sqlx::query(
r#"create table auth.users( r#"
id uuid NOT NULL UNIQUE, CREATE TABLE auth.users(
deleted_at timestamptz null, id uuid NOT NULL UNIQUE,
CONSTRAINT users_pkey PRIMARY KEY (id) deleted_at timestamptz null,
)"#, CONSTRAINT users_pkey PRIMARY KEY (id)
)
"#,
) )
.execute(pool) .execute(pool)
.await?; .await?;
@ -26,6 +28,19 @@ CONSTRAINT users_pkey PRIMARY KEY (id)
Ok(()) Ok(())
} }
pub async fn insert_auth_user(pool: &PgPool, user_uuid: Uuid) -> anyhow::Result<()> {
sqlx::query(
r#"
INSERT INTO auth.users (id)
VALUES ($1)
"#,
)
.bind(user_uuid)
.execute(pool)
.await?;
Ok(())
}
lazy_static! { lazy_static! {
pub static ref ID_GEN: RwLock<Snowflake> = RwLock::new(Snowflake::new(1)); pub static ref ID_GEN: RwLock<Snowflake> = RwLock::new(Snowflake::new(1));
} }

View File

@ -1,4 +1,4 @@
use crate::pg_sql::util::{setup_db, test_create_user}; use crate::pg_sql::util::{insert_auth_user, setup_db, test_create_user};
use sqlx::PgPool; use sqlx::PgPool;
#[sqlx::test(migrations = false)] #[sqlx::test(migrations = false)]
@ -9,6 +9,7 @@ async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
let name = user_uuid.to_string(); let name = user_uuid.to_string();
let email = format!("{}@appflowy.io", name); let email = format!("{}@appflowy.io", name);
insert_auth_user(&pool, user_uuid).await.unwrap();
test_create_user(&pool, user_uuid, &email, &name) test_create_user(&pool, user_uuid, &email, &name)
.await .await
.unwrap(); .unwrap();