Beispiel #1
0
 public function testCreateWithBody()
 {
     $migrationBody = array('up' => array('DROP TABLE IF EXISTS `album`', 'CREATE TABLE `album` (
               `id` int(11) NOT NULL AUTO_INCREMENT,
               `artist` varchar(100) NOT NULL,
               `title` varchar(100) NOT NULL,
               PRIMARY KEY (`id`)
             ) ENGINE=MyISAM  DEFAULT CHARSET=utf8'), 'down' => array('DROP TABLE IF EXISTS album'));
     $migrationPath = self::$manager->create(null, $migrationBody);
     if (is_file($migrationPath)) {
         $migrationFile = file_get_contents($migrationPath);
         $this->assertContains('CREATE TABLE `album`', $migrationFile);
         $this->assertContains('$this->query("DROP TABLE IF EXISTS `album`");', $migrationFile);
         unlink($migrationPath);
     }
 }
Beispiel #2
0
 public function generateAction()
 {
     $module = $this->request->getParam('module');
     if ($module) {
         $this->console->writeLine('Only for module "' . $module . '":');
     }
     $empty = $this->request->getParam('empty');
     $commit = $this->request->getParam('commit');
     $whitelist = $this->request->getParam('whitelist');
     $blacklist = $this->request->getParam('blacklist');
     try {
         if ($empty) {
             $migrationPath = $this->manager->create($module);
             if ($migrationPath) {
                 $this->console->writeLine('Migration created: ' . $migrationPath, Color::GREEN);
             }
         } else {
             $migrationPath = $this->manager->generateMigration($module, $blacklist, $whitelist);
             if ($migrationPath) {
                 $this->console->writeLine('Migration generated: ' . $migrationPath, Color::GREEN);
             }
             if (!empty($migrationPath)) {
                 if ($commit) {
                     preg_match("/\\d\\d\\d\\d\\d\\d\\d\\d_\\d\\d\\d\\d\\d\\d_\\d\\d/i", $migrationPath, $matches);
                     $migration = current($matches);
                     $this->manager->commit($module, $migration);
                     $this->console->writeLine('Committed migration: ' . $migration, Color::GREEN);
                 }
             } else {
                 $this->console->writeLine('Your database has no changes from last revision!');
             }
         }
     } catch (ZFCToolException $e) {
         $this->console->writeLine($e->getMessage(), Color::RED);
     } catch (\Exception $e) {
         $this->console->writeLine($e->getMessage(), Color::RED);
     }
 }