| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
use makenotwork::db::{ProjectId, UserId}; |
| 16 |
use sqlx::PgPool; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
pub(crate) async fn seed_user(pool: &PgPool, username: &str) -> UserId { |
| 21 |
let hash = |
| 22 |
makenotwork::auth::hash_password("password123").expect("hash password for seed user"); |
| 23 |
sqlx::query_scalar::<_, UserId>( |
| 24 |
"INSERT INTO users (username, email, password_hash, email_verified) |
| 25 |
VALUES ($1, $2, $3, true) RETURNING id", |
| 26 |
) |
| 27 |
.bind(username) |
| 28 |
.bind(format!("{username}@test.com")) |
| 29 |
.bind(&hash) |
| 30 |
.fetch_one(pool) |
| 31 |
.await |
| 32 |
.expect("seed user") |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
pub(crate) async fn seed_project(pool: &PgPool, user: UserId, slug: &str) -> ProjectId { |
| 37 |
sqlx::query_scalar::<_, ProjectId>( |
| 38 |
"INSERT INTO projects (user_id, slug, title) VALUES ($1, $2, 'P') RETURNING id", |
| 39 |
) |
| 40 |
.bind(user) |
| 41 |
.bind(slug) |
| 42 |
.fetch_one(pool) |
| 43 |
.await |
| 44 |
.expect("seed project") |
| 45 |
} |
| 46 |
|