From 442e29adc60db8c12ba5dcd5673ba938e6d14b56 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 2 Mar 2015 21:10:10 +0300 Subject: [PATCH] First migration. Creates database in copypaste1 format. --- app/AppKernel.php | 1 + .../Version20150302205121.php | 60 +++++++++ app/config/config.yml | 6 + composer.json | 4 +- composer.lock | 123 +++++++++++++++++- 5 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 app/DoctrineMigrations/Version20150302205121.php diff --git a/app/AppKernel.php b/app/AppKernel.php index faee254..a75d4a0 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -15,6 +15,7 @@ class AppKernel extends Kernel new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new Skobkin\Bundle\CopyPasteBundle\SkobkinCopyPasteBundle(), ); diff --git a/app/DoctrineMigrations/Version20150302205121.php b/app/DoctrineMigrations/Version20150302205121.php new file mode 100644 index 0000000..7f4d312 --- /dev/null +++ b/app/DoctrineMigrations/Version20150302205121.php @@ -0,0 +1,60 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $schemaManager = $this->connection->getSchemaManager(); + + if ($schemaManager->tablesExist(['lang', 'paste'])) { + $this->write('Copypaste1 tables detected. Skiping creation...'); + } else { + $this->write('Creating database in old format...'); + + $this->addSql( + 'CREATE TABLE `lang` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT \'ID\', + `name` varchar(100) CHARACTER SET utf8 NOT NULL COMMENT \'Language title for GUI\', + `file` varchar(24) CHARACTER SET utf8 NOT NULL COMMENT \'Language filename for GeSHi\', + `enabled` tinyint(1) unsigned NOT NULL COMMENT \'Is language usable or not\', + PRIMARY KEY (`id`), + KEY `lang_enabled` (`enabled`) + ) ENGINE=MyISAM AUTO_INCREMENT=190 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=\'Programming languages\'' + ); + $this->addSql( + 'CREATE TABLE `paste` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT \'ID\', + `code` mediumtext CHARACTER SET utf8 NOT NULL COMMENT \'Code\', + `code_comment` text CHARACTER SET utf8 NOT NULL COMMENT \'Comments for code\', + `lang` int(11) unsigned NOT NULL COMMENT \'id языка ввода\', + `filename` varchar(128) CHARACTER SET utf8 NOT NULL COMMENT \'Filename\', + `name` varchar(48) CHARACTER SET utf8 NOT NULL COMMENT \'Author of quote name\', + `date_pub` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT \'Publish date\', + `date_exp` timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\' COMMENT \'Expire date\', + `ip` varchar(48) CHARACTER SET utf8 NOT NULL COMMENT \'IP\', + `secret` varchar(16) COLLATE utf8_unicode_ci NOT NULL COMMENT \'Paste secret\', + PRIMARY KEY (`id`), + KEY `expiration` (`date_exp`) + ) ENGINE=InnoDB AUTO_INCREMENT=1194 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' + ); + } + } + + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE lang'); + $this->addSql('DROP TABLE paste'); + } +} diff --git a/app/config/config.yml b/app/config/config.yml index bf4da51..b916725 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -64,6 +64,12 @@ doctrine: auto_generate_proxy_classes: "%kernel.debug%" auto_mapping: true +doctrine_migrations: + dir_name: %kernel.root_dir%/DoctrineMigrations + namespace: Application\Migrations + table_name: migration_versions + name: Application Migrations + # Swiftmailer Configuration swiftmailer: transport: "%mailer_transport%" diff --git a/composer.json b/composer.json index 5d5968b..e75cc92 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,9 @@ "symfony/monolog-bundle": "~2.4", "sensio/distribution-bundle": "~3.0,>=3.0.12", "sensio/framework-extra-bundle": "~3.0,>=3.0.2", - "incenteev/composer-parameter-handler": "~2.0" + "incenteev/composer-parameter-handler": "~2.0", + "doctrine/migrations": "1.0.*@dev", + "doctrine/doctrine-migrations-bundle": "2.1.*@dev" }, "require-dev": { "sensio/generator-bundle": "~2.3" diff --git a/composer.lock b/composer.lock index a6013e9..c0f9202 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "73f15ad91f600008506b4294b7b7d01c", + "hash": "5fc11fb887ef6aed953b90118745b7f8", "packages": [ { "name": "doctrine/annotations", @@ -514,6 +514,65 @@ ], "time": "2014-11-28 09:43:36" }, + { + "name": "doctrine/doctrine-migrations-bundle", + "version": "dev-master", + "target-dir": "Doctrine/Bundle/MigrationsBundle", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineMigrationsBundle.git", + "reference": "6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62", + "reference": "6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62", + "shasum": "" + }, + "require": { + "doctrine/doctrine-bundle": "~1.0", + "doctrine/migrations": "~1.0@dev", + "php": ">=5.3.2", + "symfony/framework-bundle": "~2.1" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Bundle\\MigrationsBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony DoctrineMigrationsBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "dbal", + "migrations", + "schema" + ], + "time": "2015-02-16 13:24:46" + }, { "name": "doctrine/inflector", "version": "v1.0.1", @@ -635,6 +694,64 @@ ], "time": "2014-09-09 13:34:57" }, + { + "name": "doctrine/migrations", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/migrations.git", + "reference": "058a4635ac9b80a5b1997df28a754e64b1425a1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/migrations/zipball/058a4635ac9b80a5b1997df28a754e64b1425a1d", + "reference": "058a4635ac9b80a5b1997df28a754e64b1425a1d", + "shasum": "" + }, + "require": { + "doctrine/dbal": "~2.0", + "php": ">=5.3.2" + }, + "require-dev": { + "symfony/console": "2.*", + "symfony/yaml": "2.*" + }, + "suggest": { + "symfony/console": "to run the migration from the console" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\DBAL\\Migrations": "lib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Database Schema migrations using Doctrine DBAL", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "migrations" + ], + "time": "2015-02-19 08:13:05" + }, { "name": "doctrine/orm", "version": "v2.4.7", @@ -1667,7 +1784,9 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "symfony/symfony": 20 + "symfony/symfony": 20, + "doctrine/migrations": 20, + "doctrine/doctrine-migrations-bundle": 20 }, "prefer-stable": false, "prefer-lowest": false,