mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 02:51:04 +00:00
Change the way to check for initial migration
This commit is contained in:
parent
f209798368
commit
43e1711eb6
1 changed files with 25 additions and 4 deletions
|
@ -4,20 +4,36 @@ namespace Application\Migrations;
|
|||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\SchemaException;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Initial database structure.
|
||||
*/
|
||||
class Version20160401000000 extends AbstractMigration
|
||||
class Version20160401000000 extends AbstractMigration implements ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
if ($this->version->getConfiguration()->getNumberOfExecutedMigrations() > 0) {
|
||||
$this->version->markMigrated();
|
||||
try {
|
||||
$schema->getTable($this->getTable('entry'));
|
||||
|
||||
$this->skipIf(true, 'Database already initialized');
|
||||
} catch (SchemaException $e) {
|
||||
// it's ok, the table does not exist we can proceed to the initial migration
|
||||
}
|
||||
|
||||
switch ($this->connection->getDatabasePlatform()->getName()) {
|
||||
|
@ -188,4 +204,9 @@ SQL
|
|||
$this->addSql('DROP TABLE "wallabag_user"');
|
||||
$this->addSql('DROP TABLE wallabag_annotation');
|
||||
}
|
||||
|
||||
private function getTable($tableName)
|
||||
{
|
||||
return $this->container->getParameter('database_table_prefix') . $tableName;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue