Unify migration style and cleanup (#1037)

* unify helper methods access type to private
* unify codestyle
* remove unused down methods
This commit is contained in:
Thomas Rupprecht 2023-02-08 21:53:58 +01:00 committed by GitHub
parent 2ff953ef89
commit a1a1cf6f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 161 additions and 298 deletions

View File

@ -36,11 +36,4 @@ class FixOldTables extends Migration
}); });
} }
} }
/**
* Reverse the migration
*/
public function down(): void
{
}
} }

View File

@ -54,7 +54,7 @@ class AddAngelSupporterPermissions extends Migration
); );
} }
protected function getQuery(string $type): string private function getQuery(string $type): string
{ {
return sprintf(' return sprintf('
%s FROM GroupPrivileges %s FROM GroupPrivileges

View File

@ -114,7 +114,7 @@ class CreateEventConfigTable extends Migration
$this->schema->dropIfExists('event_config'); $this->schema->dropIfExists('event_config');
} }
protected function getConfigValue(Collection $config, string $name): mixed private function getConfigValue(Collection $config, string $name): mixed
{ {
$value = $config->where('name', $name)->first('value', (object) ['value' => null])->value; $value = $config->where('name', $name)->first('value', (object) ['value' => null])->value;

View File

@ -31,7 +31,7 @@ class ChangeUsersContactDectFieldSize extends Migration
$this->changeDectTo(5); $this->changeDectTo(5);
} }
protected function changeDectTo(int $length): void private function changeDectTo(int $length): void
{ {
foreach ($this->tables as $table => $column) { foreach ($this->tables as $table => $column) {
if (!$this->schema->hasTable($table)) { if (!$this->schema->hasTable($table)) {

View File

@ -34,11 +34,4 @@ class FixMissingArrivalDates extends Migration
->update((array) $state); ->update((array) $state);
} }
} }
/**
* Down is not possible and not needed since this is a bugfix.
*/
public function down(): void
{
}
} }

View File

@ -16,47 +16,35 @@ class CreateScheduleShiftTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->create( $this->schema->create('schedules', function (Blueprint $table): void {
'schedules', $table->increments('id');
function (Blueprint $table): void { $table->string('url');
$table->increments('id'); });
$table->string('url');
}
);
$this->schema->create( $this->schema->create('schedule_shift', function (Blueprint $table): void {
'schedule_shift', $table->integer('shift_id')->index()->unique();
function (Blueprint $table): void { if ($this->schema->hasTable('Shifts')) {
$table->integer('shift_id')->index()->unique(); // Legacy table access
if ($this->schema->hasTable('Shifts')) { $table->foreign('shift_id')
// Legacy table access ->references('SID')->on('Shifts')
$table->foreign('shift_id') ->onUpdate('cascade')
->references('SID')->on('Shifts') ->onDelete('cascade');
->onUpdate('cascade')
->onDelete('cascade');
}
$this->references($table, 'schedules');
$table->uuid('guid');
} }
);
$this->references($table, 'schedules');
$table->uuid('guid');
});
if ($this->schema->hasTable('Shifts')) { if ($this->schema->hasTable('Shifts')) {
$this->schema->table( $this->schema->table('Shifts', function (Blueprint $table): void {
'Shifts', $table->dropColumn('PSID');
function (Blueprint $table): void { });
$table->dropColumn('PSID');
}
);
} }
if ($this->schema->hasTable('Room')) { if ($this->schema->hasTable('Room')) {
$this->schema->table( $this->schema->table('Room', function (Blueprint $table): void {
'Room', $table->dropColumn('from_frab');
function (Blueprint $table): void { });
$table->dropColumn('from_frab');
}
);
} }
} }
@ -66,24 +54,15 @@ class CreateScheduleShiftTable extends Migration
public function down(): void public function down(): void
{ {
if ($this->schema->hasTable('Room')) { if ($this->schema->hasTable('Room')) {
$this->schema->table( $this->schema->table('Room', function (Blueprint $table): void {
'Room', $table->boolean('from_frab')->default(false);
function (Blueprint $table): void { });
$table->boolean('from_frab')
->default(false);
}
);
} }
if ($this->schema->hasTable('Shifts')) { if ($this->schema->hasTable('Shifts')) {
$this->schema->table( $this->schema->table('Shifts', function (Blueprint $table): void {
'Shifts', $table->integer('PSID')->nullable()->default(null)->unique();
function (Blueprint $table): void { });
$table->integer('PSID')
->nullable()->default(null)
->unique();
}
);
} }
$this->schema->drop('schedule_shift'); $this->schema->drop('schedule_shift');

View File

@ -103,8 +103,7 @@ class CreateNewsTable extends Migration
$this->schema->create('News', function (Blueprint $table): void { $this->schema->create('News', function (Blueprint $table): void {
$table->increments('ID'); $table->increments('ID');
$table->integer('Datum'); $table->integer('Datum');
$table->string('Betreff', 150) $table->string('Betreff', 150)->default('');
->default('');
$table->text('Text'); $table->text('Text');
$this->references($table, 'users', 'UID'); $this->references($table, 'users', 'UID');
$table->boolean('Treffen')->default(false); $table->boolean('Treffen')->default(false);

View File

@ -66,17 +66,14 @@ class CreateMessagesTable extends Migration
private function createNewMessagesTable(): void private function createNewMessagesTable(): void
{ {
$this->schema->create( $this->schema->create('messages', function (Blueprint $table): void {
'messages', $table->increments('id');
function (Blueprint $table): void { $this->referencesUser($table);
$table->increments('id'); $this->references($table, 'users', 'receiver_id');
$this->referencesUser($table); $table->boolean('read')->default(0);
$this->references($table, 'users', 'receiver_id'); $table->text('text');
$table->boolean('read')->default(0); $table->timestamps();
$table->text('text'); });
$table->timestamps();
}
);
} }
private function copyPreviousToNewMessagesTable(): void private function copyPreviousToNewMessagesTable(): void
@ -105,18 +102,14 @@ class CreateMessagesTable extends Migration
private function createPreviousMessagesTable(): void private function createPreviousMessagesTable(): void
{ {
$this->schema->create( $this->schema->create('Messages', function (Blueprint $table): void {
'Messages', $table->increments('id');
function (Blueprint $table): void { $table->integer('Datum');
$table->increments('id'); $this->references($table, 'users', 'SUID');
$table->integer('Datum'); $this->references($table, 'users', 'RUID');
$this->references($table, 'users', 'SUID'); $table->char('isRead')->default('N');
$this->references($table, 'users', 'RUID'); $table->text('Text');
$table->char('isRead') });
->default('N');
$table->text('Text');
}
);
} }
private function copyNewToPreviousMessagesTable(): void private function copyNewToPreviousMessagesTable(): void

View File

@ -59,18 +59,13 @@ class CreateQuestionsTable extends Migration
private function createNewQuestionsTable(): void private function createNewQuestionsTable(): void
{ {
$this->schema->create( $this->schema->create('questions', function (Blueprint $table): void {
'questions', $table->increments('id');
function (Blueprint $table): void { $this->referencesUser($table);
$table->increments('id'); $table->text('text');
$this->referencesUser($table); $table->text('answer')->nullable();
$table->text('text'); $this->references($table, 'users', 'answerer_id')->nullable();
$table->text('answer') });
->nullable();
$this->references($table, 'users', 'answerer_id')
->nullable();
}
);
} }
private function copyPreviousToNewQuestionsTable(): void private function copyPreviousToNewQuestionsTable(): void
@ -94,18 +89,13 @@ class CreateQuestionsTable extends Migration
private function createPreviousQuestionsTable(): void private function createPreviousQuestionsTable(): void
{ {
$this->schema->create( $this->schema->create('Questions', function (Blueprint $table): void {
'Questions', $table->increments('QID');
function (Blueprint $table): void { $this->references($table, 'users', 'UID');
$table->increments('QID'); $table->text('Question');
$this->references($table, 'users', 'UID'); $this->references($table, 'users', 'AID')->nullable();
$table->text('Question'); $table->text('Answer')->nullable();
$this->references($table, 'users', 'AID') });
->nullable();
$table->text('Answer')
->nullable();
}
);
} }
private function copyNewToPreviousQuestionsTable(): void private function copyNewToPreviousQuestionsTable(): void

View File

@ -15,10 +15,7 @@ class UserPersonalDataAddPronounField extends Migration
public function up(): void public function up(): void
{ {
$this->schema->table('users_personal_data', function (Blueprint $table): void { $this->schema->table('users_personal_data', function (Blueprint $table): void {
$table->string('pronoun', 15) $table->string('pronoun', 15)->nullable()->default(null)->after('last_name');
->nullable()
->default(null)
->after('last_name');
}); });
} }

View File

@ -28,11 +28,5 @@ class ChangeMysqlDatabaseEncodingToUtf8mb4 extends Migration
} }
} }
/** // As utf8mb4 is a superset of utf8, there is nothing to do in the downgrade
* Reverse the migration
*/
public function down(): void
{
// As utf8mb4 is a superset of utf8, there is nothing to do here
}
} }

