Skip to content

Loading in New Tables

Andrew edited this page Mar 23, 2024 · 1 revision

Since this game is in constant development, there are times we have to do things that you're not really supposed to be able to do in Symfony2. I (Andrew) suspect they expect you to export and import SQL data or have some sort of tool to copy everything over, rather than doing SQL structure changes to the live database while it contains data.

So, this guide is going to include all the steps you need to take to load in new tables, to include new DataFixures, into an existing Symfony Doctrine Database. For this example, we're going to be working with the following:

  • src/DataFixture/LoadPositionData.php
  • config/doctrine/RealmPosition.orm.xml
  • config/doctrine/PositionType.orm.xml

The goal here, in our example, is to extend the existing RealmPosition table to include a settable Type, which we'll load in as a DataFixture for initial population. We're doing a few other changes to that table, but the big one we care about for this example is the Type field, as it's mapped to the new PositionType table that we haven't added to the database yet.

So, what's the order of operations required?

  1. Ensure all your files are setup correctly and in the appropriate locations. You'll need to ensure you have entity files created that match the doctrine xml files. These entity files should include the get/set for each property, along with properties for each doctrine field.

  2. Run command: "php bin/console doctrine:schema:update --complete --dump-sql"

This will confirm the correct tables and edits are being made. If they are, continue, if not fix and try again.

  1. Run command: "php bin/console doctrine:schema:update --complete --force"

This will apply the previously listed SQL updates.

  1. Run command: "php bin/console doctrine:fixtures:load --group=LoadPositionData --append"

This will load a specific DataFixture to the database. --append is important because otherwise you'll probably drop your entire database before loading. :)

And there you go. With that your new tables should be loaded in and fully operational. Just don't forget to edit everything else! Like your controllers or views or translation strings.

Clone this wiki locally