From 4cfb8941d5fd6f42ed399f7a2472cde4dc64ab83 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 25 Feb 2018 16:08:01 -0600 Subject: [PATCH] Fix broken users table in database causing validation errors. --- CHANGELOG.md | 1 + app/Models/User.php | 1 + ...152_remove_default_null_value_on_table.php | 38 +++++++++++++++++++ ...fine_unique_index_on_users_external_id.php | 32 ++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 database/migrations/2018_02_25_160152_remove_default_null_value_on_table.php create mode 100644 database/migrations/2018_02_25_160604_define_unique_index_on_users_external_id.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 706af0715..c7d1fc6d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ## v0.7.3 (Derelict Dermodactylus) ### Fixed * Fixes server creation API endpoint not passing the provided `external_id` to the creation service. +* Fixes a bug causing users to be un-editable on new installations once more than one user exists. ### Added * Adds ability to modify the external ID for a server through the API. diff --git a/app/Models/User.php b/app/Models/User.php index 10c710f19..aff4f3287 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -121,6 +121,7 @@ class User extends Model implements * @var array */ protected $attributes = [ + 'external_id' => null, 'root_admin' => false, 'language' => 'en', 'use_totp' => false, diff --git a/database/migrations/2018_02_25_160152_remove_default_null_value_on_table.php b/database/migrations/2018_02_25_160152_remove_default_null_value_on_table.php new file mode 100644 index 000000000..e9414f230 --- /dev/null +++ b/database/migrations/2018_02_25_160152_remove_default_null_value_on_table.php @@ -0,0 +1,38 @@ +string('external_id')->default(null)->change(); + }); + + DB::transaction(function () { + DB::table('users')->where('external_id', '=' , 'NULL')->update([ + 'external_id' => null, + ]); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // This should not be rolled back. + } +} diff --git a/database/migrations/2018_02_25_160604_define_unique_index_on_users_external_id.php b/database/migrations/2018_02_25_160604_define_unique_index_on_users_external_id.php new file mode 100644 index 000000000..0a9b8afe2 --- /dev/null +++ b/database/migrations/2018_02_25_160604_define_unique_index_on_users_external_id.php @@ -0,0 +1,32 @@ +index(['external_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropIndex(['external_id']); + }); + } +}