Database

Leicmin uses PostgreSQL. There is no intent in adding more databases at this point. We also believe that the logic should be easy to understand, so there are no intentions of adding triggers or stored procedures into the database tier, only Rust code to manage complex processes.

Database layers

Database work has four related components:

  • The domain module under src/leicmin/src/data/<category>/<entity>/mod.rs contains application-facing types and operations
  • The SeaORM entity src/leicmin/src/data/<category>/<entity>/db.rs contains Model, ActiveModel, columns, and relations
  • A migration under src/leicmin/src/data/migrations/ changes databases that already exist
  • src/leicmin/src/data/migrations/mod.rs registers migrations in execution order

Migration workflow

Persistent schema changes are made only with SeaORM migrations; do not add schema-changing SQL to handlers, startup code, tests, or seed scripts.

  1. Inspect a nearby entity and its migration before choosing names, types, relations, defaults, and timestamp conventions
  2. Create a migration with just add-migration NAME
  3. Update the domain module and SeaORM entity as required
  4. Implement up and down in the generated migration
  5. Check that the migration is registered in migrations/mod.rs
  6. Run just format, just build, and just test the verify the code is correct and the migration works against a temporary PostgreSQL database

Create a migration with:

just add-migration add_widget

This generates a file such as src/leicmin/src/data/migrations/m20261011_033343_add_widget.rs and updates src/leicmin/src/data/migrations/mod.rs.

Migration tracking normally runs each migration once. Use guards such as if_not_exists or conflict-safe inserts only when they are appropriate; do not hide an existing object with the wrong definition.

Topics

Migration history

Leicmin previously used SQLx migrations. The legacy _sqlx_migrations history is checked separately from the current SeaORM seaql_migrations history. Do not reorder or remove entries from the legacy compatibility list in src/leicmin/src/data/mod.rs.

src/leicmin/src/data/schema.rs is legacy holdover code from the original Diesel/Rust implementation. It is not part of the active database migration path and must not be modified for new schema changes. All known instllations of Leicmin have already been updated and no changes should be made to this file.

Metadata

Project

Forges