Seeding data - green-ecolution/backend GitHub Wiki
Seeding data refers to the filling of a database with initial or sample data. This data is used either to provide the necessary base values for the database or to provide test data for development purposes. Seeding helps to start the database in a defined state so that the application or system can be properly tested and developed.
This system use data seeder for the following reasons:
Regions in an area
The regions in the database need to be defined as the system needs to know exactly where each region is geographically located in the backend. In this way, the regions can be determined automatically when a tree cluster is created or updated, based on the centre point of all trees in that cluster. In this example, we use the different districts of Flensburg, Germany.
Link to seeder: 01_regions.sql
The geometry is MultiPolygon geometry in Well-Known Binary (WKB) format to describe geographic shape.
- The first few bytes (0106000020E6100000) indicate the type of geometry.
- 01060000 → This signifies a MultiPolygon geometry.
- 20E6100000 → This suggests that the data is in SRID 4326 (WGS 84 coordinate system).
Demo data
Some demo data is added for development, testing, and quality assurance purposes. These data help simulate real-world scenarios and ensure that the application behaves as expected in various situations. However, this data is not necessary in the production environment and can be safely removed once the testing phase is complete.
Link to seeder: 99_demo_data.sql
Data seeder for tests
The test folder in the seeded data directory contains data seeders specifically used by the backend unit tests. These seeders populate the test database with predefined data, ensuring that the unit tests run in a consistent and controlled environment.
All data seeders can be found in the /internal/storage/postgres/seed
directory.
Commands
# applies seed data after migrations are up to date
make seed/up
# rolls back and reapplies seed data
make seed/reset