From ae303882b4cdc8c62081c643882d902ef80022d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20Fie=C3=9Finger?= <41627893+bfiessinger@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:05:46 +0200 Subject: [PATCH] use Laravel migration commands instead of raw SQL statements to avoid incompatibilities with other Databases that do not support the ALTER TABLE statement --- src/views/generators/char_migration.blade.php | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/views/generators/char_migration.blade.php b/src/views/generators/char_migration.blade.php index 065d989..66e1ce6 100644 --- a/src/views/generators/char_migration.blade.php +++ b/src/views/generators/char_migration.blade.php @@ -11,11 +11,25 @@ public function up() { Schema::table(\Config::get('countries.table_name'), function($table) { - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY country_code CHAR(3) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_2 CHAR(2) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_3 CHAR(3) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY region_code CHAR(3) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY sub_region_code CHAR(3) NOT NULL DEFAULT ''"); + $table->char('country_code', 3) + ->default('') + ->change(); + + $table->char('iso_3166_2', 2) + ->default('') + ->change(); + + $table->char('iso_3166_3', 3) + ->default('') + ->change(); + + $table->char('region_code', 3) + ->default('') + ->change(); + + $table->char('sub_region_code', 3) + ->default('') + ->change(); }); } /** @@ -27,11 +41,25 @@ public function down() { Schema::table(\Config::get('countries.table_name'), function($table) { - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY country_code VARCHAR(3) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_2 VARCHAR(2) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_3 VARCHAR(3) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY region_code VARCHAR(3) NOT NULL DEFAULT ''"); - DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY sub_region_code VARCHAR(3) NOT NULL DEFAULT ''"); + $table->string('country_code', 3) + ->default('') + ->change(); + + $table->string('iso_3166_2', 2) + ->default('') + ->change(); + + $table->string('iso_3166_3', 3) + ->default('') + ->change(); + + $table->string('region_code', 3) + ->default('') + ->change(); + + $table->string('sub_region_code', 3) + ->default('') + ->change(); }); }