fix: auto-apply DB schema on fresh install and fix admin registration (#81)

- Auto-apply schema.sql when database tables don't exist (embedded in binary)
- Handle missing tables gracefully during admin registration (treat as fresh install)
- Fix docker-compose depends_on to wait for postgres healthcheck
- Rename personal folder from 'Mi Carpeta' to 'My Folder' with backward compat
- Translate remaining Spanish messages to English
This commit is contained in:
Dionisio
2026-02-12 14:45:52 +01:00
parent 321fae7dcb
commit ad07a5abda
9 changed files with 58 additions and 26 deletions
+20 -2
View File
@@ -39,11 +39,29 @@ pub async fn create_database_pool(config: &AppConfig) -> Result<PgPool> {
Ok(row) => {
let tables_exist: bool = row.get(0);
if !tables_exist {
tracing::warn!("Database tables do not exist. Please run migrations with: cargo run --bin migrate --features migrations");
tracing::warn!("Database tables do not exist. Auto-applying schema...");
let schema_sql = include_str!("../../db/schema.sql");
match sqlx::raw_sql(schema_sql).execute(&pool).await {
Ok(_) => {
tracing::info!("Database schema applied successfully");
},
Err(e) => {
tracing::error!("Failed to auto-apply database schema: {}. You may need to run: psql -f db/schema.sql", e);
}
}
}
},
Err(_) => {
tracing::warn!("Could not verify migration status. Please run migrations with: cargo run --bin migrate --features migrations");
tracing::warn!("Could not verify migration status. Attempting to auto-apply schema...");
let schema_sql = include_str!("../../db/schema.sql");
match sqlx::raw_sql(schema_sql).execute(&pool).await {
Ok(_) => {
tracing::info!("Database schema applied successfully");
},
Err(e) => {
tracing::error!("Failed to auto-apply database schema: {}. You may need to run: psql -f db/schema.sql", e);
}
}
}
}
@@ -54,7 +54,7 @@ impl UserPgRepository {
impl UserRepository for UserPgRepository {
/// Creates a new user using a transaction
async fn create_user(&self, user: User) -> UserRepositoryResult<User> {
// Creamos una copia del usuario para el closure
// Create a copy of the user for the closure
let user_clone = user.clone();
with_transaction(
@@ -43,7 +43,7 @@ impl PasswordHasherPort for Argon2PasswordHasher {
.map_err(|e| DomainError::new(
ErrorKind::InternalError,
"PasswordHasher",
format!("Error al generar hash de password: {}", e)
format!("Error generating password hash: {}", e)
))
}
@@ -52,7 +52,7 @@ impl PasswordHasherPort for Argon2PasswordHasher {
.map_err(|e| DomainError::new(
ErrorKind::InternalError,
"PasswordHasher",
format!("Error al procesar hash: {}", e)
format!("Error processing password hash: {}", e)
))?;
Ok(Argon2::default().verify_password(password.as_bytes(), &parsed_hash).is_ok())