fix: add user to auth user
This commit is contained in:
parent
583edfdb72
commit
768d683878
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue