I would like to use database migration tool in my current project. It's a php-project in zf3, therefore i decided for doctrine migrations. Here is pretty good example, how to use this tool.
The issue is, im adding tables from my code, which then are saved in a separate table. On init (first initial migration) I would like to remove all tables, that were added by program (from my code - the amount differs) and just create the table, in which the software saves created tables. I didn't find a simple solution, how to remove all tables except one from a database, therefore i thought, that i flush the whole database and then create the table, I need.
In order to not delete the migrations table, I created separated database, where only this one table exists. Now on up i would like to change the database, flush it, create the table, where all created tables will be saved, and change the database to migration, so that migration will be saved.
Here is the code, that will clarify, what I want to do:
public function preUp(Schema $schema) {
$this->addSql('use migration');
$this->addSql('drop database osm');
$this->addSql('create database osm');
$this->addSql('use osm');
}
public function up(Schema $schema){
$table = $schema->createTable('axx');
$table->addColumn('id', 'integer', ['autoincrement'=>true]);
$table->addColumn('title', 'text', ['notnull'=>true]);
$table->addColumn('date_created', 'datetime', ['notnull'=>true]);
$table->setPrimaryKey(['id']);
$table->addOption('engine' , 'InnoDB');
}
public function postUp(Schema $schema){
$this->addSql('use migration');
}
This code isn't working properly - the table post will be created in migration database. Why? Besides of that, I suppose there is in general a better solution for this problem, which i would like to hear.