View File

@ -19,16 +19,13 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
{ {
$connection = $this->schema->getConnection(); $connection = $this->schema->getConnection();
$this->schema->table( $this->schema->table('schedules', function (Blueprint $table): void {
'schedules', $table->string('name')->default('')->after('id');
function (Blueprint $table): void { $table->integer('shift_type')->default(0)->after('name');
$table->string('name')->default('')->after('id'); $table->integer('minutes_before')->default(0)->after('shift_type');
$table->integer('shift_type')->default(0)->after('name'); $table->integer('minutes_after')->default(0)->after('minutes_before');
$table->integer('minutes_before')->default(0)->after('shift_type'); $table->timestamps();
$table->integer('minutes_after')->default(0)->after('minutes_before'); });
$table->timestamps();
}
);
$connection->table('schedules') $connection->table('schedules')
->update([ ->update([
@ -37,15 +34,12 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
'minutes_after' => 15, 'minutes_after' => 15,
]); ]);
$this->schema->table( $this->schema->table('schedules', function (Blueprint $table): void {
'schedules', $table->string('name')->default(null)->change();
function (Blueprint $table): void { $table->integer('shift_type')->default(null)->change();
$table->string('name')->default(null)->change(); $table->integer('minutes_before')->default(null)->change();
$table->integer('shift_type')->default(null)->change(); $table->integer('minutes_after')->default(null)->change();
$table->integer('minutes_before')->default(null)->change(); });
$table->integer('minutes_after')->default(null)->change();
}
);
// Add legacy reference // Add legacy reference
if ($this->schema->hasTable('ShiftTypes')) { if ($this->schema->hasTable('ShiftTypes')) {
@ -61,12 +55,9 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
'shift_type' => $connection->raw('(' . $query->toSql() . ')') 'shift_type' => $connection->raw('(' . $query->toSql() . ')')
]); ]);
$this->schema->table( $this->schema->table('schedules', function (Blueprint $table): void {
'schedules', $this->addReference($table, 'shift_type', 'ShiftTypes');
function (Blueprint $table): void { });
$this->addReference($table, 'shift_type', 'ShiftTypes');
}
);
} }
} }
@ -75,16 +66,13 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('schedules', function (Blueprint $table): void {
'schedules', $table->dropForeign('schedules_shift_type_foreign');
function (Blueprint $table): void { $table->dropColumn('name');
$table->dropForeign('schedules_shift_type_foreign'); $table->dropColumn('shift_type');
$table->dropColumn('name'); $table->dropColumn('minutes_before');
$table->dropColumn('shift_type'); $table->dropColumn('minutes_after');
$table->dropColumn('minutes_before'); $table->dropTimestamps();
$table->dropColumn('minutes_after'); });
$table->dropTimestamps();
}
);
} }
} }

