/** * {@inheritdoc} */ public function prepare($connection = null) { if (!is_null($connection)) { $this->connection = $connection; $this->prepared = true; } $tables = $this->getTablesOf($this->connection); $run = new ScriptBuilder(['indent' => 4, 'padding' => 8]); foreach ($tables as $key => $value) { if (in_array($value['table_name'], self::$ignoring)) { continue; } $destination = $this->dictionary->translate($table['table_name']); $records = $this->getDataOf($value['table_name']); $clause = new ScriptBuilder(['indent' => 4, 'padding' => 12]); foreach ($records as $record) { $clause->append('[')->lineBreak()->indent(); foreach ($record as $column => $data) { $clause->append($this->parse($column, $data, $this->dictionary->getColumnsOf($table['table_name'])))->lineBreak(); } if ($this->hasRecords($records, 1)) { $clause->unindent()->append('],')->lineBreak(); } else { $clause->unindent()->append(']')->lineBreak(); } } if ($this->hasRecords($records)) { $run->append('DB::table("' . $destination . '")->insert([')->lineBreak()->append($clause->build(), false)->lineBreak()->append(']);')->lineBreak()->lineBreak(); } } $this->records = $run; return $this; }
/** * {@inheritdoc} */ public function prepare($connection = null) { if (!is_null($connection)) { $this->connection = $connection; $this->prepared = true; } $tables = $this->getTablesOf($this->connection); foreach ($tables as $key => $table) { if (in_array($table['table_name'], self::$ignoring)) { continue; } $destination = $this->dictionary->translate($table['table_name']); $up = new ScriptBuilder(['indent' => 4, 'padding' => 8]); $up->append('Schema::create("' . $destination . '", function($' . 'table) {')->lineBreak()->indent(); $down = new ScriptBuilder(['indent' => 4, 'padding' => 8]); $down->append('Schema::drop("' . $destination . '");'); $schema = $this->getSchemaOf($table['table_name']); foreach ($schema as $clause) { $up->append($this->parse($clause, $this->dictionary->getColumnsOf($table['table_name'])))->lineBreak(); } $indexes = $this->getIndexesOf($table['table_name']); if (!is_null($indexes) && count($indexes)) { foreach ($indexes as $index) { $up->append('$' . 'table->index("' . $index['Key_name'] . '");')->lineBreak(); } } $up->unindent()->append('});')->lineBreak(); $this->schema[$table['table_name']] = ['up' => $up->build(), 'down' => $down->build()]; } return $this; }