function getTableMigration($table, $mysqli, $indent) { $ind = getIndentation($indent); $output = array(); $output[] = $ind . '// Migration for table ' . $table; $output[] = $ind . '$table = $this->table(\'' . $table . '\');'; $output[] = $ind . '$table'; foreach (getColumns($table, $mysqli) as $column) { if ($column['Field'] !== 'id') { $output[] = getColumnMigration($column['Field'], $column, $indent + 1); } } if ($foreign_keys = getForeignKeysMigrations(getForeignKeys($table, $mysqli), $indent + 1)) { $output[] = $foreign_keys; } $output[] = $ind . ' ->create();'; $output[] = PHP_EOL; return implode(PHP_EOL, $output); }
$modelName = ucfirst($options['nameFilter']->filter($table)); $tableClass = $options['tableClassPrefix'] . $modelName; $content = " protected \$_name = '{$table}';\n"; $pk = getPrimaryKeys($table, $options); if (count($pk) > 1 || !isSequence($table, $pk[0], $options)) { $content .= " protected \$_sequence = false;\n"; } $pk = "array('" . implode("','", $pk) . "')"; $content .= " protected \$_primary = {$pk};\n"; $ok = getOrderKeys($table, $options); if (count($ok) > 0) { $ok = "array('" . implode("','", $ok) . "')"; $content .= " protected \$_defaultOrder = {$ok};\n"; } $rowClass = $options['baseRowClass']; $fks = getForeignKeys($table, $options); if (count($fks) > 0) { $content .= " protected \$_referenceMap = array(\n"; foreach ($fks as $fkID => $fk) { $cols = "array('" . implode("','", $fk['columns']) . "')"; $refCols = "array('" . implode("','", $fk['refColumns']) . "')"; $content .= " '{$fkID}' => array(\n"; $content .= " 'columns' => {$cols},\n"; $content .= " 'refTableClass' => '" . $fk['refTableClass'] . "',\n"; $content .= " 'refColumns' => {$refCols}\n"; $content .= " ),\n"; } $content .= " );\n"; } emitClass($tableClass, $options['baseTableClass'], $content, true); $modelClass = $options['rowClassPrefix'] . $modelName;