Postgres migration improvement; prevent MysqlToPostgres from being run

This commit is contained in:
Kelvin Zhang 2016-08-18 14:02:24 +01:00
parent bdbaca7a19
commit deaf14f53c
2 changed files with 33 additions and 33 deletions

View file

@ -40,28 +40,28 @@ class AddDeletedAtColumnToActivities extends Migration
->where('resource_type', 2)
->join('tracks', 'activities.resource_id', '=', 'tracks.id')
->whereNotNull('tracks.deleted_at')
->update(['activities.deleted_at' => DB::raw('tracks.deleted_at')]);
->update(['deleted_at' => DB::raw('tracks.deleted_at')]);
// Albums
DB::table('activities')
->where('resource_type', 3)
->join('albums', 'activities.resource_id', '=', 'albums.id')
->whereNotNull('albums.deleted_at')
->update(['activities.deleted_at' => DB::raw('albums.deleted_at')]);
->update(['deleted_at' => DB::raw('albums.deleted_at')]);
// Playlists
DB::table('activities')
->where('resource_type', 4)
->join('playlists', 'activities.resource_id', '=', 'playlists.id')
->whereNotNull('playlists.deleted_at')
->update(['activities.deleted_at' => DB::raw('playlists.deleted_at')]);
->update(['deleted_at' => DB::raw('playlists.deleted_at')]);
// Comments
DB::table('activities')
->where('resource_type', 5)
->join('comments', 'activities.resource_id', '=', 'comments.id')
->whereNotNull('comments.deleted_at')
->update(['activities.deleted_at' => DB::raw('comments.deleted_at')]);
->update(['deleted_at' => DB::raw('comments.deleted_at')]);
}
/**

View file

@ -15,34 +15,34 @@ class MysqlToPostgres extends Migration
*/
public function up()
{
$this->console = new ConsoleOutput();
// Generate pgloader config
$mysqlConnection = "from mysql://" . env('DB_USERNAME') . ":" . env('DB_PASSWORD') . "@" . env('DB_HOST') . "/" . env('DB_DATABASE');
$postgresConnection = "into postgresql://" . env('POSTGRESQL_DB_USERNAME', 'homestead') . ":" . env('POSTGRESQL_DB_PASSWORD', 'secret') . "@" . env('POSTGRESQL_DB_HOST', 'localhost') . "/" . env('POSTGRESQL_DB_DATABASE', 'homestead');
$header = "LOAD DATABASE";
$body = <<<'EOD'
with truncate
CAST type datetime to timestamp using zero-dates-to-null,
type date to timestamp using zero-dates-to-null
EXCLUDING TABLE NAMES MATCHING 'migrations';
EOD;
$output = implode("\n", array($header, $mysqlConnection, $postgresConnection, $body));
$configPath = base_path() . "/pfmimport.load";
file_put_contents($configPath, $output);
// Run pgloader
$this->execRunWithCallback("pgloader " . $configPath);
// Run after-import.sql
DB::unprepared(file_get_contents(base_path() . "/database/after-import.sql"));
// Remove pgloader config
unlink($configPath);
// $this->console = new ConsoleOutput();
//
// // Generate pgloader config
// $mysqlConnection = "from mysql://" . env('DB_USERNAME') . ":" . env('DB_PASSWORD') . "@" . env('DB_HOST') . "/" . env('DB_DATABASE');
// $postgresConnection = "into postgresql://" . env('POSTGRESQL_DB_USERNAME', 'homestead') . ":" . env('POSTGRESQL_DB_PASSWORD', 'secret') . "@" . env('POSTGRESQL_DB_HOST', 'localhost') . "/" . env('POSTGRESQL_DB_DATABASE', 'homestead');
//
// $header = "LOAD DATABASE";
// $body = <<<'EOD'
//with truncate
//
//CAST type datetime to timestamp using zero-dates-to-null,
// type date to timestamp using zero-dates-to-null
//
//EXCLUDING TABLE NAMES MATCHING 'migrations';
//EOD;
//
// $output = implode("\n", array($header, $mysqlConnection, $postgresConnection, $body));
// $configPath = base_path() . "/pfmimport.load";
// file_put_contents($configPath, $output);
//
// // Run pgloader
// $this->execRunWithCallback("pgloader " . $configPath);
//
// // Run after-import.sql
// DB::unprepared(file_get_contents(base_path() . "/database/after-import.sql"));
//
// // Remove pgloader config
// unlink($configPath);
}
private function execRunWithCallback($command)