Merge pull request #3487 from wallabag/initial-migration

Change the way to check for initial migration
This commit is contained in:
Nicolas Lœuillet 2017-12-12 20:20:31 +01:00 committed by GitHub
commit 1f198256ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,21 +4,30 @@ namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Initial database structure. * 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 * @param Schema $schema
*/ */
public function up(Schema $schema) public function up(Schema $schema)
{ {
if ($this->version->getConfiguration()->getNumberOfExecutedMigrations() > 0) { $this->skipIf($schema->hasTable($this->getTable('entry')), 'Database already initialized');
$this->version->markMigrated();
$this->skipIf(true, 'Database already initialized');
}
switch ($this->connection->getDatabasePlatform()->getName()) { switch ($this->connection->getDatabasePlatform()->getName()) {
case 'sqlite': case 'sqlite':
@ -188,4 +197,9 @@ SQL
$this->addSql('DROP TABLE "wallabag_user"'); $this->addSql('DROP TABLE "wallabag_user"');
$this->addSql('DROP TABLE wallabag_annotation'); $this->addSql('DROP TABLE wallabag_annotation');
} }
private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix') . $tableName;
}
} }