Skip to content

Commit

Permalink
Effiana fix migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandOrientedTmp committed Jan 11, 2019
1 parent 083d83e commit bff4b65
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cron/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Effiana\CronBundle\Entity\CronJob;
use Effiana\CronBundle\Entity\CronJobRepository;
use Effiana\CronBundle\Entity\Repository\CronJobRepository;
use Effiana\CronBundle\Entity\CronReport;
use Symfony\Bridge\Doctrine\RegistryInterface;

Expand Down
4 changes: 2 additions & 2 deletions Entity/CronJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
/**
* CronJob
*
* @ORM\Table(name="cron_job", uniqueConstraints={@ORM\UniqueConstraint(name="un_name", columns={"name"})})
* @ORM\Entity(repositoryClass="Effiana\CronBundle\Entity\CronJobRepository")
* @ORM\Table(name="effiana_cron_job", uniqueConstraints={@ORM\UniqueConstraint(name="un_name", columns={"name"})})
* @ORM\Entity(repositoryClass="Effiana\CronBundle\Entity\Repository\CronJobRepository")
*/
class CronJob
{
Expand Down
4 changes: 2 additions & 2 deletions Entity/CronReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/**
* CronReport
*
* @ORM\Table(name="cron_report")
* @ORM\Entity(repositoryClass="Effiana\CronBundle\Entity\CronReportRepository")
* @ORM\Table(name="effiana_cron_report")
* @ORM\Entity(repositoryClass="Effiana\CronBundle\Entity\Repository\CronReportRepository")
*/
class CronReport
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Effiana\CronBundle\Entity;
namespace Effiana\CronBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Effiana\CronBundle\Entity;
namespace Effiana\CronBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

Expand Down
14 changes: 7 additions & 7 deletions Migrations/Schema/EffianaCronBundleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class EffianaCronBundleInstaller implements Installation
*/
public function getMigrationVersion()
{
return 'v2_0_3';
return 'v2_0_4';
}

/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
if(!$schema->hasTable('cron_job')) {
if(!$schema->hasTable('effiana_cron_job')) {

$table = $schema->createTable('cron_job');
$table = $schema->createTable('effiana_cron_job');
$table->addColumn('id', 'integer', ['notnull' => true, 'autoincrement' => true]);
$table->addColumn('name', 'string', ['default' => null, 'notnull' => true, 'length' => 191]);
$table->addColumn('command', 'string', ['default' => null, 'notnull' => true, 'length' => 1024]);
Expand All @@ -45,11 +45,11 @@ public function up(Schema $schema, QueryBag $queries)

$table->setPrimaryKey(['id']);

$queries->addPostQuery('INSERT INTO cron_job SELECT nextval(\'cron_job_id_seq\') AS id, name, command, cron_expression, name AS description, TRUE as enabled FROM scheduled_command;');
$queries->addPostQuery('INSERT INTO cron_job SELECT nextval(\'effiana_cron_job_id_seq\') AS id, name, command, cron_expression, name AS description, TRUE as enabled FROM scheduled_command;');
}
if(!$schema->hasTable('cron_report')) {
if(!$schema->hasTable('effiana_cron_report')) {

$table = $schema->createTable('cron_report');
$table = $schema->createTable('effiana_cron_report');
$table->addColumn('id', 'integer', ['notnull' => true, 'autoincrement' => true]);
$table->addColumn('run_at', 'datetime', ['notnull' => true]);
$table->addColumn('run_time', 'float', ['notnull' => true]);
Expand All @@ -58,7 +58,7 @@ public function up(Schema $schema, QueryBag $queries)
$table->addColumn('job_id', 'integer', ['notnull' => true]);
$table->setPrimaryKey(['id']);

$table->addForeignKeyConstraint('cron_job', ['job_id'], ['id']);
$table->addForeignKeyConstraint('effiana_cron_job', ['job_id'], ['id']);
}

}
Expand Down
71 changes: 71 additions & 0 deletions Migrations/Schema/v2_0_4/EffianaCronBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* This file is part of the BrandOriented package.
*
* (c) Brand Oriented sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Dominik Labudzinski <[email protected]>
*/

namespace Effiana\CronBundle\Migrations\Schema\v2_0_4;

use BrandOriented\DatabaseBundle\Migration\Column;
use BrandOriented\DatabaseBundle\Migration\Migration;
use BrandOriented\DatabaseBundle\Migration\QueryBag;
use BrandOriented\DatabaseBundle\Migration\Extension\RenameExtension;
use BrandOriented\DatabaseBundle\Migration\Extension\RenameExtensionAwareInterface;
use BrandOriented\DatabaseBundle\Migration\OrderedMigrationInterface;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Schema;

class EffianaCronBundle implements Migration, RenameExtensionAwareInterface, OrderedMigrationInterface
{
/**
* @var RenameExtension
*/
protected $renameExtension;

/**
* @inheritdoc
*/
public function getOrder()
{
return 1;
}

/**
* @inheritdoc
*/
public function setRenameExtension(RenameExtension $renameExtension)
{
$this->renameExtension = $renameExtension;
}

/**
* @inheritdoc
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function up(Schema $schema, QueryBag $queries)
{
if($schema->hasTable('cron_job')) {
$this->renameExtension->renameTable(
$schema,
$queries,
'cron_job',
'effiana_cron_job'
);
}
if($schema->hasTable('cron_report')) {
$this->renameExtension->renameTable(
$schema,
$queries,
'cron_report',
'effiana_cron_report'
);
}
}

}

0 comments on commit bff4b65

Please sign in to comment.