Symfony2 Doctrine database into production - symfony

Sorry if the question is one of a newb.
When I deliver my symfony2 website to my production webserver. I'm using a low cost hosting service. I cannot access mysql remotely ( only execute statement from their website through phpmyadmin ).
Case 1: Assuming I could access remotely, i should run:
php app/console doctrine:schema:create --env=prod
with appropriate database settings so it would update my db.
Case 2: Assuming I can't access remotely, then i have two option:
I could create an ugly script that would call the above line from the website and remove it after delivery.
I could get the sql statement printed to a file and execute it. Which seems better to me.
Question:
Is there a pb with the above ?
Is there a way to get an sql script in a file from:
php app/console doctrine:schema:create --env=prod

You can dump the sql statement using the --dump-sql option, and store it in a file:
php app/console doctrine:schema:create --dump-sql > statement.sql

Related

Symfony doesn't find pdo_sqlsrv driver

I have one problem with Doctrine (or with my server configuration, I don't know where is the problem) in my Symfony2 web. I have been looking for an answer since several days but I haven't found it yet.
I need to connect my symfony web to a remote Microsoft SQL database through Doctrine. For this reason, I have added the "database_driver: pdo_sqlsrv" param in app/config/parameters.yml, but when I try to execute (in my Mac) a command like:
php bin/console doctrine:database:create
or
php bin/console doctrine:generate:entities AppBundle/Entity/Product
I get the following error:
[Doctrine\DBAL\Driver\PDOException] could not find driver
[PDOException] could not find driver
I have checked the phpinfo and the driver doesn't appear (only mysql, sqlite). I don't know if it's possible to add MSSQL, because in Microsoft SQL Server Functions (PDO_SQLSRV) appears that it needs to be running on a Windows.
Is not possible to access a mssql database without Windows? (If yes, how can I do it).
Would I need a Windows hosting?
Thanks in advance.
I'm using sql server on my last project.
here is what i've done to make it work on my dev environment
install pdo-dblib
composer require leaseweb/doctrine-pdo-dblib
configure doctrine to use the driver_class from the lib above instead of refering the sql_serv driver
driver_class: Lsw\DoctrinePdoDblib\Doctrine\DBAL\Driver\PDODblib\Driver

Clearing doctrine's mapping cache

I mistakenly used a mysql reserved keyword 'condition' when defining my model(yml). I then renamed the field to 'description' and generated entities but cannot run the command php app/console doctrine:schema:update because the generated query ALTER TABLE segment_filters CHANGE condition description VARCHAR(300) NOT NULL contains the keyword.
I have tried the following:
renaming field directly on the database(desparation)
clearing cache php app/console cache:clear
clearing various doctrine caches doctrine:cache:clear-* -flush (with and without flush)
I have tried googling and reading but maybe it's one of those days that the head just needs a break. Any help will be heavily appreciated
I have faced a similar issue before. This is related to mysql syntax. Symfony2 reverse engineering will help you resolve this issue
Change the col name directly on the database table.
run php app/console doctrine:mapping:import --force Bundlename format(yml/xml/php).
This will map your doctrine yml's for that bundle with the database
run doctrine:generate:entities on that bundle.
Mission accomplished.

Should I clear/warm cache after doctrine migrations?

I would like to know about how symfony2 console commands cache:clear and cache:warmup works in regards to changes in doctrine entities.
I've read this http://blog.whiteoctober.co.uk/2014/02/25/symfony2-cache-warmup-explained/ and this https://stackoverflow.com/a/17787070/779320. There it is stated that symfony2 warm-up generates Doctrine proxies.
Thing is, I frequently have a situation after application deploy using capifony where I must run doctrine migrations. After that I always run cache:clear and cache:warmup.
According to the links above (if I understand correctly), if there is any entity addition/deletion, I should run cache:warmup. But what if there is only entity's fields changes. Should I run both cache:clear and cache:warmup commands necessary to be run or just one? Or, which one is necessary? Or, not at all?
Migrations are responsible for persistence layer only. It has nothing to do with EntityProxies, it only makes Database in sync with Model - that's all.
In production, during deployment, you probably run git pull and composer install, which clears the cache, so migrations shoud run just after that.
Reason - after composer install your new code and Model itself is ready to use new fields/entities, but the Database still falls behind, so migrations keeps it in sync.

unable to connect with database

I have downloded some code of symfony from github. I have configured all the things.
I have created the database using command
php app/console doctrine:database:create
I have created the database also but when I am trying to log in or register then I am not registering when I am looking at profiler then it shows that no query has been executed. what should I do ?
Check your parameters_dev.ini file inside config and confirm whether the setting s are correct or not ? have you already created the database? can you upload some more code for details?
Check your port and try type 127.0.0.1 instead of localhost in parameters file, it's strange but it works for me.
Did you create the schema after you created the database?
php app/console doctrine:schema:create
What do the logs (app/logs/dev.log or app/logs/prod.log) say?

Symfony 2 Project Receiving [PDOException] General Error: 2050

[PDOException]
SQLSTATE[HY000]: General error: 2050
example:dbextra:install [--drop]
Database is setup properly, pdo is up and running, pdo_mysql is up and running, redis is up and running, elasticsearch is up and running...
If I look in my parameters.ini or I load the page and look under db in Symfony2 it tells me that everything is running fine. But I can't get dbextra:install to work and my app simply will not write to the database even though all the logs are saying that it IS writing to the database.
My app has a user name and password login and the ability to create new users. It correctly loads the forms and allows you to create a new user... but never actually writes that info to the database (even though it's saying it IS writing it to the database.)
Checked all the settings and all the servers are functioning normally (otherwise the app wouldn't run at all.)
The only error message I can get is that one.
Any ideas?
Someone using Ubuntu with Symfony2 will ABSOLUTELY run into this problem. So I thought I´d take a moment to explain the solution.
Symfony2 requires PDO... and it requires MySQL... but you can get pretty damned far without actually having pdo_mysql. If you just have PDO and MySQL installed... your application will probably run... but it will never write to the database.
And if you do a search for PDO_MySQL Ubuntu... you'll find a lot of outdated links to old versions of pdo_mysql that won't function properly with MySQL 5.5.
The solution is to run:
apt-get install php5-mysql
And then just restart apache and that will get rid of the error.

Resources