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('
%s FROM GroupPrivileges

View File

@ -114,7 +114,7 @@ class CreateEventConfigTable extends Migration
$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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,12 +16,9 @@ class AddEmailNewsToUsersSettings extends Migration
*/
public function up(): void
{
$this->schema->table(
'users_settings',
function (Blueprint $table): void {
$table->boolean('email_news')->default(false)->after('email_shiftinfo');
}
);
$this->schema->table('users_settings', 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
{
$this->schema->table(
'users_settings',
function (Blueprint $table): void {
$table->dropColumn('email_news');
}
);
$this->schema->table('users_settings', function (Blueprint $table): void {
$table->dropColumn('email_news');
});
}
}

View File

@ -16,14 +16,11 @@ class OauthAddTokens extends Migration
*/
public function up(): void
{
$this->schema->table(
'oauth',
function (Blueprint $table): void {
$table->string('access_token')->nullable()->default(null)->after('identifier');
$table->string('refresh_token')->nullable()->default(null)->after('access_token');
$table->dateTime('expires_at')->nullable()->default(null)->after('refresh_token');
}
);
$this->schema->table('oauth', function (Blueprint $table): void {
$table->string('access_token')->nullable()->default(null)->after('identifier');
$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
{
$this->schema->table(
'oauth',
function (Blueprint $table): void {
$table->dropColumn('access_token');
$table->dropColumn('refresh_token');
$table->dropColumn('expires_at');
}
);
$this->schema->table('oauth', function (Blueprint $table): void {
$table->dropColumn('access_token');
$table->dropColumn('refresh_token');
$table->dropColumn('expires_at');
});
}
}

View File

@ -16,12 +16,9 @@ class NewsAddIsPinned extends Migration
*/
public function up(): void
{
$this->schema->table(
'news',
function (Blueprint $table): void {
$table->boolean('is_pinned')->default(false)->after('is_meeting');
}
);
$this->schema->table('news', 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
{
$this->schema->table(
'news',
function (Blueprint $table): void {
$table->dropColumn('is_pinned');
}
);
$this->schema->table('news', function (Blueprint $table): void {
$table->dropColumn('is_pinned');
});
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -14,12 +14,9 @@ class AddMobileShowToUsersSettings extends Migration
*/
public function up(): void
{
$this->schema->table(
'users_settings',
function (Blueprint $table): void {
$table->boolean('mobile_show')->default(false)->after('email_news');
}
);
$this->schema->table('users_settings', 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
{
$this->schema->table(
'users_settings',
function (Blueprint $table): void {
$table->dropColumn('mobile_show');
}
);
$this->schema->table('users_settings', function (Blueprint $table): void {
$table->dropColumn('mobile_show');
});
}
}

View File

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

View File

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

View File

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

View File

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