New migration. Updates tables names, columns names and settings.

This commit is contained in:
Alexey Skobkin 2015-03-02 22:25:59 +03:00
parent 442e29adc6
commit 03baa5bb6c
3 changed files with 101 additions and 16 deletions

View file

@ -0,0 +1,85 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20150302213116 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
// Tables structure
$this->write('Upgrading column names and setting...');
$this->addSql(
'ALTER TABLE lang
CHANGE id id INT AUTO_INCREMENT NOT NULL,
CHANGE name name VARCHAR(100) NOT NULL,
CHANGE file code VARCHAR(24) NOT NULL,
CHANGE enabled enabled TINYINT(1) NOT NULL'
);
$this->addSql('CREATE INDEX idx_code ON lang (code)');
$this->addSql(
'ALTER TABLE paste
CHANGE id id INT AUTO_INCREMENT NOT NULL,
CHANGE code text LONGTEXT NOT NULL,
CHANGE code_comment description LONGTEXT DEFAULT NULL,
CHANGE lang language INT NOT NULL,
CHANGE filename file_name VARCHAR(128) DEFAULT NULL,
CHANGE name author VARCHAR(48) DEFAULT NULL,
CHANGE date_pub date_publish DATETIME NOT NULL,
CHANGE date_exp date_expire DATETIME DEFAULT NULL,
CHANGE ip ip VARCHAR(48) NOT NULL,
CHANGE secret secret VARCHAR(16) DEFAULT NULL'
);
// Renaming tables
$this->write('Renaming tables to the full name format...');
$this->addSql('RENAME TABLE lang TO languages');
$this->addSql('RENAME TABLE paste TO copypastes');
}
public function down(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
// Tables structure
$this->write('Downgrading column names and setting...');
$this->addSql('DROP INDEX idx_code ON languages');
$this->addSql(
'ALTER TABLE lang
CHANGE id id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT \'ID\',
CHANGE name name VARCHAR(100) NOT NULL,
CHANGE code file VARCHAR(24) NOT NULL,
CHANGE enabled enabled TINYINT(1) NOT NULL COMMENT \'Is language usable\''
);
$this->addSql(
'ALTER TABLE paste
CHANGE id id INT AUTO_INCREMENT NOT NULL,
CHANGE text code LONGTEXT NOT NULL COMMENT \'Code\',
CHANGE description code_comment LONGTEXT NOT NULL COMMENT \'Comments for code\',
CHANGE language lang INT UNSIGNED NOT NULL COMMENT \'Language ID\',
CHANGE file_name filename VARCHAR(128) NOT NULL COMMENT \'Filename\',
CHANGE id id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT \'ID\',
CHANGE author name VARCHAR(48) NOT NULL COMMENT \'Author of quote name\',
CHANGE date_publish date_pub DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT \'Publish date\',
CHANGE date_expire date_exp DATETIME DEFAULT \'0000-00-00 00:00:00\' NOT NULL COMMENT \'Expire date\',
CHANGE ip ip varchar(48) NOT NULL COMMENT \'IP\',
CHANGE secret secret VARCHAR(16) NOT NULL COMMENT \'Paste secret\''
);
// Renaming tables
$this->write('Renaming tables to the old short format...');
$this->addSql('RENAME TABLE languages TO lang');
$this->addSql('RENAME TABLE paste TO copypastes');
}
}

View file

@ -5,17 +5,17 @@ namespace Skobkin\Bundle\CopyPasteBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Paste * Copypaste
* *
* @ORM\Table( * @ORM\Table(
* name="paste", * name="copypastes",
* indexes={ * indexes={
* @ORM\Index(name="idx_expire", columns={"date_exp"}) * @ORM\Index(name="idx_expire", columns={"date_expire"})
* } * }
* ) * )
* @ORM\Entity * @ORM\Entity
*/ */
class Paste class Copypaste
{ {
/** /**
* @var integer * @var integer
@ -29,49 +29,49 @@ class Paste
/** /**
* @var string * @var string
* *
* @ORM\Column(name="code", type="text", nullable=false) * @ORM\Column(name="text", type="text", nullable=false)
*/ */
private $text; private $text;
/** /**
* @var string * @var string
* *
* @ORM\Column(name="code_comment", type="text", nullable=true) * @ORM\Column(name="description", type="text", nullable=true)
*/ */
private $description; private $description;
/** /**
* @var integer * @var integer
* *
* @ORM\Column(name="lang", type="integer", nullable=false) * @ORM\Column(name="language", type="integer", nullable=false)
*/ */
private $language; private $language;
/** /**
* @var string * @var string
* *
* @ORM\Column(name="filename", type="string", length=128, nullable=true) * @ORM\Column(name="file_name", type="string", length=128, nullable=true)
*/ */
private $fileName; private $fileName;
/** /**
* @var string * @var string
* *
* @ORM\Column(name="name", type="string", length=48, nullable=true) * @ORM\Column(name="author", type="string", length=48, nullable=true)
*/ */
private $author; private $author;
/** /**
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(name="date_pub", type="datetime", nullable=false) * @ORM\Column(name="date_publish", type="datetime", nullable=false)
*/ */
private $datePublished; private $datePublished;
/** /**
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(name="date_exp", type="datetime", nullable=true) * @ORM\Column(name="date_expire", type="datetime", nullable=true)
*/ */
private $dateExpire; private $dateExpire;

View file

@ -5,18 +5,18 @@ namespace Skobkin\Bundle\CopyPasteBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Lang * Language
* *
* @ORM\Table( * @ORM\Table(
* name="lang", * name="languages",
* indexes={ * indexes={
* @ORM\Index(name="idx_enabled", columns={"enabled"}), * @ORM\Index(name="idx_enabled", columns={"enabled"}),
* @ORM\Index(name="idx_file", columns={"file"}) * @ORM\Index(name="idx_code", columns={"code"})
* } * }
* ) * )
* @ORM\Entity * @ORM\Entity
*/ */
class Lang class Language
{ {
/** /**
* @var integer * @var integer
@ -37,7 +37,7 @@ class Lang
/** /**
* @var string * @var string
* *
* @ORM\Column(name="file", type="string", length=24, nullable=false) * @ORM\Column(name="code", type="string", length=24, nullable=false)
*/ */
private $code; private $code;