public function testSave()
 {
     // No migrations yet
     $this->assertTrue($this->m->save());
     // Has one migration and no changes in model
     $this->assertFalse($this->m->save());
 }
 public function actionSchemamigration($module, $model, $auto = true, $db = null)
 {
     $className = strtr("\\Modules\\{module}\\Models\\{model}", ['{module}' => ucfirst($module), '{model}' => ucfirst($model)]);
     if (class_exists($className) === false) {
         echo "Model not found in namespace: " . $className . PHP_EOL;
         exit(1);
     }
     $path = Alias::get('App.Modules.' . ucfirst($module) . '.Migrations');
     if (!is_dir($path)) {
         mkdir($path);
     }
     $model = new $className();
     $migration = new Migration($model, $path);
     $migration->setDb($db);
     if ($migration->hasChanges() == false) {
         echo "Error: " . $migration->getName() . ". No changes." . PHP_EOL;
         die(1);
     }
     $namespace = strtr("Modules\\{module}\\Migrations", ['{module}' => ucfirst($module)]);
     if ($auto) {
         $safeUp = $migration->getSafeUp();
         $safeDown = $migration->getSafeDown();
     } else {
         $safeUp = '';
         $safeDown = '';
     }
     if ($migration->save()) {
         // TODO $db
         $fileName = $path . DIRECTORY_SEPARATOR . $migration->getName();
         $source = $this->generateTemplate($namespace, $migration->getName(), $safeUp, $safeDown);
         file_put_contents($fileName . '.php', $source);
         list(, $timestamp) = explode('_', $migration->getName());
         $model = new ModelMigration();
         $sync = new Sync($model);
         if ($sync->hasTable($model)) {
             $sync->create();
         }
         echo "Migration created: " . $migration->getName() . PHP_EOL;
     } else {
         echo "Failed to save migration: " . $migration->getName() . ". No changes." . PHP_EOL;
         die(1);
     }
 }