# Entity maker ## Description Application connects to postgres database, inspects targeted table and creates: - sqlalchemy table - model - filter - load options - repository - manager - factory - mapper ## Generated files Generated source files are targeted for Python 3.13 using SQLAlchemy. All example files import from televend_core.databases.*, our a specific in-house framework. Pluralization should be not just handling the *s* suffix, but using proper english. ### Foreign key relationships Create imports following naming rules. For example, for author_info table, create import as `from televend_core.databases.televend_repositories.author_info.model import AuthorInfo` Strip `_id` suffix from field name and use proper entity name. ### PostgreSQL enum types Query PostgreSQL system catalogs to get enum values and place it in `enum.py` output file. Also, use those values in factory, as in example. ### Reverse relationships Skip reverse relationships entirely. They will be added manually later when files are generated. ### Filter field selection Available filter operators are listed in `./example/filters.py`. Generate filters using following rules: - All boolean fields: create filter with EQ operator - All ID fields (primary key and foreign keys): create filters with both EQ and IN operators. For IN operator, use plural field name (e.g., `ids: list[int]` for `id` field, `machine_ids: list[int]` for `machine_id` field) - All text fields (varchar, text): create filter with EQ operator only ### Mapper file Generate mapper file snippet without import statements. Map all foreign keys as relationships. User will manually remove relationships that are not important later. ### Load options Load options should include all relationships defined in the mapper file. ### Factory special cases Ignore factory special cases (e.g., using `.user_ptr_id` instead of `.id`). Use standard `.id` for all foreign key references. ### Missing fields in model Include all fields from database table in the generated model, even if missing in example. ## Input parameters Application have following command line parameters: - optional db host - default `localhost` - optional db port - default `5432` - optional db name - optional db schema - default `public` - optional db user - default `postgres` - optional db password - default `postgres` - optional db table - optional output directory - optional entity name When application starts, it will offer users to enter missing parameters from command line, using defaults as listed above. Save entered values in `~/.config/entity-maker.toml` and use it for the next time. ### CLI prompts behavior - Display current value from config file (if exists) - Allow pressing Enter to accept default or stored value - Validate inputs: - Port must be numeric - Database name is required (no default) - Table name is required (no default) - Output directory must exist or be creatable Generated files are placed in specificied output directory, in subdirectory named after table name, but in sigular. Check naming section for details. Optional entity name should override the automatically generated entity name. ## Examples Example sql table structure is located in `./example/cashbag_conforms.sql`. Example output is located in `./example/cashbag_conform`. Note: In the example SQL, the `route_id` field is deprecated and not used in generated files. This is intentional and should not be used as reference. ## Naming example Table name: `cashbag_conforms`. Output subdirectory: `cashbag_conform` Model name: `CashbagConform` Filter name `CashbagConformFilter` Load options name `CashbagConformLoadOptions` Repository name `CashbagConformRepository` Manager name `CashbagConformManager` Factory name `CashbagConformFactory` ## Technologies used This is command line application. Application is written in golang. Application needs to be run on Linux only, no need to support other operating systems. Make application output modern and colorful.