Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2: How to avoid the sessions table being dropped by doctrine migrations?

I'm new to migrations, and I'm trying to stick to the automatically generated ones:

$ php app/console doctrine:migrations:diff
$ php app/console doctrine:migrations:migrate

The problem is that this drops my sessions table. What can I do to avoid that?

like image 802
HappyDeveloper Avatar asked Jul 08 '11 09:07

HappyDeveloper


2 Answers

Another option is simply to tell Doctrine to ignore the table. You can use the schema_filter option as described in this SO post.

So, if your table is called sessions, add the following to config.yml (Symfony < 4) or doctrine.yaml (Symfony >=4 ):

doctrine:
    dbal:
      # standard database config here
      schema_filter: ~^(?!sessions)~

We had a large number of tables to ignore, so we took the opposite approach - we told Doctrine to only consider tables which began with a certain prefix, and set up listeners to ensure all our Doctrine-managed tables had a prefix. The use of listeners for table prefixes is documented at http://docs.doctrine-project.org/en/latest/cookbook/sql-table-prefixes.html and there's a SO post about the Symfony side of it here.

like image 115
Sam Avatar answered Oct 18 '22 19:10

Sam


I know I am late to this question, but figured i would offer a suggestion.

import the session tables into your entities. even if you don't use it through the interfaces it creates, it will allow Doctrine to keep track of the tables, so that it knows they are ment to be there.

see: http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html

like image 22
WhyteWolf Avatar answered Oct 18 '22 19:10

WhyteWolf