From 80b20a8b251da88dfee51888e7b45c3ebbf05989 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Mon, 9 Mar 2020 13:16:10 -0400 Subject: [PATCH] Increase ID column size; seed ID generator with uniqid() #630 (#631) --- app/Contracts/Model.php | 2 +- .../2017_06_08_0000_create_users_table.php | 3 +- .../2017_12_20_005147_create_acars_tables.php | 5 ++- .../2018_01_03_014930_create_stats_table.php | 25 +---------- .../2020_03_09_141152_increase_id_lengths.php | 45 +++++++++++++++++++ app/Support/Utils.php | 2 +- .../Services/Importers/FlightImporter.php | 2 +- 7 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 app/Database/migrations/2020_03_09_141152_increase_id_lengths.php diff --git a/app/Contracts/Model.php b/app/Contracts/Model.php index bb9d0ddc..bb56dec7 100644 --- a/app/Contracts/Model.php +++ b/app/Contracts/Model.php @@ -13,7 +13,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model /** * Max length of ID for string columns */ - public const ID_MAX_LENGTH = 12; + public const ID_MAX_LENGTH = 16; /** * For the factories, skip the mutators. Only apply to one instance diff --git a/app/Database/migrations/2017_06_08_0000_create_users_table.php b/app/Database/migrations/2017_06_08_0000_create_users_table.php index 61339475..cfa66c1a 100755 --- a/app/Database/migrations/2017_06_08_0000_create_users_table.php +++ b/app/Database/migrations/2017_06_08_0000_create_users_table.php @@ -1,6 +1,7 @@ string('country', 2)->nullable(); $table->string('home_airport_id', 5)->nullable(); $table->string('curr_airport_id', 5)->nullable(); - $table->string('last_pirep_id', \App\Models\Pirep::ID_MAX_LENGTH)->nullable(); + $table->string('last_pirep_id', Pirep::ID_MAX_LENGTH)->nullable(); $table->unsignedBigInteger('flights')->default(0); $table->unsignedBigInteger('flight_time')->nullable()->default(0); $table->unsignedBigInteger('transfer_time')->nullable()->default(0); diff --git a/app/Database/migrations/2017_12_20_005147_create_acars_tables.php b/app/Database/migrations/2017_12_20_005147_create_acars_tables.php index 10647470..2222e425 100644 --- a/app/Database/migrations/2017_12_20_005147_create_acars_tables.php +++ b/app/Database/migrations/2017_12_20_005147_create_acars_tables.php @@ -1,6 +1,7 @@ string('id', 12); - $table->string('pirep_id', \App\Contracts\Model::ID_MAX_LENGTH); + $table->string('id', Model::ID_MAX_LENGTH); + $table->string('pirep_id', Model::ID_MAX_LENGTH); $table->unsignedTinyInteger('type'); $table->unsignedInteger('nav_type')->nullable(); $table->unsignedInteger('order')->default(0); diff --git a/app/Database/migrations/2018_01_03_014930_create_stats_table.php b/app/Database/migrations/2018_01_03_014930_create_stats_table.php index f31631e3..3656caac 100644 --- a/app/Database/migrations/2018_01_03_014930_create_stats_table.php +++ b/app/Database/migrations/2018_01_03_014930_create_stats_table.php @@ -2,6 +2,7 @@ use App\Contracts\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; class CreateStatsTable extends Migration { @@ -22,28 +23,6 @@ class CreateStatsTable extends Migration $table->primary('id'); $table->timestamps(); }); - /*$this->addCounterGroups([ - 'flights' => 1, - ]); - - $stats = [ - [ - 'id' => $this->formatSettingId('flights.total_flights'), - 'order' => $this->getNextOrderNumber('flights'), - 'value' => 0, - 'type' => 'int', - 'description' => 'Total number of flights in the VA', - ], - [ - 'id' => $this->formatSettingId('flights.total_time'), - 'order' => $this->getNextOrderNumber('flights'), - 'value' => 0, - 'type' => 'int', - 'description' => 'Total number of hours in the VA', - ], - ]; - - $this->addData('stats', $stats);*/ } /** @@ -53,6 +32,6 @@ class CreateStatsTable extends Migration */ public function down() { - Schema::dropIfExists('settings'); + Schema::dropIfExists('stats'); } } diff --git a/app/Database/migrations/2020_03_09_141152_increase_id_lengths.php b/app/Database/migrations/2020_03_09_141152_increase_id_lengths.php new file mode 100644 index 00000000..32477b55 --- /dev/null +++ b/app/Database/migrations/2020_03_09_141152_increase_id_lengths.php @@ -0,0 +1,45 @@ + ['id', 'pirep_id'], + 'bids' => ['flight_id'], + 'flights' => ['id'], + 'pireps' => ['id', 'flight_id'], + 'flight_fare' => ['flight_id'], + 'flight_field_values' => ['flight_id'], + 'flight_subfleet' => ['flight_id'], + 'pirep_comments' => ['pirep_id'], + 'pirep_fares' => ['pirep_id'], + 'pirep_field_values' => ['pirep_id'], + 'users' => ['last_pirep_id'], + ]; + + foreach ($tables as $table_name => $columns) { + Schema::table($table_name, function (Blueprint $table) use ($columns) { + foreach ($columns as $column) { + $table->string($column, 36)->change(); + } + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +} diff --git a/app/Support/Utils.php b/app/Support/Utils.php index fc11a1d5..6eac5e66 100644 --- a/app/Support/Utils.php +++ b/app/Support/Utils.php @@ -26,7 +26,7 @@ class Utils $length = Model::ID_MAX_LENGTH; } - $hashids = new Hashids('', $length); + $hashids = new Hashids(uniqid(), $length); $mt = str_replace('.', '', microtime(true)); return $hashids->encode($mt); } diff --git a/modules/Importer/Services/Importers/FlightImporter.php b/modules/Importer/Services/Importers/FlightImporter.php index affb0d96..505956e0 100644 --- a/modules/Importer/Services/Importers/FlightImporter.php +++ b/modules/Importer/Services/Importers/FlightImporter.php @@ -54,7 +54,7 @@ class FlightImporter extends BaseImporter // $flight = Flight::updateOrCreate($w, $attrs); $flight = Flight::create(array_merge($w, $attrs)); } catch (\Exception $e) { - //$this->error($e); + $this->error($e); } $this->idMapper->addMapping('flights', $row->id, $flight->id);