Skip to content

Commit

Permalink
Implementando migrations (Coderockr#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitornp committed Aug 11, 2014
1 parent 6c4d9c8 commit 38b8742
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 230 deletions.
15 changes: 1 addition & 14 deletions bin/orcamentos
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
#!/usr/bin/env php
<?php

use Symfony\Component\Console\Application as ConsoleApplication;
use Doctrine\ORM\Tools\Console\ConsoleRunner;

chdir(__DIR__ . '/..');

require_once('vendor/autoload.php');
$application = new ConsoleApplication();
$application->setHelperSet(include 'cli-config.php');
$application->add(new Orcamentos\Console\InitializeCommand);
$application->add(new Orcamentos\Console\ResetPasswordCommand);

ConsoleRunner::addCommands($application);

$application->run();
include "orcamentos.php";
98 changes: 98 additions & 0 deletions bin/orcamentos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Helper\QuestionHelper;

chdir(__DIR__ . '/..');

define('DS', DIRECTORY_SEPARATOR);

require 'vendor/autoload.php';

// Load configs
$configValues = require_once 'config/config.php';

// Mapping annotation
AnnotationRegistry::registerFile('vendor' . DS . 'doctrine' . DS . 'orm' . DS . 'lib' . DS . 'Doctrine' . DS . 'ORM' . DS . 'Mapping' . DS . 'Driver' . DS . 'DoctrineAnnotations.php');

// Doctrine AnnotationDriver
$driver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
new Doctrine\Common\Annotations\AnnotationReader(),
array('src' . DS . 'Orcamentos' . DS . 'Model')
);

// Doctrine cache
$cache = new \Doctrine\Common\Cache\ApcCache();

// Doctrine
$config = new Configuration();

// Proxies (3)
$config->setProxyDir(sys_get_temp_dir() . '/' . md5(__DIR__));
$config->setProxyNamespace('Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setMetadataDriverImpl($driver);
$config->setMetadataCacheImpl($cache);

// EntityManager
$em = EntityManager::create($configValues['db.options'], $config);

// Console
$console = new ConsoleApplication('Gerenciamento de Orçamentos', '1.0.0');
$console->setCatchExceptions(true);
$console->setHelperSet(new HelperSet([
new ConnectionHelper($em->getConnection()),
new EntityManagerHelper($em),
$console->getHelperSet()->get('dialog'),
$console->getHelperSet()->get('progress'),
$console->getHelperSet()->get('table'),
new FormatterHelper(),
new DebugFormatterHelper(),
new ProcessHelper(),
new QuestionHelper()
]));

$console->addCommands(array(
// DBAL Commands
new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),

// ORM Commands
new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(),
new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(),
new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(),
new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(),
new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(),
new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(),
new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(),
new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(),
new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(),
new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(),
new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(),
new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(),
new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(),
new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(),

// Migrations Commands
new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand(),

// Orcamentos Commands
new Orcamentos\Console\InitializeCommand(),
new Orcamentos\Console\ResetPasswordCommand()
));
$console->run();
29 changes: 0 additions & 29 deletions bootstrap.php

This file was deleted.

56 changes: 0 additions & 56 deletions cli-config.php

This file was deleted.

9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
},
"autoload": {
"psr-4": {
"Orcamentos\\": "src/Orcamentos"
}
},
"minimum-stability": "dev"
"Orcamentos\\": "src/Orcamentos",
"Orcamentos\\Migrations\\": "migrations"
}
},
"minimum-stability": "dev"
}
4 changes: 4 additions & 0 deletions migrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: Gerenciamento de Orçamentos - Migrations
migrations_namespace: Orcamentos\Migrations
table_name: doctrine_migration_versions
migrations_directory: migrations
77 changes: 77 additions & 0 deletions migrations/Version20140807204731.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Orcamentos\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

class Version20140807204731 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

$this->addSql("CREATE TABLE client (id INT AUTO_INCREMENT NOT NULL, company_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, cnpj VARCHAR(14) NOT NULL, corporateName VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, logotype VARCHAR(255) DEFAULT NULL, telephone VARCHAR(255) DEFAULT NULL, responsable VARCHAR(255) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_C7440455979B1AD6 (company_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE company (id INT AUTO_INCREMENT NOT NULL, plan_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, city VARCHAR(255) DEFAULT NULL, taxes DOUBLE PRECISION NOT NULL, email VARCHAR(255) NOT NULL, telephone VARCHAR(255) NOT NULL, site VARCHAR(255) DEFAULT NULL, logotype VARCHAR(255) DEFAULT NULL, responsable VARCHAR(255) DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_4FBF094FE899029B (plan_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE type (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, type VARCHAR(255) NOT NULL, contractType VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE plan (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, price DOUBLE PRECISION DEFAULT NULL, quoteLimit INT DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE privatenote (id INT AUTO_INCREMENT NOT NULL, project_id INT DEFAULT NULL, user_id INT DEFAULT NULL, note LONGTEXT DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_FFBFCCE1166D1F9C (project_id), INDEX IDX_FFBFCCE1A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE project (id INT AUTO_INCREMENT NOT NULL, client_id INT DEFAULT NULL, company_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, tags VARCHAR(255) DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_2FB3D0EE19EB6921 (client_id), INDEX IDX_2FB3D0EE979B1AD6 (company_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE quote (id INT AUTO_INCREMENT NOT NULL, project_id INT DEFAULT NULL, dueDate DATETIME DEFAULT NULL, taxes DOUBLE PRECISION NOT NULL, version VARCHAR(150) NOT NULL, status INT NOT NULL, profit DOUBLE PRECISION NOT NULL, commission DOUBLE PRECISION NOT NULL, privateNotes LONGTEXT DEFAULT NULL, deadline LONGTEXT DEFAULT NULL, priceDescription LONGTEXT DEFAULT NULL, paymentType LONGTEXT DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_6B71CBF4166D1F9C (project_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE resource (id INT AUTO_INCREMENT NOT NULL, company_id INT DEFAULT NULL, type_id INT DEFAULT NULL, name VARCHAR(150) NOT NULL, cost DOUBLE PRECISION NOT NULL, equipmentLife INT DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_BC91F416979B1AD6 (company_id), INDEX IDX_BC91F416C54C8C93 (type_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE resourcequote (id INT AUTO_INCREMENT NOT NULL, resource_id INT DEFAULT NULL, quote_id INT DEFAULT NULL, amount DOUBLE PRECISION NOT NULL, value DOUBLE PRECISION NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_39741B5589329D25 (resource_id), INDEX IDX_39741B55DB805178 (quote_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE share (id INT AUTO_INCREMENT NOT NULL, quote_id INT DEFAULT NULL, email VARCHAR(150) NOT NULL, hash VARCHAR(255) NOT NULL, shortUrl VARCHAR(255) NOT NULL, sent TINYINT(1) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_EF069D5ADB805178 (quote_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE sharenote (id INT AUTO_INCREMENT NOT NULL, share_id INT DEFAULT NULL, note LONGTEXT DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_F829661E2AE63FDB (share_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, company_id INT DEFAULT NULL, name VARCHAR(150) NOT NULL, email VARCHAR(150) NOT NULL, password VARCHAR(100) NOT NULL, admin TINYINT(1) DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), INDEX IDX_8D93D649979B1AD6 (company_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE view (id INT AUTO_INCREMENT NOT NULL, share_id INT DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_FEFDAB8E2AE63FDB (share_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("ALTER TABLE client ADD CONSTRAINT FK_C7440455979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id)");
$this->addSql("ALTER TABLE company ADD CONSTRAINT FK_4FBF094FE899029B FOREIGN KEY (plan_id) REFERENCES plan (id)");
$this->addSql("ALTER TABLE privatenote ADD CONSTRAINT FK_FFBFCCE1166D1F9C FOREIGN KEY (project_id) REFERENCES project (id)");
$this->addSql("ALTER TABLE privatenote ADD CONSTRAINT FK_FFBFCCE1A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)");
$this->addSql("ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)");
$this->addSql("ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id)");
$this->addSql("ALTER TABLE quote ADD CONSTRAINT FK_6B71CBF4166D1F9C FOREIGN KEY (project_id) REFERENCES project (id)");
$this->addSql("ALTER TABLE resource ADD CONSTRAINT FK_BC91F416979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id)");
$this->addSql("ALTER TABLE resource ADD CONSTRAINT FK_BC91F416C54C8C93 FOREIGN KEY (type_id) REFERENCES type (id)");
$this->addSql("ALTER TABLE resourcequote ADD CONSTRAINT FK_39741B5589329D25 FOREIGN KEY (resource_id) REFERENCES resource (id)");
$this->addSql("ALTER TABLE resourcequote ADD CONSTRAINT FK_39741B55DB805178 FOREIGN KEY (quote_id) REFERENCES quote (id)");
$this->addSql("ALTER TABLE share ADD CONSTRAINT FK_EF069D5ADB805178 FOREIGN KEY (quote_id) REFERENCES quote (id)");
$this->addSql("ALTER TABLE sharenote ADD CONSTRAINT FK_F829661E2AE63FDB FOREIGN KEY (share_id) REFERENCES share (id)");
$this->addSql("ALTER TABLE user ADD CONSTRAINT FK_8D93D649979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id)");
$this->addSql("ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8E2AE63FDB FOREIGN KEY (share_id) REFERENCES share (id)");
}

