Skip to content

Instantly share code, notes, and snippets.

@hasnhasan
Created June 17, 2019 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasnhasan/ce46d0f7691809f4bbf48e6aae489da7 to your computer and use it in GitHub Desktop.
Save hasnhasan/ce46d0f7691809f4bbf48e6aae489da7 to your computer and use it in GitHub Desktop.
$this->info('--Aktarım Başladı-');
$connectionName = 'old_mysql';
$newDb = \DB::connection('');
$oldDb = \DB::connection($connectionName);
$tmpOldTables = $oldDb->getDoctrineSchemaManager()->listTables();
$tables = $newDb->getDoctrineSchemaManager()->listTables();
$newTables = [];
$foreignKeys = [];
$indexes = [];
foreach ($tables as $table) {
if (!isset($newTables[$table->getName()])) {
$newTables[$table->getName()] = [];
}
$foreignKeys[$table->getName()] = $table->getForeignKeys();
$indexes[$table->getName()] = $table->getIndexes();
foreach ($table->getColumns() as $column) {
$newTables[$table->getName()][$column->getName()] = $column;
}
}
$oldTables = [];
foreach ($tmpOldTables as $table) {
#Eski db de migrations tablosunu sil
if ($table->getName() == 'migrations') {
$oldDb->select('DROP TABLE migrations');
}
if (!isset($oldTables[$table->getName()])) {
$oldTables[$table->getName()] = [];
}
foreach ($table->getColumns() as $column) {
$oldTables[$table->getName()][$column->getName()] = $column;
}
}
$oldTableNameList = $oldDb->getDoctrineSchemaManager()->listTableNames();
$tableNameList = $newDb->getDoctrineSchemaManager()->listTableNames();
$createTables = array_diff($tableNameList, $oldTableNameList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment