Nesting directories
Nesting models in directories
Section titled “Nesting models in directories”As your collection of datagen models grows, you can organize them into nested directory structures. This allows you to:
- Namespace your models - Avoid naming conflicts by organizing models in separate directories
- Group related models - Structure models by service, domain, feature, or any criteria that suits your needs
- Maintain clarity - Keep large codebases organized and easier to navigate
You are free to organize your directories however you wish. For example, you might structure them by:
- Services or microservices
- Database schemas
- Business domains
- Features or modules
Example structure
Section titled “Example structure”Consider organizing models by service, where each service has its own set of tables:
models/├── serviceA/│ ├── tableA.dg│ ├── tableB.dg│ └── tableC.dg└── serviceB/ ├── tableA.dg ├── tableD.dg └── tableE.dgReferencing nested models
Section titled “Referencing nested models”When referencing models in nested directories, use the fully qualified path:
self.datagen.<directory>.<model>().<field>()For the structure above:
- To refer to
tableBinserviceA:self.datagen.serviceA.tableB().<column>() - To refer to
tableDinserviceB:self.datagen.serviceB.tableD().<column>()
All paths are relative to the root models directory you provide to datagen.
Running datagen with nested directories
Section titled “Running datagen with nested directories”For example, if your models are organized as shown above:
# Correct - provide the root directorydatagen -d ./models -o output
# Incorrect - providing subdirectories will cause errorsdatagen -d ./models/serviceA -o outputdatagen -d ./models/serviceB -o outputProviding individual subdirectories like serviceA or serviceB will cause data generation errors, especially when models reference each other across directories using self.datagen paths.