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,17 +16,12 @@ class CreateScheduleShiftTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
$this->schema->create( $this->schema->create('schedules', function (Blueprint $table): void {
'schedules',
function (Blueprint $table): void {
$table->increments('id'); $table->increments('id');
$table->string('url'); $table->string('url');
} });
);
$this->schema->create( $this->schema->create('schedule_shift', function (Blueprint $table): void {
'schedule_shift',
function (Blueprint $table): void {
$table->integer('shift_id')->index()->unique(); $table->integer('shift_id')->index()->unique();
if ($this->schema->hasTable('Shifts')) { if ($this->schema->hasTable('Shifts')) {
// Legacy table access // Legacy table access
@ -38,25 +33,18 @@ class CreateScheduleShiftTable extends Migration
$this->references($table, 'schedules'); $this->references($table, 'schedules');
$table->uuid('guid'); $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',
function (Blueprint $table): void {
$table->dropColumn('PSID'); $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',
function (Blueprint $table): void {
$table->dropColumn('from_frab'); $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',
function (Blueprint $table): void {
$table->increments('id'); $table->increments('id');
$this->referencesUser($table); $this->referencesUser($table);
$this->references($table, 'users', 'receiver_id'); $this->references($table, 'users', 'receiver_id');
$table->boolean('read')->default(0); $table->boolean('read')->default(0);
$table->text('text'); $table->text('text');
$table->timestamps(); $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',
function (Blueprint $table): void {
$table->increments('id'); $table->increments('id');
$table->integer('Datum'); $table->integer('Datum');
$this->references($table, 'users', 'SUID'); $this->references($table, 'users', 'SUID');
$this->references($table, 'users', 'RUID'); $this->references($table, 'users', 'RUID');
$table->char('isRead') $table->char('isRead')->default('N');
->default('N');
$table->text('Text'); $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',
function (Blueprint $table): void {
$table->increments('id'); $table->increments('id');
$this->referencesUser($table); $this->referencesUser($table);
$table->text('text'); $table->text('text');
$table->text('answer') $table->text('answer')->nullable();
->nullable(); $this->references($table, 'users', 'answerer_id')->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',
function (Blueprint $table): void {
$table->increments('QID'); $table->increments('QID');
$this->references($table, 'users', 'UID'); $this->references($table, 'users', 'UID');
$table->text('Question'); $table->text('Question');
$this->references($table, 'users', 'AID') $this->references($table, 'users', 'AID')->nullable();
->nullable(); $table->text('Answer')->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',
function (Blueprint $table): void {
$table->string('name')->default('')->after('id'); $table->string('name')->default('')->after('id');
$table->integer('shift_type')->default(0)->after('name'); $table->integer('shift_type')->default(0)->after('name');
$table->integer('minutes_before')->default(0)->after('shift_type'); $table->integer('minutes_before')->default(0)->after('shift_type');
$table->integer('minutes_after')->default(0)->after('minutes_before'); $table->integer('minutes_after')->default(0)->after('minutes_before');
$table->timestamps(); $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',
function (Blueprint $table): void {
$table->string('name')->default(null)->change(); $table->string('name')->default(null)->change();
$table->integer('shift_type')->default(null)->change(); $table->integer('shift_type')->default(null)->change();
$table->integer('minutes_before')->default(null)->change(); $table->integer('minutes_before')->default(null)->change();
$table->integer('minutes_after')->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',
function (Blueprint $table): void {
$this->addReference($table, 'shift_type', 'ShiftTypes'); $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',
function (Blueprint $table): void {
$table->dropForeign('schedules_shift_type_foreign'); $table->dropForeign('schedules_shift_type_foreign');
$table->dropColumn('name'); $table->dropColumn('name');
$table->dropColumn('shift_type'); $table->dropColumn('shift_type');
$table->dropColumn('minutes_before'); $table->dropColumn('minutes_before');
$table->dropColumn('minutes_after'); $table->dropColumn('minutes_after');
$table->dropTimestamps(); $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',
function (Blueprint $table): void {
$table->boolean('email_news')->default(false)->after('email_shiftinfo'); $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',
function (Blueprint $table): void {
$table->dropColumn('email_news'); $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',
function (Blueprint $table): void {
$table->string('access_token')->nullable()->default(null)->after('identifier'); $table->string('access_token')->nullable()->default(null)->after('identifier');
$table->string('refresh_token')->nullable()->default(null)->after('access_token'); $table->string('refresh_token')->nullable()->default(null)->after('access_token');
$table->dateTime('expires_at')->nullable()->default(null)->after('refresh_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',
function (Blueprint $table): void {
$table->dropColumn('access_token'); $table->dropColumn('access_token');
$table->dropColumn('refresh_token'); $table->dropColumn('refresh_token');
$table->dropColumn('expires_at'); $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',
function (Blueprint $table): void {
$table->boolean('is_pinned')->default(false)->after('is_meeting'); $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',
function (Blueprint $table): void {
$table->dropColumn('is_pinned'); $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',
function (Blueprint $table): void {
$table->text('access_token')->change(); $table->text('access_token')->change();
$table->text('refresh_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',
function (Blueprint $table): void {
$table->string('access_token')->change(); $table->string('access_token')->change();
$table->string('refresh_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',
function (Blueprint $table): void {
$table->text('description')->nullable()->after('shifttype_id'); $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',
function (Blueprint $table): void {
$table->dropColumn('description'); $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',
function (Blueprint $table): void {
$table->boolean('email_goody')->default(false)->after('email_human'); $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',
function (Blueprint $table): void {
$table->dropColumn('email_goody'); $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',
function (Blueprint $table): void {
$table->boolean('mobile_show')->default(false)->after('email_news'); $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',
function (Blueprint $table): void {
$table->dropColumn('mobile_show'); $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',
function (Blueprint $table): void {
$table->text('dect')->nullable()->after('description'); $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',
function (Blueprint $table): void {
$table->dropColumn('dect'); $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',
function (Blueprint $table): void {
$table->boolean('hide_register')->default(false)->after('show_on_dashboard'); $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',
function (Blueprint $table): void {
$table->dropColumn('hide_register'); $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',
function (Blueprint $table): void {
$table->dropForeign('shifttypes_ibfk_1'); $table->dropForeign('shifttypes_ibfk_1');
$table->dropColumn('angeltype_id'); $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 {
$table->integer('angeltype_id')
->after('name')
->index()
->nullable();
$this->addReference($table, 'angeltype_id', 'AngelTypes', null, 'shifttypes_ibfk_1'); $this->addReference($table, 'angeltype_id', 'AngelTypes', null, 'shifttypes_ibfk_1');
} });
);
} }
} }