public function down(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

$this->addSql("ALTER TABLE project DROP FOREIGN KEY FK_2FB3D0EE19EB6921");
$this->addSql("ALTER TABLE client DROP FOREIGN KEY FK_C7440455979B1AD6");
$this->addSql("ALTER TABLE project DROP FOREIGN KEY FK_2FB3D0EE979B1AD6");
$this->addSql("ALTER TABLE resource DROP FOREIGN KEY FK_BC91F416979B1AD6");
$this->addSql("ALTER TABLE user DROP FOREIGN KEY FK_8D93D649979B1AD6");
$this->addSql("ALTER TABLE resource DROP FOREIGN KEY FK_BC91F416C54C8C93");
$this->addSql("ALTER TABLE company DROP FOREIGN KEY FK_4FBF094FE899029B");
$this->addSql("ALTER TABLE privatenote DROP FOREIGN KEY FK_FFBFCCE1166D1F9C");
$this->addSql("ALTER TABLE quote DROP FOREIGN KEY FK_6B71CBF4166D1F9C");
$this->addSql("ALTER TABLE resourcequote DROP FOREIGN KEY FK_39741B55DB805178");
$this->addSql("ALTER TABLE share DROP FOREIGN KEY FK_EF069D5ADB805178");
$this->addSql("ALTER TABLE resourcequote DROP FOREIGN KEY FK_39741B5589329D25");
$this->addSql("ALTER TABLE sharenote DROP FOREIGN KEY FK_F829661E2AE63FDB");
$this->addSql("ALTER TABLE view DROP FOREIGN KEY FK_FEFDAB8E2AE63FDB");
$this->addSql("ALTER TABLE privatenote DROP FOREIGN KEY FK_FFBFCCE1A76ED395");
$this->addSql("DROP TABLE client");
$this->addSql("DROP TABLE company");
$this->addSql("DROP TABLE type");
$this->addSql("DROP TABLE plan");
$this->addSql("DROP TABLE privatenote");
$this->addSql("DROP TABLE project");
$this->addSql("DROP TABLE quote");
$this->addSql("DROP TABLE resource");
$this->addSql("DROP TABLE resourcequote");
$this->addSql("DROP TABLE share");
$this->addSql("DROP TABLE sharenote");
$this->addSql("DROP TABLE user");
$this->addSql("DROP TABLE view");
}
}
25 changes: 14 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="phpunit_bootstrap.php"
>

syntaxCheck="false">

<php>
<ini name="date.timezone" value="America/Sao_Paulo"/>
</php>

<!-- Indicando qual é o diretório onde as classes de teste se encontram -->
<testsuites>
<testsuite name="Orçamentos Coderockr">
<directory suffix=".php">src/</directory>
<testsuite name="Orçamentos Coderockr Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<!-- Adicionando filtros, basicamente whitelist (diretórios que serão executados),
dentro temos o exclude (diretórios que não serão executados pelos testes) -->

<!-- Adicionando filtros, basicamente whitelist (diretórios que serão executados),
dentro temos o exclude (diretórios que não serão executados pelos testes) -->
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
Expand All @@ -29,7 +31,8 @@
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="tests/_reports/coverage" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70" />
<log type="coverage-html" target="tests/_reports/coverage" charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="testdox-text" target="tests/_reports/testdox/executed.txt"/>
</logging>
</phpunit>
</phpunit>
6 changes: 0 additions & 6 deletions phpunit_bootstrap.php

This file was deleted.

Loading

0 comments on commit 38b8742

Please sign in to comment.