Exemple #1
0
 /**
  * To Perform migration to ensure the table and its properties
  * are up-to-date
  *
  */
 public static function migration()
 {
     $tables = Migration::tables();
     // Simple Filters.
     if (!isset($tables)) {
         return false;
     }
     foreach ($tables as $key => $value) {
         if (empty($value) || is_null($value) || !isset($value)) {
             continue;
         }
         loop:
         if (Capsule::Schema()->hasTable($key)) {
             foreach ($value as $column => $datatype) {
                 if (!Capsule::Schema()->hasColumn($key, $column)) {
                     //Assign the Name and Datatype for temporary access
                     self::$columns['name'] = $column;
                     self::$columns['datatype'] = $datatype;
                     Capsule::Schema()->table($key, function ($table) {
                         $column = self::$columns['name'];
                         $datatype = self::$columns['datatype'];
                         $table->{$datatype}($column)->after('id');
                     });
                 }
             }
         } else {
             Capsule::schema()->create($key, function ($table) {
                 $table->increments('id');
                 $table->timestamps();
             });
             goto loop;
         }
     }
 }
Exemple #2
0
 /**
  * Test initialization and population of tables
  */
 public function testInitializeAndPopulate()
 {
     $migration = new Migration();
     $migration->tables(array('ut_init', 'ut_pop'));
     $result = $migration->initialize(TRUE);
     $this->assertEquals(2, count($result));
     $this->assertEquals(1, $result['ut_init']);
     $this->assertEquals(2, $result['ut_pop']);
     $database = Database::instance();
     $this->assertRegExp('/testName_1/', $database->queries[2]);
     $this->assertRegExp('/someName_2/', $database->queries[2]);
 }