Skip to content

Database Design - Storing Your Games

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.

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
  1. 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 entity

    Framefox 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: game
    Creating 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: title
    Property type [?] (str): str
    Maximum length (256):
    Optional [?] (no):
    Property 'title' added to src/entity/game.py
    Do you want to add a new property to the entity ?(press enter to quit the terminal)
    Property name: platform
    Property type [?] (str): str
    Maximum length (256):
    Optional [?] (no):
    Property 'platform' added to src/entity/game.py
    Do you want to add a new property to the entity ?(press enter to quit the terminal)
    Property name: status
    Property type [?] (str): str
    Maximum length (256):
    Optional [?] (no): yes
    Property 'status' added to src/entity/game.py
    Do you want to add a new property to the entity ?(press enter to quit the terminal)
    Property name: rating
    Property type [?] (str): int
    Maximum length (256):
    Optional [?] (no): yes
    Property 'rating' added to src/entity/game.py
    Do you want to add a new property to the entity ?(press enter to quit the terminal)
    Property name: notes
    Property type [?] (str): str
    Maximum length (256):
    Optional [?] (no): yes
    Property 'notes' added to src/entity/game.py
    Do 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! 🎉

  2. 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-migration

    You’ll see something like:

    Migration output
    Migration created: migrations/versions/20240603_152345_create_game_table.py

    Now apply the migration (create the actual table):

    Apply migration
    framefox database upgrade

    You 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!

In just a few minutes, we:

  1. Created our first entity - The Game model with interactive properties
  2. Generated database tables - Using migrations automatically
  3. Set up the database foundation - Ready to store game data
  4. Learned the Framefox workflow - Entity → Migration → Database

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.

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!

This created the actual table in your database where games will be stored. Framefox handled this automatically.

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! 🔐✨