mix selecto.gen.domain (selecto_mix v0.4.2)
Generate Selecto domain configuration from Ecto schemas or database relations with Igniter support.
This task automatically discovers Ecto schemas in your project and generates corresponding Selecto domain configurations. It preserves user customizations when re-run and supports incremental updates when database schemas change.
Examples
# Generate domain for a single schema
mix selecto.gen.domain Blog.Post
# Generate domains for all schemas in a context
mix selecto.gen.domain Blog.*
# Generate domains for all schemas in the project
mix selecto.gen.domain --all
# Generate with specific output directory
mix selecto.gen.domain Blog.Post --output lib/blog/selecto_domains
# Force regenerate (overwrites customizations)
mix selecto.gen.domain Blog.Post --force
# Expand associated schemas with full columns/associations
mix selecto.gen.domain Blog.Post --expand-schemas categories,tags,authors
# Generate a read-only domain from an existing database view
mix selecto.gen.domain --adapter postgresql --view reporting.active_customers --primary-key customer_id
# Generate from a materialized view
mix selecto.gen.domain --adapter postgresql --materialized-view reporting.daily_rollup --primary-key customer_id
# Use special join modes for optimized queries
mix selecto.gen.domain Product --expand-tag Tags:name --expand-star Category:category_nameOptions
--all- Generate domains for all discovered Ecto schemas--output- Specify output directory (default: lib/APP_NAME/selecto_domains)--force- Overwrite existing domain files without merging customizations--dry-run- Show what would be generated without creating files--include-associations- Include associations as joins (default: true)--exclude- Comma-separated list of schemas to exclude--live- Generate LiveView files for the domain--saved-views- Generate saved views implementation (requires --live)--expand-schemas- Comma-separated list of associated schemas to fully expand with columns and associations--expand-tag- Many-to-many tag mode: TableName:display_field (uses IDs, prevents denormalization)--expand-star- Star schema mode: TableName:display_field (lookup table with ID-based filtering)--expand-lookup- Lookup table mode: TableName:display_field (small reference tables)--expand-polymorphic- Polymorphic association: field_name:type_field,id_field:Type1,Type2,Type3--parameterized-joins- Generate example parameterized join configurations--path- Custom path for the LiveView route (e.g., /products instead of /product)--enable-modal- Enable modal detail view for row clicks in LiveView (requires --live)--view- Introspect an existing database view as a read-only domain source--materialized-view- Introspect an existing materialized view as a read-only domain source--primary-key- Explicit primary key column for DB views/materialized views--include-views- Include views and materialized views when generating DB-backed domains with--all
File Generation
For each schema, generates:
schemas/SCHEMA_NAME_domain.ex- Selecto domain configuration
With --live flag, additionally generates:
live/SCHEMA_NAME_live.ex- LiveView modulelive/SCHEMA_NAME_live.html.heex- LiveView template
With --saved-views flag, additionally generates:
- SavedView schema and context modules (if not already present)
- Saved views integration in the LiveView
Customization Preservation
When re-running the task, user customizations are preserved by:
- Detecting custom fields, filters, and joins
- Merging new schema fields with existing customizations
- Preserving custom domain metadata and configuration
- Backing up original files before major changes
The generated files include special markers that help identify generated vs. customized sections.