Skip to content

Conversation

@RAprogramm
Copy link
Owner

@RAprogramm RAprogramm commented Jan 8, 2026

Summary

  • Add compile-time migration generation from Entity definitions
  • Support full column constraints: unique, index, default, check, varchar
  • Support composite indexes at entity level
  • Support foreign key references with ON DELETE actions
  • PostgreSQL DDL generation (CREATE TABLE, CREATE INDEX, DROP TABLE)

Usage

#[derive(Entity)]
#[entity(table = "users", migrations)]
pub struct User {
    #[id]
    pub id: Uuid,

    #[column(unique, index)]
    pub email: String,

    #[column(varchar = 100)]
    pub name: String,

    #[belongs_to(Organization, on_delete = "cascade")]
    pub org_id: Uuid,
}

// Generated:
// User::MIGRATION_UP - CREATE TABLE SQL
// User::MIGRATION_DOWN - DROP TABLE SQL

- Add ColumnConfig for column-level constraints (#[column(...)])
  - unique, index, default, check, varchar, sql_type, nullable, name
- Add CompositeIndexDef for entity-level indexes
  - #[entity(index(col1, col2), unique_index(...))]
- Add ReferentialAction for ON DELETE/UPDATE actions
- Extend StorageConfig with on_delete for #[belongs_to]
- Add migrations flag to EntityAttrs and EntityDef
- Add parse_index_attrs helper for composite indexes
- Add PostgresTypeMapper for Rust -> PostgreSQL type mapping
- Create migrations module structure (types/, postgres/)
- Add ColumnConfig parsing for column constraints (unique, index,
  default, check, varchar, sql_type, nullable)
- Add IndexType enum (BTree, Hash, Gin, Gist, Brin) for index types
- Add ReferentialAction enum for ON DELETE actions
- Add CompositeIndexDef for entity-level composite indexes
- Add PostgresTypeMapper for Rust to PostgreSQL type mapping
- Generate MIGRATION_UP and MIGRATION_DOWN constants
- Support full DDL: CREATE TABLE, CREATE INDEX, DROP TABLE CASCADE
- Add column attribute to derive macro
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 99.56772% with 6 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ntity-derive-impl/src/entity/parse/field/column.rs 99.11% 2 Missing ⚠️
...ity-derive-impl/src/entity/sql/postgres/helpers.rs 98.73% 2 Missing ⚠️
...erive-impl/src/entity/migrations/types/postgres.rs 99.42% 1 Missing ⚠️
...ity-derive-impl/src/entity/parse/entity/helpers.rs 99.57% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

RAprogramm and others added 5 commits January 8, 2026 09:24
- Add unit tests for sql/postgres/helpers.rs (100% coverage)
- Add tests for migrations/mod.rs (100% coverage)
- Add tests for migrations/postgres/ddl.rs (100% coverage)
- Add tests for parse/field/column.rs IndexType::from_str
- Add tests for parse/entity/index.rs builder methods
- Export IndexType from parse module for test usage
- Remove unused parse_index_meta function from index.rs (duplicate of
  parse_index_content in helpers.rs)
- Fix parse_index_attrs to properly consume all nested meta items
  (was failing to parse indexes when other attrs like table = "..." came first)
- Fix parse_index_content to distinguish between `name` column and
  `name = "..."` option by checking for `=` sign
- Add 19 comprehensive tests for parse_index_attrs covering all index options
- Coverage: helpers.rs 47.75% -> 96.01%, index.rs 77.45% -> 100%
@RAprogramm RAprogramm merged commit ac35092 into main Jan 8, 2026
16 checks passed
@RAprogramm RAprogramm deleted the feature/migrations branch January 8, 2026 03:35
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.

2 participants