Search code examples
phpsymfonydoctrine-ormdoctrine-migrations

Generate one single migration from all migration files symfony doctrine?


My website is hosted on shared server so I cant run migration command since I dont have access to ssh. Is there any way I can generate one single migration/sql file from all migration files generated during development, so that I can easily import/execute manually?

I am using Symfony 2 framework with Doctrine2


Solution

  • Output SQL and execute manually

    You could output the SQL of the migrations to run on your local machine and then execute it from a web-console (e.g. phpMyAdmin).

    php app/console doctrine:migrations:migrate --write-sql -e prod
    

    Where the "prod" environment point towards a database where its structure is in sync with the one on your server.
    Once you successfully ran the compiled SQL on your server, just re-run the same command to update your "local" version of the database (without the --write-sql option)

    php app/console doctrine:migrations:migrate  -e prod
    

    This will update your remote database without the need for SSH, with a direct connection to the (My)SQL server.

    Upon next database change; repeat...

    Just point towards your production database

    If possible, just point towards your production/remote database for your "prod" environment.

    database_host: <your-website-domain>
    database_port: 3306 #default
    database_name: <your-database-name>
    database_user: <your-database-user>
    database_password: <your-database-password>
    

    But most shared-hosting companies will not allow you to connect directly to the database from an external connection, then your stuck with the proposition mentioned above.