Database Design - Storing Your Games
🗄️ Database Design
Section titled “🗄️ Database Design”Now that we have our GameVault project running, let’s add the ability to store games! Think of this as creating a digital filing cabinet for all your gaming data.
What we’re building 🎯
Section titled “What we’re building 🎯”We want to store information about games like:
- Title - “The Legend of Zelda”, “Cyberpunk 2077”
- Platform - PC, PlayStation, Xbox, Nintendo Switch
- Status - Playing, Completed, Wishlist
- Rating - How much you liked it (1-10)
- Notes - Your personal thoughts
-
Create your first entity 📝
In Framefox, we use entities to represent data. Think of an entity as a template that describes what information we want to store.
Let’s create our Game entity using the interactive terminal:
Create entity framefox create entityFramefox will ask you some questions. Here’s what the real interaction looks like:
Interactive entity creation What is the name of the Entity ?(snake_case)Entity name: gameCreating the entity 'game'Entity 'game' and repository created successfully.Do you want to add a new property to the entity ?(press enter to quit the terminal)Property name: titleProperty type [?] (str): strMaximum length (256):Optional [?] (no):Property 'title' added to src/entity/game.pyDo you want to add a new property to the entity ?(press enter to quit the terminal)Property name: platformProperty type [?] (str): strMaximum length (256):Optional [?] (no):Property 'platform' added to src/entity/game.pyDo you want to add a new property to the entity ?(press enter to quit the terminal)Property name: statusProperty type [?] (str): strMaximum length (256):Optional [?] (no): yesProperty 'status' added to src/entity/game.pyDo you want to add a new property to the entity ?(press enter to quit the terminal)Property name: ratingProperty type [?] (str): intMaximum length (256):Optional [?] (no): yesProperty 'rating' added to src/entity/game.pyDo you want to add a new property to the entity ?(press enter to quit the terminal)Property name: notesProperty type [?] (str): strMaximum length (256):Optional [?] (no): yesProperty 'notes' added to src/entity/game.pyDo you want to add a new property to the entity ?(press enter to quit the terminal)Property name: [press enter to finish]That’s it! Framefox just created your first database entity! 🎉
-
Create the database tables 🛠️
Now we need to tell the database about our new Game entity. Framefox uses migrations for this:
Create migration framefox database create-migrationYou’ll see something like:
Migration output ✓ Migration created: migrations/versions/20240603_152345_create_game_table.pyNow apply the migration (create the actual table):
Apply migration framefox database upgradeYou should see:
Database upgrade output ✓ Running migration 20240603_152345_create_game_table✓ Database schema updated successfully🎉 Awesome! Your database now has a
games
table ready to store data!
What we accomplished 🏆
Section titled “What we accomplished 🏆”In just a few minutes, we:
- ✅ Created our first entity - The Game model with interactive properties
- ✅ Generated database tables - Using migrations automatically
- ✅ Set up the database foundation - Ready to store game data
- ✅ Learned the Framefox workflow - Entity → Migration → Database
Understanding what happened 🤔
Section titled “Understanding what happened 🤔”The Entity (Game Model)
Section titled “The Entity (Game Model)”This is like a blueprint that says “every game should have a title, platform, status, etc.” Framefox created the src/entity/game.py
file with all your properties.
The Repository
Section titled “The Repository”This is a helper that makes it easy to save, find, and manage games in the database. You got src/repository/game_repository.py
for free!
The Migration
Section titled “The Migration”This created the actual table in your database where games will be stored. Framefox handled this automatically.
Next steps 🚀
Section titled “Next steps 🚀”In the next chapter, we’ll:
- Add user accounts to GameVault
- Learn about authentication (login/signup)
- Make sure each user only sees their own games
But right now, you’ve got the database foundation for a real web app! That’s pretty amazing for someone just starting out. 🎉
Ready to add user accounts? Let’s move on to Authentication! 🔐✨