Files
imphnen-backend-service/imphnen-backend/src/bin/seed_mentor_user.rs
T
maulanasdqnandClaude Sonnet 4.6 331a4a4e88 feat: v0.3.0 — standardize codebase, centralize infra, merge QR into CMS
- Enforce axum best practices across all 13 workspace crates
  (max 200 LOC/file, no comments, no unwrap, clean architecture)
- Fix domain→infrastructure dependency inversions in imphnen-iam and imphnen-dimentorin
- Extract imphnen-storage (MinIO) and imphnen-email (Lettre) as standalone crates
- Centralize all config in ENV struct: CDN_URL, CORS_ALLOWED_ORIGINS
- Centralize SMTP through imphnen-email; remove dead HackathonConfig
- Centralize database: QR crate now shares main DB pool (single DATABASE_URL)
- Rename QR users table to qr_users to avoid collision with main users table
- Merge imphnen-qr into imphnen-cms/src/qr (13 crates, down from 14)
- Restructure imphnen-hackathon flat modules into clean architecture
- Remove all stale env vars from .env.example (SurrealDB, QR_JWT, Hackathon infra)
- Fix Dockerfile to include all current workspace crates
- Bump all crate versions 0.2.0 → 0.3.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 22:29:08 +07:00

91 lines
3.3 KiB
Rust

#![allow(clippy::all)]
use imphnen_entities::seaorm::auth::mentors::ActiveModel as MentorsActiveModel;
use imphnen_entities::seaorm::auth::roles::{
Column as RoleColumn, Entity as RoleEntity,
};
use imphnen_entities::seaorm::auth::users::ActiveModel as UsersActiveModel;
use imphnen_libs::hash_password;
use imphnen_libs::postgres::{PostgresConfig, PostgresConnection};
use sea_orm::{
ActiveModelTrait, ActiveValue::Set, ColumnTrait, ConnectionTrait, EntityTrait,
QueryFilter,
};
use serde_json::json;
use std::error::Error;
use uuid::Uuid;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let config = PostgresConfig::from_env()?;
let pg_conn = PostgresConnection::new(config).await?;
let db = &pg_conn.conn;
let _ = pg_conn
.execute(sea_orm::Statement::from_string(
db.get_database_backend(),
"DELETE FROM app_mentors WHERE id = 'e6f78d23-83bf-5c2b-bcd4-001345678901'"
.to_string(),
))
.await
.ok();
let _ = pg_conn
.execute(sea_orm::Statement::from_string(
db.get_database_backend(),
"DELETE FROM app_users WHERE email = 'mentor@example.com'".to_string(),
))
.await
.ok();
let role = RoleEntity::find()
.filter(RoleColumn::Name.eq("Mentor"))
.one(db)
.await?
.ok_or("Role 'Mentor' not found")?;
let user_id = Uuid::new_v4();
let mut user_model: UsersActiveModel = Default::default();
user_model.id = Set(user_id);
user_model.email = Set("mentor@example.com".to_string());
user_model.password_hash = Set(hash_password("password").unwrap());
user_model.username = Set("mentor@example.com".to_string());
user_model.first_name = Set(Some("Mentor".to_string()));
user_model.last_name = Set(Some("User".to_string()));
user_model.avatar_url = Set(Some("https://example.com/avatar.jpg".to_string()));
user_model.is_active = Set(true);
user_model.is_verified = Set(true);
user_model.role_id = Set(Some(role.id));
user_model.created_at = Set(chrono::Utc::now());
user_model.updated_at = Set(chrono::Utc::now());
user_model.insert(db).await?;
let mentor_id = Uuid::new_v4();
let mut mentor_model: MentorsActiveModel = Default::default();
mentor_model.id = Set(mentor_id);
mentor_model.user_id = Set(user_id);
mentor_model.industries = Set(Some(json!(["Software", "Education"])));
mentor_model.expertise = Set(Some(json!(["Rust", "Microservices"])));
mentor_model.languages = Set(Some(json!(["Indonesian", "English"])));
mentor_model.current_company = Set(Some("PT Contoh".to_string()));
mentor_model.current_role = Set(Some("Senior Backend Engineer".to_string()));
mentor_model.years_of_experience = Set(Some(5));
mentor_model.topics_of_interest =
Set(Some(json!(["Rust Programming", "Backend Development"])));
mentor_model.preferred_mentee_level = Set(Some("beginner".to_string()));
mentor_model.preferred_mentoring_formats = Set(Some(json!(["online", "offline"])));
mentor_model.availability_commitment = Set(Some(
"2 jam per minggu untuk mentoring online dan offline".to_string(),
));
mentor_model.mentoring_rate = Set(Some(100000.0));
mentor_model.status = Set(Some("verified".to_string()));
mentor_model.is_deleted = Set(false);
mentor_model.created_at = Set(chrono::Utc::now());
mentor_model.updated_at = Set(chrono::Utc::now());
mentor_model.insert(db).await?;
println!("Mentor created successfully!");
println!("✅ Inserted mentor user: mentor@example.com");
println!("✅ Mentor user seeded");
Ok(())
}