View File

@ -16,12 +16,9 @@ class AddEmailNewsToUsersSettings extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->table( $this->schema->table('users_settings', function (Blueprint $table): void {
'users_settings', $table->boolean('email_news')->default(false)->after('email_shiftinfo');
function (Blueprint $table): void { });
$table->boolean('email_news')->default(false)->after('email_shiftinfo');
}
);
} }
/** /**
@ -29,11 +26,8 @@ class AddEmailNewsToUsersSettings extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('users_settings', function (Blueprint $table): void {
'users_settings', $table->dropColumn('email_news');
function (Blueprint $table): void { });
$table->dropColumn('email_news');
}
);
} }
} }

View File

@ -16,14 +16,11 @@ class OauthAddTokens extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->table( $this->schema->table('oauth', function (Blueprint $table): void {
'oauth', $table->string('access_token')->nullable()->default(null)->after('identifier');
function (Blueprint $table): void { $table->string('refresh_token')->nullable()->default(null)->after('access_token');
$table->string('access_token')->nullable()->default(null)->after('identifier'); $table->dateTime('expires_at')->nullable()->default(null)->after('refresh_token');
$table->string('refresh_token')->nullable()->default(null)->after('access_token'); });
$table->dateTime('expires_at')->nullable()->default(null)->after('refresh_token');
}
);
} }
/** /**
@ -31,13 +28,10 @@ class OauthAddTokens extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('oauth', function (Blueprint $table): void {
'oauth', $table->dropColumn('access_token');
function (Blueprint $table): void { $table->dropColumn('refresh_token');
$table->dropColumn('access_token'); $table->dropColumn('expires_at');
$table->dropColumn('refresh_token'); });
$table->dropColumn('expires_at');
}
);
} }
} }

View File

@ -16,12 +16,9 @@ class NewsAddIsPinned extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->table( $this->schema->table('news', function (Blueprint $table): void {
'news', $table->boolean('is_pinned')->default(false)->after('is_meeting');
function (Blueprint $table): void { });
$table->boolean('is_pinned')->default(false)->after('is_meeting');
}
);
} }
/** /**
@ -29,11 +26,8 @@ class NewsAddIsPinned extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('news', function (Blueprint $table): void {
'news', $table->dropColumn('is_pinned');
function (Blueprint $table): void { });
$table->dropColumn('is_pinned');
}
);
} }
} }

View File

@ -16,13 +16,10 @@ class OauthChangeTokensToText extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->table( $this->schema->table('oauth', function (Blueprint $table): void {
'oauth', $table->text('access_token')->change();
function (Blueprint $table): void { $table->text('refresh_token')->change();
$table->text('access_token')->change(); });
$table->text('refresh_token')->change();
}
);
} }
/** /**
@ -30,12 +27,9 @@ class OauthChangeTokensToText extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('oauth', function (Blueprint $table): void {
'oauth', $table->string('access_token')->change();
function (Blueprint $table): void { $table->string('refresh_token')->change();
$table->string('access_token')->change(); });
$table->string('refresh_token')->change();
}
);
} }
} }

View File

@ -20,12 +20,9 @@ class AddShiftsDescription extends Migration
return; return;
} }
$this->schema->table( $this->schema->table('Shifts', function (Blueprint $table): void {
'Shifts', $table->text('description')->nullable()->after('shifttype_id');
function (Blueprint $table): void { });
$table->text('description')->nullable()->after('shifttype_id');
}
);
} }
/** /**
@ -37,11 +34,8 @@ class AddShiftsDescription extends Migration
return; return;
} }
$this->schema->table( $this->schema->table('Shifts', function (Blueprint $table): void {
'Shifts', $table->dropColumn('description');
function (Blueprint $table): void { });
$table->dropColumn('description');
}
);
} }
} }

View File

@ -18,12 +18,9 @@ class UsersSettingsAddEmailGoody extends Migration
{ {
$connection = $this->schema->getConnection(); $connection = $this->schema->getConnection();
$this->schema->table( $this->schema->table('users_settings', function (Blueprint $table): void {
'users_settings', $table->boolean('email_goody')->default(false)->after('email_human');
function (Blueprint $table): void { });
$table->boolean('email_goody')->default(false)->after('email_human');
}
);
$connection $connection
->table('users_settings') ->table('users_settings')
@ -35,11 +32,8 @@ class UsersSettingsAddEmailGoody extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('users_settings', function (Blueprint $table): void {
'users_settings', $table->dropColumn('email_goody');
function (Blueprint $table): void { });
$table->dropColumn('email_goody');
}
);
} }
} }

View File

@ -51,7 +51,7 @@ class FixOldGroupsTableIdAndName extends Migration
* @param string[] $naming * @param string[] $naming
* @param int[] $ids * @param int[] $ids
*/ */
protected function migrate(array $naming, array $ids): void private function migrate(array $naming, array $ids): void
{ {
if (!$this->schema->hasTable('Groups')) { if (!$this->schema->hasTable('Groups')) {
return; return;

View File

@ -14,12 +14,9 @@ class AddMobileShowToUsersSettings extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->table( $this->schema->table('users_settings', function (Blueprint $table): void {
'users_settings', $table->boolean('mobile_show')->default(false)->after('email_news');
function (Blueprint $table): void { });
$table->boolean('mobile_show')->default(false)->after('email_news');
}
);
} }
/** /**
@ -27,11 +24,8 @@ class AddMobileShowToUsersSettings extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('users_settings', function (Blueprint $table): void {
'users_settings', $table->dropColumn('mobile_show');
function (Blueprint $table): void { });
$table->dropColumn('mobile_show');
}
);
} }
} }

View File

@ -14,12 +14,9 @@ class AddDectToRooms extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->table( $this->schema->table('rooms', function (Blueprint $table): void {
'rooms', $table->text('dect')->nullable()->after('description');
function (Blueprint $table): void { });
$table->text('dect')->nullable()->after('description');
}
);
} }
/** /**
@ -27,11 +24,8 @@ class AddDectToRooms extends Migration
*/ */
public function down(): void public function down(): void
{ {
$this->schema->table( $this->schema->table('rooms', function (Blueprint $table): void {
'rooms', $table->dropColumn('dect');
function (Blueprint $table): void { });
$table->dropColumn('dect');
}
);
} }
} }

