From dc21d003549125686d4d6af31e0db5a24eff2f34 Mon Sep 17 00:00:00 2001 From: Benjamin Dowson <8258161+lattlay@users.noreply.github.com> Date: Sun, 28 Oct 2018 15:05:15 -0600 Subject: [PATCH] fix: fix prefix table names (DB_PREFIX) handle (#1938) --- app/Console/Commands/Update.php | 10 ++++---- config/database.php | 2 +- ...07_173437_add_multiple_genders_choices.php | 13 +++++----- .../2018_10_07_120133_fix_json_column.php | 20 ++++++--------- .../testing/disks/public/testfile.vcf | 25 ------------------- 5 files changed, 20 insertions(+), 50 deletions(-) delete mode 100644 storage/framework/testing/disks/public/testfile.vcf diff --git a/app/Console/Commands/Update.php b/app/Console/Commands/Update.php index 786fa91fdac..22e05043194 100644 --- a/app/Console/Commands/Update.php +++ b/app/Console/Commands/Update.php @@ -117,12 +117,12 @@ private function migrateCollationTest() $databasename = $connection->getDatabaseName(); - $schemata = $connection->table('information_schema.schemata') - ->select('DEFAULT_CHARACTER_SET_NAME') - ->where('schema_name', '=', $databasename) - ->get(); + $schemata = DB::select( + 'select DEFAULT_CHARACTER_SET_NAME from information_schema.schemata where schema_name = ?', + [$databasename] + ); - $schema = $schemata->first()->DEFAULT_CHARACTER_SET_NAME; + $schema = $schemata[0]->DEFAULT_CHARACTER_SET_NAME; return config('database.use_utf8mb4') && $schema == 'utf8' || ! config('database.use_utf8mb4') && $schema == 'utf8mb4'; diff --git a/config/database.php b/config/database.php index 40ee8f5b295..f01dae7fe3f 100644 --- a/config/database.php +++ b/config/database.php @@ -96,7 +96,7 @@ 'password' => env('DB_TEST_PASSWORD'), 'charset' => env('DB_USE_UTF8MB4', true) ? 'utf8mb4' : 'utf8', 'collation' => env('DB_USE_UTF8MB4', true) ? 'utf8mb4_unicode_ci' : 'utf8_unicode_ci', - 'prefix' => '', + 'prefix' => env('DB_TEST_PREFIX', ''), 'strict' => false, ], diff --git a/database/migrations/2017_06_07_173437_add_multiple_genders_choices.php b/database/migrations/2017_06_07_173437_add_multiple_genders_choices.php index 255f559760b..d91e5529717 100644 --- a/database/migrations/2017_06_07_173437_add_multiple_genders_choices.php +++ b/database/migrations/2017_06_07_173437_add_multiple_genders_choices.php @@ -13,16 +13,17 @@ class AddMultipleGendersChoices extends Migration public function up() { $driverName = DB::connection()->getDriverName(); + $tablePrefix = DB::connection()->getTablePrefix(); switch ($driverName) { case 'mysql': - DB::statement("ALTER TABLE contacts CHANGE COLUMN gender gender ENUM('male', 'female', 'none')"); - DB::statement("ALTER TABLE significant_others CHANGE COLUMN gender gender ENUM('male', 'female', 'none')"); - DB::statement("ALTER TABLE kids CHANGE COLUMN gender gender ENUM('male', 'female', 'none')"); + DB::statement('ALTER TABLE '.$tablePrefix."contacts CHANGE COLUMN gender gender ENUM('male', 'female', 'none')"); + DB::statement('ALTER TABLE '.$tablePrefix."significant_others CHANGE COLUMN gender gender ENUM('male', 'female', 'none')"); + DB::statement('ALTER TABLE '.$tablePrefix."kids CHANGE COLUMN gender gender ENUM('male', 'female', 'none')"); break; case 'pgsql': - $this->alterEnum('contacts', 'gender', ['male', 'female', 'none']); - $this->alterEnum('significant_others', 'gender', ['male', 'female', 'none']); - $this->alterEnum('kids', 'gender', ['male', 'female', 'none']); + $this->alterEnum($tablePrefix.'contacts', 'gender', ['male', 'female', 'none']); + $this->alterEnum($tablePrefix.'significant_others', 'gender', ['male', 'female', 'none']); + $this->alterEnum($tablePrefix.'kids', 'gender', ['male', 'female', 'none']); break; default: throw new \Exception("Driver {$driverName} not supported."); diff --git a/database/migrations/2018_10_07_120133_fix_json_column.php b/database/migrations/2018_10_07_120133_fix_json_column.php index ee09c95aaa9..c62587499e7 100644 --- a/database/migrations/2018_10_07_120133_fix_json_column.php +++ b/database/migrations/2018_10_07_120133_fix_json_column.php @@ -20,21 +20,15 @@ public function up() $databasename = $connection->getDatabaseName(); - $columns = $connection->table('information_schema.columns') - ->select('table_name', 'column_name') - ->where([ - ['table_schema', '=', $databasename], - ['data_type', '=', 'json'], - ]) - ->whereIn('table_name', [ - 'default_life_event_types', - 'life_event_types', - 'life_events', - ]) - ->get(); + $columns = DB::select( + 'select table_name, column_name from information_schema.columns where table_schema = ? and data_type = ? '. + ' and table_name in (?, ?, ?)', + [$databasename, 'json', 'default_life_event_types', 'life_event_types', 'life_events'] + ); + $tablePrefix = DB::connection()->getTablePrefix(); foreach ($columns as $column) { - DB::statement('ALTER TABLE `'.$databasename.'`.`'.$column->table_name.'` MODIFY `'.$column->column_name.'` text;'); + DB::statement('ALTER TABLE `'.$databasename.'`.`'.$tablePrefix.$column->table_name.'` MODIFY `'.$column->column_name.'` text;'); } } } diff --git a/storage/framework/testing/disks/public/testfile.vcf b/storage/framework/testing/disks/public/testfile.vcf deleted file mode 100644 index a0f1c0b1613..00000000000 --- a/storage/framework/testing/disks/public/testfile.vcf +++ /dev/null @@ -1,25 +0,0 @@ -BEGIN:VCARD -VERSION:3.0 -FN:Bono -N:;Bono;;; -EMAIL;TYPE=INTERNET:bono@example.com -TEL:+1 202-555-0191 -ORG:U2 -TITLE:Lead vocalist -BDAY:1960-05-10 -NOTE:Lorem ipsum dolor sit amet -END:VCARD -BEGIN:VCARD -VERSION:3.0 -FN:John Doe -N:Doe;John;;; -EMAIL;TYPE=INTERNET:john.doe@example.com -END:VCARD -BEGIN:VCARD -VERSION:3.0 -FN: -N:;;;; -NICKNAME:Johnny -ADR:;;17 Shakespeare Ave.;Southampton;;SO17 2HB;United Kingdom -END:VCARD - \ No newline at end of file