A Python-based tool for dynamically generating relational databases with fake data, driven by a customizable JSON schema. Ideal for testing, prototyping, and simulating database interactions using an MVC architecture.
- Dynamic Table Creation: Define tables and relationships using a JSON schema.
- Fake Data Generation: Populate your database with realistic fake data using the Faker library.
- Relational Integrity: Enforces relationships between tables using foreign key constraints.
- MVC Architecture: Clean separation of concerns with Models, Views, and Controllers.
- Customizable: Easily modify the schema and data generation rules.
- Define your schema: Modify the
schema.jsonfile to match your desired database structure. - Run the script: Execute the main program to generate the database and display the tables.
python main.py- View the results: The generated tables and relationships will be displayed in the console or output format of your choice.
python main.pyThis command generates the database based on the schema.json and populates it with fake data.
fake-database-generator/
│
├── models.py # Handles data structure and generation
├── views.py # Handles data presentation
├── controllers.py # Manages the flow between models and views
├── main.py # Entry point for the application
├── schema.json # JSON schema defining tables and relationships
└── requirements.txt # Python dependencies
The schema.json file is the core configuration for this project. It defines the structure of your database, including tables, fields, and relationships.
[
{
"table_name": "Users",
"fields": [
{"name": "user_id", "type": "INTEGER", "primary_key": true},
{"name": "first_name", "type": "TEXT", "fake_data": "first_name"},
{"name": "last_name", "type": "TEXT", "fake_data": "last_name"},
{"name": "email", "type": "TEXT", "fake_data": "email"},
{"name": "account_id", "type": "INTEGER", "foreign_key": {"references": "Accounts(account_id)"}, "unique": true},
{"name": "order_id", "type": "INTEGER", "foreign_key": {"references": "Orders(order_id)"}},
]
},
...
]Suppose you want to create a database with Users, Orders, Products, and OrderDetails tables:
- Modify
schema.jsonwith the required structure and relationships. - Run
main.py.
The output will show the generated tables and their contents, with all relationships enforced.
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue to improve this project.
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin feature/your-feature-name). - Open a Pull Request.