Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine Migrations in new DB setup

We're using Doctrine Migrations to keep the application DB in sync across versions. The app will be installed each time we get a new customer meaning a new DB for each installation.

Now, the new DB will have all DB changes in the migrations file in place but will try to execute the migration files as they are not registered in the migrations table.

What's the best way to handle this situation?

like image 262
Michi Avatar asked Oct 25 '13 05:10

Michi


2 Answers

Just after fresh install to fill current schema use this commands:

  1. Create new empty chema of current version

    ./bin/console doctrine:schema:create

  2. Fill out the migration records with the current version (without actually run the migrations - schema already has current version after first command)

    ./bin/console doctrine:migrations:version --add --all

This command adds records of the migrations and doctrine:migrations:status will show you that there is no migrations need for the current verions.

Thats all!

like image 105
Peter Petrovich Avatar answered Oct 21 '22 06:10

Peter Petrovich


As mentioned in my comment, I've successfully created a blank database schema just by using Doctrine migrations. I believe it's necessary to create the empty database first (php app/console doctrine:database:create) and then run the migrations task.

The only potential issue I can think of is that any base data that your app requires to function will either need to be in the migrations files or will need to be inserted separately.

As an aside, running the all the migrations in one go has picked up a couple of small errors that I'd missed when just executing one at a time.

like image 1
StuBez Avatar answered Oct 21 '22 08:10

StuBez