Skip to content

Commit 4cfb894

Browse files
committed
Fix broken users table in database causing validation errors.
1 parent 8daf970 commit 4cfb894

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
66
## v0.7.3 (Derelict Dermodactylus)
77
### Fixed
88
* Fixes server creation API endpoint not passing the provided `external_id` to the creation service.
9+
* Fixes a bug causing users to be un-editable on new installations once more than one user exists.
910

1011
### Added
1112
* Adds ability to modify the external ID for a server through the API.

app/Models/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class User extends Model implements
121121
* @var array
122122
*/
123123
protected $attributes = [
124+
'external_id' => null,
124125
'root_admin' => false,
125126
'language' => 'en',
126127
'use_totp' => false,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\DB;
4+
use Illuminate\Support\Facades\Schema;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Database\Migrations\Migration;
7+
8+
class RemoveDefaultNullValueOnTable extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*
13+
* @throws \Exception
14+
* @throws \Throwable
15+
*/
16+
public function up()
17+
{
18+
Schema::table('users', function (Blueprint $table) {
19+
$table->string('external_id')->default(null)->change();
20+
});
21+
22+
DB::transaction(function () {
23+
DB::table('users')->where('external_id', '=' , 'NULL')->update([
24+
'external_id' => null,
25+
]);
26+
});
27+
}
28+
29+
/**
30+
* Reverse the migrations.
31+
*
32+
* @return void
33+
*/
34+
public function down()
35+
{
36+
// This should not be rolled back.
37+
}
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class DefineUniqueIndexOnUsersExternalId extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('users', function (Blueprint $table) {
17+
$table->index(['external_id']);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('users', function (Blueprint $table) {
29+
$table->dropIndex(['external_id']);
30+
});
31+
}
32+
}

0 commit comments

Comments
 (0)