Skip to content

Conversation

@elcoosp
Copy link

@elcoosp elcoosp commented Nov 24, 2025

Description

This PR migrates Loco.rs from SeaORM 1.x to SeaORM 2.0, including all necessary code updates and dependency changes to support the new version.

Changes

1. Dependency Updates

  • Updated sea-orm from 1.1.0 to 2.0.0-rc.19
  • Updated sea-orm-migration from 1.0.0 to 2.0.0-rc.19
  • Added temporary patch for sea-query to use a custom git repository during migration

2. Query DSL Module Refactor

  • Removed IntoCondition implementation for ConditionBuilder
  • Replaced with From<ConditionBuilder> for Condition implementation
  • Updated ConditionBuilder to be Clone
  • Simplified the build() method to return Condition directly

3. Database Schema Migration

  • Updated enum existence check to use query_one_raw instead of query_one
  • Added handling for additional database backends with unimplemented!() fallbacks
  • Fixed PostgreSQL-specific enum operations

4. Database Operations

  • Replaced deprecated query_one with query_one_raw across the codebase
  • Updated execute calls to execute_raw for schema operations
  • Added proper error handling for database operations

5. Iden Trait Implementation

  • Updated Iden implementation for the Loco enum to match SeaORM 2.0 API changes
  • Changed unquoted method signature to return &str instead of writing to a formatter

6. Middleware Updates

  • Updated timeout middleware to use TimeoutLayer::with_status_code
  • Added proper HTTP status code handling (408 Request Timeout)
  • Used StatusCode::from_u16 for status code creation

7. Template Updates

  • Updated base template Cargo.toml files to use SeaORM 2.0
  • Updated migration template dependencies

Breaking Changes Addressed

SeaORM 2.0 API Changes:

  • query_one()query_one_raw()
  • execute()execute_raw() (for schema operations)
  • Iden::unquoted() signature change
  • Removal of IntoCondition trait in favor of From trait
  • Non-exhaustive database backend enum requiring default cases

Condition Building:

// Before (SeaORM 1.x)
impl IntoCondition for ConditionBuilder {
    fn into_condition(self) -> Condition {
        self.build()
    }
}

// After (SeaORM 2.0)
impl From<ConditionBuilder> for Condition {
    fn from(builder: ConditionBuilder) -> Self {
        builder.condition
    }
}

Database Operations:

// Before
conn.query_one(Statement::from_string(/* ... */))

// After  
conn.query_one_raw(Statement::from_string(/* ... */))

Testing

  • Database migrations work correctly
  • Query building functions properly
  • Middleware timeout functionality
  • All database backends (PostgreSQL, SQLite, MySQL)
  • Template generation for new projects

Notes

  • Temporary sea-query patch is used to address immediate compatibility issues
  • Some database backend features are marked as unimplemented for non-PostgreSQL databases
  • This migration maintains backward compatibility for Loco.rs users while enabling SeaORM 2.0 features

Next Steps

  • Remove temporary sea-query patch once upstream issues are resolved
  • Update documentation with SeaORM 2.0 examples
  • Ensure migration templates are correct

This migration ensures Loco.rs remains compatible with the latest SeaORM version while maintaining all existing functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant