Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to rebuild database structure ?
  • Hi, I developped a small application on a development environment (using scaffolding and migrations).
    Now, I would like to reinstall it on a testing env. I didn't find any doc on how to do that ? Shoud I dump the entire database, or Fuel could rebuild it by using migrations scripts (by the way, I did not success by using the second solution) ? Any help would be appreciated, Best Regards,
  • Depends on your definition of "rebuild". If you are refering to the database schema, and you have used migrations to create your database, then all you have to do is:
    - inform the app the environment is Fuel::stage (test is used for unit testing!)
    - configure your database in app/config/stage/db.php
    - run "php oil refine migrate" in your app root to run all your migrations At the end, you will have the same database schema as in development. This by the way is one of the main reasons for using migrations, even for code that isn't generated.
  • Maybe there is a miserunderstood on the word "environment". In my case, it is referring to one server. When I said I want to deploy in a testing environment, it means I copy all the source code on an other server, which will uses it's own database. So now, I tried to follow your points, but I think I'm facing some errors. After completed my fuel/app/config/stage/db.php file, I used the following command line: # FUEL_ENV="stage" php ./oil refine migrate
    Already on the latest migration for app:default I presume it did not work (because of application name which is not default, for exemple ?).
  • Yes, I understand. But you shouldn't run a FuelPHP application on a staging or production server in development mode (which is the default). You probably get this error because you've copied everything over, including the migrations.php config file. This is why environments are important. Locally, you use app/config/development, which contains everything that is specific to that environment. Notably your db and migrations config. When you move to your staging server, switch the application to the "stage" environment, so it will use a different db and migrations config. Same for the move to production. Also check if your migrations.php config file is not in app/config. Because then it's global for all Fuel environments, and you will run into the migration issue again.
  • Thank your for you answer, and I understand what you said. So, as you said, I first copied all files including the migrations.php into the config/development directory. Then, I copied thoses files into the config/stage directory (that I created) and modified my config/stage/db.php file to switch to the new empty database. Then, i use the FUEL_ENV variable onto the command line to ue se refine migrate function: # FUEL_ENV="stage" php oil refine migrate And I got the error I mentioned in my previous posts. And this is here where I'm lost :-) Why "this error" occurs ? (because I think I done all the necessary, isn't it ?) I made the same test using the development environment on an other empty database. And the only table I had after the refine migrate is the migration table (which is empty by the way). Really, I'm lost somewhere!
  • Migrations are controller by the migrations.php config file. So NEVER copy this file elsewhere and do NOT include it in your repository if you use version control. The migrations.php file reflects the migrations executed in a specific installation, and in a specific environment of that installation. The only files in your config/environment folders are files that are differerent per environment. Currently that's usually only migrations and db. You DO copy the migrations file over if you want to sync the database of that environment to exactly the level of migrations specified in the migrations.php config file. In which case you use
    php oil refine migrate:current

    This will replay all migrations that are present in the migrations.php config file but not in the migrations table.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion