Data Seeding Metadata
Data Seeding Metadata
Data source files allow you to seed the database with initial data. This is useful for lookup tables, configuration, or demo content.
1. Overview
File Naming Convention: <object_name>.data.yml
The filename (without the .data.yml extension) automatically identifies which object to seed data into. This is the recommended approach as it eliminates redundancy.
Examples:
status.data.yml→ Seeds data into object:statususers.data.yml→ Seeds data into object:usersproduct_categories.data.yml→ Seeds data into object:product_categories
Features:
- Implicit object mapping: Object name inferred from filename
- Auto-deduplication: Duplicate key errors are typically ignored (depending on driver implementation), allowing for basic idempotency
- Order matters: Files loaded alphabetically, so ensure parent data is seeded before child data
2. File Format
Recommended Format: Filename-based (Implicit)
File: status.data.yml
File: users.data.yml
Alternative Format: Explicit Object (Legacy)
For backwards compatibility, you can still explicitly specify the object:
Note: The filename-based approach is preferred as it reduces redundancy and makes file organization clearer.
3. Best Practices
-
Use Immutable IDs: Provide explicit IDs (
_id) to ensure consistent referencing across environments: -
Versioning: Include a metadata field if you need to track data versions:
-
Order Matters: ObjectQL loads data files in alphabetical order. If you have relationships, ensure parent data loads first:
-
Use Prefix Numbering: For complex dependencies, use numeric prefixes: