Example #1
0
 /**
  * get difference between current db state and last db state, after this
  * create migration with auto-generated queries
  *
  * @param null $module
  * @param string $blacklist
  * @param string $whitelist
  * @param bool $showDiff
  * @return array|bool|string
  */
 public function generateMigration($module = null, $blacklist = '', $whitelist = '', $showDiff = false)
 {
     $blkListedTables = array();
     $blkListedTables[] = $this->options['migrationsSchemaTable'];
     $blkListedTables = array_merge($blkListedTables, $this->strToArray($blacklist));
     $whtListedTables = array();
     $whtListedTables = array_merge($whtListedTables, $this->strToArray($whitelist));
     $options = array();
     $options['blacklist'] = $blkListedTables;
     if (sizeof($whtListedTables) > 0) {
         $options['whitelist'] = $whtListedTables;
     }
     $currDb = new Database($this->db, $options);
     $lastPublishedDb = new Database($this->db, $options, false);
     $lastPublishedDb->fromString($this->getLastDbState());
     $diff = new Diff($this->db, $currDb, $lastPublishedDb);
     $difference = $diff->getDifference();
     if (!count($difference['up']) && !count($difference['down'])) {
         return false;
     } else {
         if ($showDiff) {
             return $difference;
         } else {
             return $this->create($module, $difference);
         }
     }
 }