View File

@ -18,12 +18,9 @@ class AddHideRegisterToAngeltypes extends Migration
return; return;
} }
$this->schema->table( $this->schema->table('AngelTypes', function (Blueprint $table): void {
'AngelTypes', $table->boolean('hide_register')->default(false)->after('show_on_dashboard');
function (Blueprint $table): void { });
$table->boolean('hide_register')->default(false)->after('show_on_dashboard');
}
);
} }
/** /**
@ -35,11 +32,8 @@ class AddHideRegisterToAngeltypes extends Migration
return; return;
} }
$this->schema->table( $this->schema->table('AngelTypes', function (Blueprint $table): void {
'AngelTypes', $table->dropColumn('hide_register');
function (Blueprint $table): void { });
$table->dropColumn('hide_register');
}
);
} }
} }

View File

@ -108,7 +108,7 @@ class CreatePrivilegesAndGroupsRelatedTables extends Migration
$this->schema->drop('privileges_new'); $this->schema->drop('privileges_new');
} }
protected function createNew(): void private function createNew(): void
{ {
$this->schema->create('groups', function (Blueprint $table): void { $this->schema->create('groups', function (Blueprint $table): void {
$table->increments('id'); $table->increments('id');
@ -134,7 +134,7 @@ class CreatePrivilegesAndGroupsRelatedTables extends Migration
}); });
} }
protected function createOldTable(): void private function createOldTable(): void
{ {
$this->schema->create('Groups', function (Blueprint $table): void { $this->schema->create('Groups', function (Blueprint $table): void {
$table->string('Name', 35); $table->string('Name', 35);
@ -162,7 +162,7 @@ class CreatePrivilegesAndGroupsRelatedTables extends Migration
}); });
} }
protected function copyOldToNew(): void private function copyOldToNew(): void
{ {
$connection = $this->schema->getConnection(); $connection = $this->schema->getConnection();
@ -211,7 +211,7 @@ class CreatePrivilegesAndGroupsRelatedTables extends Migration
} }
} }
protected function copyNewToOld(): void private function copyNewToOld(): void
{ {
$connection = $this->schema->getConnection(); $connection = $this->schema->getConnection();

View File

@ -20,13 +20,10 @@ class ShifttypeRemoveAngeltype extends Migration
return; return;
} }
$this->schema->table( $this->schema->table('ShiftTypes', function (Blueprint $table): void {
'ShiftTypes', $table->dropForeign('shifttypes_ibfk_1');
function (Blueprint $table): void { $table->dropColumn('angeltype_id');
$table->dropForeign('shifttypes_ibfk_1'); });
$table->dropColumn('angeltype_id');
}
);
} }
/** /**
@ -38,15 +35,9 @@ class ShifttypeRemoveAngeltype extends Migration
return; return;
} }
$this->schema->table( $this->schema->table('ShiftTypes', function (Blueprint $table): void {
'ShiftTypes', $table->integer('angeltype_id')->after('name')->index()->nullable();
function (Blueprint $table): void { $this->addReference($table, 'angeltype_id', 'AngelTypes', null, 'shifttypes_ibfk_1');
$table->integer('angeltype_id') });
->after('name')
->index()
->nullable();
$this->addReference($table, 'angeltype_id', 'AngelTypes', null, 'shifttypes_ibfk_1');
}
);
} }
} }