Skip to content

Commit

Permalink
ci: data reading has been validated to generate migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleon4 committed Aug 8, 2023
1 parent 09d1daf commit b131dc1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 95 deletions.
14 changes: 3 additions & 11 deletions app/Console/Framework/Migrations/GenerateMigrationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$tbl = $table->{"Tables_in_{$connection['dbname']}"};
$table_name = str->of($tbl)->test("/-/") ? "`{$tbl}`" : $tbl;
$new_table_name = str->of($table_name)->replace("-", "_")->replace("`", "")->lower()->get();
$columns_db = DB::connection($connection['dbname'])
->show()
->full()
->columns()
->from($table_name)
->getAll();
$columns_db = DB::connection($connection['dbname'])->show()->full()->columns()->from($table_name)->getAll();

$foreigns = DB::connection($connection['dbname'])
->table("INFORMATION_SCHEMA.KEY_COLUMN_USAGE", true)
Expand All @@ -113,9 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
->isNotNull()
->fetchMode(\PDO::FETCH_ASSOC)
->getAll();
$foreigns = !isset($foreigns->status)
? arr->of(!isset($foreigns[0]) ? [$foreigns] : $foreigns)->keyBy('COLUMN_NAME')
: [];
$foreigns = !isset($foreigns->status) ? arr->of($foreigns)->keyBy('COLUMN_NAME') : [];
$size_columns_db = arr->of($columns_db)->length();
$columns = "";

Expand Down Expand Up @@ -171,12 +164,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
Store::folder($path);
$migration_name = str->of($path)->concat("Table")->concat($tbl_pascal)->get();
$info_table = DB::connection($connection['dbname'])->table($table_name)->select()->limit(0, $limit)->fetchMode(\PDO::FETCH_ASSOC)->getAll();
$info_table = !isset($info_table[0]) ? [$info_table] : $info_table;

$rows_insert = "";
if (!isset($info_table->status)) {
foreach ($info_table as $key => $row) {
$rows_insert .= ("\t\t\t\t[" . $addRow($columns_db, (array) $row) . "],\n");
$rows_insert .= ("\t\t\t\t[{$addRow($columns_db, (array) $row)}],\n");
}
}

Expand Down
Loading

0 comments on commit b131dc1

Please sign in to comment.