Пример #1
0
 /**
  * @return voud
  * @param Nano_Db $db
  */
 public static function clean(Nano_Db $db)
 {
     $tables = $db->query('show tables', PDO::FETCH_NUM);
     foreach ($tables as $row) {
         if (Nano_Migrate::VERSION_TABLE === $row[0]) {
             continue;
         }
         $db->query('truncate table `' . $row[0] . '`');
     }
 }
Пример #2
0
 /**
  * @return void
  * @param Nano_Db $db
  */
 public function run(Nano_Db $db)
 {
     $this->load();
     foreach ($this->queries as $query) {
         $db->query($query);
     }
     $this->getScript()->run($db);
     unset($this->queries);
     unset($this->script);
 }
Пример #3
0
 public function testMigrateFromVersion()
 {
     $this->setVersion('04_0001');
     $this->setVersion('04_0002');
     Nano_Migrate_Version::getAll($this->db, true);
     $this->db->exec('create table migration_test(' . 'id integer primary key' . ', comment text' . ')');
     $migrate = $this->createMigrate('from-version');
     self::assertEquals(5, count($migrate->getSteps()));
     self::assertTrue($migrate->run());
     Nano_Migrate_Version::getAll($this->db, true);
     self::assertTrue(Nano_Migrate_Version::exists($this->db, '04_0003'));
     self::assertTrue(Nano_Migrate_Version::exists($this->db, '04_0004'));
     self::assertTrue(Nano_Migrate_Version::exists($this->db, '04_0005'));
     self::assertEquals(6, $this->db->getCell('select count(*) from migration_test'));
     $rows = $this->db->query('select * from migration_test order by id', PDO::FETCH_OBJ)->fetchAll();
     $expected = array('300' => '3rd migration', '301' => '3rd migration script', '400' => '4th migration', '401' => '4th migration script', '500' => '5th migration', '501' => '5th migration script');
     foreach ($rows as $row) {
         $this->assertArrayHasKey($row->id, $expected);
         $this->assertEquals($expected[$row->id], $row->comment);
     }
 }