From cb3ec60c59406f57169f465ef659bb30d65bb856 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 12 Feb 2022 01:06:44 +0100 Subject: [PATCH] Mod migrations --- app/Activity.php | 11 ++++ ...000_create_telescope_entries_table.php} | 0 ...08_19_000000_create_failed_jobs_table.php} | 0 ..._14_235348_create_nationalities_table.php} | 6 +- ..._22_235143_create_subscriptions_table.php} | 9 +++ ...2017_04_12_010000_create_groups_table.php} | 0 ...17_07_04_235624_create_countries_table.php | 6 +- ...8_01_16_012910_create_activities_table.php | 23 +++++++- .../2018_01_22_234145_create_fees_table.php | 32 ---------- ...4_11_215742_create_subactivities_table.php | 32 ---------- ...5831_create_activity_subactivity_table.php | 32 ---------- ...2020_04_12_223230_create_members_table.php | 4 +- ...700_create_members_confirmed_at_column.php | 32 ---------- ...5_create_members_children_phone_column.php | 32 ---------- ...1_create_subscriptions_relation_column.php | 44 -------------- ...021_07_04_101300_create_payments_table.php | 3 +- ...eate_memberships_subactivity_id_column.php | 59 ------------------- ...2_165326_create_activities_slug_column.php | 36 ----------- ...227_create_activities_is_leader_column.php | 41 ------------- ...629_create_activities_is_member_column.php | 36 ----------- ...ate_payments_last_remembered_at_column.php | 32 ---------- ...01_18_205354_create_memberships_table.php} | 12 ++-- 22 files changed, 58 insertions(+), 424 deletions(-) rename database/migrations/{2018_08_08_100000_create_telescope_entries_table.php => 2010_08_08_100000_create_telescope_entries_table.php} (100%) rename database/migrations/{2019_08_19_000000_create_failed_jobs_table.php => 2010_08_19_000000_create_failed_jobs_table.php} (100%) rename database/migrations/{2018_01_14_235348_create_nationalities_table.php => 2017_01_14_235348_create_nationalities_table.php} (92%) rename database/migrations/{2018_01_22_235143_create_subscriptions_table.php => 2017_01_22_235143_create_subscriptions_table.php} (66%) rename database/migrations/{2020_04_12_010000_create_groups_table.php => 2017_04_12_010000_create_groups_table.php} (100%) delete mode 100644 database/migrations/2018_01_22_234145_create_fees_table.php delete mode 100644 database/migrations/2020_04_11_215742_create_subactivities_table.php delete mode 100644 database/migrations/2020_04_11_215831_create_activity_subactivity_table.php delete mode 100644 database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php delete mode 100644 database/migrations/2021_06_28_205305_create_members_children_phone_column.php delete mode 100644 database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php delete mode 100644 database/migrations/2021_08_22_151457_create_memberships_subactivity_id_column.php delete mode 100644 database/migrations/2021_08_22_165326_create_activities_slug_column.php delete mode 100644 database/migrations/2021_08_22_223227_create_activities_is_leader_column.php delete mode 100644 database/migrations/2021_08_22_231629_create_activities_is_member_column.php delete mode 100644 database/migrations/2021_10_29_193944_create_payments_last_remembered_at_column.php rename database/migrations/{2018_01_18_205354_create_memberships_table.php => 2022_01_18_205354_create_memberships_table.php} (59%) diff --git a/app/Activity.php b/app/Activity.php index c6e28c4e..4d51a522 100644 --- a/app/Activity.php +++ b/app/Activity.php @@ -3,6 +3,7 @@ namespace App; use App\Nami\HasNamiField; +use Cviebrock\EloquentSluggable\Sluggable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -10,6 +11,7 @@ class Activity extends Model { use HasNamiField; + use Sluggable; public $fillable = ['is_try', 'is_member', 'name', 'is_filterable', 'nami_id']; public $timestamps = false; @@ -18,6 +20,15 @@ class Activity extends Model 'nami_id' => 'integer' ]; + public function sluggable(): array + { + return [ + 'slug' => [ + 'source' => 'name', + ], + ]; + } + public function subactivities(): BelongsToMany { return $this->belongsToMany(Subactivity::class); } diff --git a/database/migrations/2018_08_08_100000_create_telescope_entries_table.php b/database/migrations/2010_08_08_100000_create_telescope_entries_table.php similarity index 100% rename from database/migrations/2018_08_08_100000_create_telescope_entries_table.php rename to database/migrations/2010_08_08_100000_create_telescope_entries_table.php diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2010_08_19_000000_create_failed_jobs_table.php similarity index 100% rename from database/migrations/2019_08_19_000000_create_failed_jobs_table.php rename to database/migrations/2010_08_19_000000_create_failed_jobs_table.php diff --git a/database/migrations/2018_01_14_235348_create_nationalities_table.php b/database/migrations/2017_01_14_235348_create_nationalities_table.php similarity index 92% rename from database/migrations/2018_01_14_235348_create_nationalities_table.php rename to database/migrations/2017_01_14_235348_create_nationalities_table.php index 7ed7eaf8..9b1633a0 100644 --- a/database/migrations/2018_01_14_235348_create_nationalities_table.php +++ b/database/migrations/2017_01_14_235348_create_nationalities_table.php @@ -1,8 +1,8 @@ id(); $table->string('name'); - $table->integer('nami_id'); + $table->unsignedInteger('nami_id'); $table->timestamps(); }); } diff --git a/database/migrations/2018_01_22_235143_create_subscriptions_table.php b/database/migrations/2017_01_22_235143_create_subscriptions_table.php similarity index 66% rename from database/migrations/2018_01_22_235143_create_subscriptions_table.php rename to database/migrations/2017_01_22_235143_create_subscriptions_table.php index edf8f9bc..f9fb3c59 100644 --- a/database/migrations/2018_01_22_235143_create_subscriptions_table.php +++ b/database/migrations/2017_01_22_235143_create_subscriptions_table.php @@ -13,9 +13,17 @@ class CreateSubscriptionsTable extends Migration */ public function up() { + Schema::create('fees', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->unsignedInteger('nami_id'); + }); + Schema::create('subscriptions', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->unsignedInteger('amount'); + $table->foreignId('fee_id')->constrained(); $table->timestamps(); }); } @@ -28,5 +36,6 @@ class CreateSubscriptionsTable extends Migration public function down() { Schema::dropIfExists('subscriptions'); + Schema::dropIfExists('fees'); } } diff --git a/database/migrations/2020_04_12_010000_create_groups_table.php b/database/migrations/2017_04_12_010000_create_groups_table.php similarity index 100% rename from database/migrations/2020_04_12_010000_create_groups_table.php rename to database/migrations/2017_04_12_010000_create_groups_table.php diff --git a/database/migrations/2017_07_04_235624_create_countries_table.php b/database/migrations/2017_07_04_235624_create_countries_table.php index a9e1a279..d60f64f7 100644 --- a/database/migrations/2017_07_04_235624_create_countries_table.php +++ b/database/migrations/2017_07_04_235624_create_countries_table.php @@ -1,8 +1,8 @@ id(); $table->string('name'); - $table->string('nami_id')->nullable(); + $table->unsignedInteger('nami_id')->nullable(); }); } diff --git a/database/migrations/2018_01_16_012910_create_activities_table.php b/database/migrations/2018_01_16_012910_create_activities_table.php index f659d715..ff370a1a 100644 --- a/database/migrations/2018_01_16_012910_create_activities_table.php +++ b/database/migrations/2018_01_16_012910_create_activities_table.php @@ -1,8 +1,8 @@ id(); $table->string('name'); - $table->integer('nami_id'); + $table->string('slug'); + $table->boolean('is_filterable')->default(false); + $table->boolean('is_member')->default(false); + $table->boolean('is_try')->default(false); + $table->unsignedInteger('nami_id'); + }); + Schema::create('subactivities', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->string('slug'); + $table->boolean('is_age_group')->default(false); + $table->boolean('is_filterable')->default(false); + $table->unsignedInteger('nami_id')->nullable(); + }); + Schema::create('activity_subactivity', function (Blueprint $table) { + $table->foreignId('activity_id')->constrained(); + $table->foreignId('subactivity_id')->constrained(); + $table->unique(['activity_id', 'subactivity_id']); }); } diff --git a/database/migrations/2018_01_22_234145_create_fees_table.php b/database/migrations/2018_01_22_234145_create_fees_table.php deleted file mode 100644 index 15b6bc27..00000000 --- a/database/migrations/2018_01_22_234145_create_fees_table.php +++ /dev/null @@ -1,32 +0,0 @@ -id(); - $table->string('name'); - $table->integer('nami_id'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('fees'); - } -} diff --git a/database/migrations/2020_04_11_215742_create_subactivities_table.php b/database/migrations/2020_04_11_215742_create_subactivities_table.php deleted file mode 100644 index b800cab3..00000000 --- a/database/migrations/2020_04_11_215742_create_subactivities_table.php +++ /dev/null @@ -1,32 +0,0 @@ -id(); - $table->string('name'); - $table->string('nami_id')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('groups'); - } -} diff --git a/database/migrations/2020_04_11_215831_create_activity_subactivity_table.php b/database/migrations/2020_04_11_215831_create_activity_subactivity_table.php deleted file mode 100644 index 99e14cd3..00000000 --- a/database/migrations/2020_04_11_215831_create_activity_subactivity_table.php +++ /dev/null @@ -1,32 +0,0 @@ -foreignId('activity_id')->constrained(); - $table->foreignId('subactivity_id')->constrained(); - $table->unique(['activity_id', 'subactivity_id']); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('activity_subactivity'); - } -} diff --git a/database/migrations/2020_04_12_223230_create_members_table.php b/database/migrations/2020_04_12_223230_create_members_table.php index 3ac74832..3cedc6c0 100644 --- a/database/migrations/2020_04_12_223230_create_members_table.php +++ b/database/migrations/2020_04_12_223230_create_members_table.php @@ -48,12 +48,14 @@ class CreateMembersTable extends Migration $table->string('email_parents')->nullable(); $table->integer('nami_id')->nullable(); $table->foreignId('nationality_id')->constrained(); - $table->foreignId('fee_id')->nullable()->constrained(); $table->text('letter_address')->nullable(); $table->foreignId('bill_kind_id')->nullable()->constrained(); $table->foreignId('first_activity_id')->nullable()->constrained('activities'); $table->foreignId('first_subactivity_id')->nullable()->constrained('subactivities'); $table->unsignedInteger('version')->default(1); + $table->datetime('confirmed_at')->nullable(); + $table->string('children_phone')->nullable(); + $table->foreignId('subscription_id')->nullable()->default(1)->constrained(); $table->timestamps(); }); diff --git a/database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php b/database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php deleted file mode 100644 index 63005deb..00000000 --- a/database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php +++ /dev/null @@ -1,32 +0,0 @@ -datetime('confirmed_at')->nullable()->after('version'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('members', function (Blueprint $table) { - $table->dropColumn('confirmed_at'); - }); - } -} diff --git a/database/migrations/2021_06_28_205305_create_members_children_phone_column.php b/database/migrations/2021_06_28_205305_create_members_children_phone_column.php deleted file mode 100644 index 8c3d6332..00000000 --- a/database/migrations/2021_06_28_205305_create_members_children_phone_column.php +++ /dev/null @@ -1,32 +0,0 @@ -string('children_phone')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('members', function (Blueprint $table) { - $table->dropColumn('children_phone'); - }); - } -} diff --git a/database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php b/database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php deleted file mode 100644 index 90d00ff0..00000000 --- a/database/migrations/2021_07_03_230731_create_subscriptions_relation_column.php +++ /dev/null @@ -1,44 +0,0 @@ -id()->change(); - $table->unsignedInteger('amount')->after('name'); - $table->foreignId('fee_id')->after('name')->constrained(); - }); - - Schema::table('members', function (Blueprint $table) { - $table->foreignId('subscription_id')->after('version')->nullable()->default(1)->constrained(); - }); - - Schema::table('members', function (Blueprint $table) { - $table->dropForeign(['fee_id']); - $table->dropColumn('fee_id'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - // - } -} diff --git a/database/migrations/2021_07_04_101300_create_payments_table.php b/database/migrations/2021_07_04_101300_create_payments_table.php index 750bd808..70d39c4f 100644 --- a/database/migrations/2021_07_04_101300_create_payments_table.php +++ b/database/migrations/2021_07_04_101300_create_payments_table.php @@ -1,9 +1,9 @@ foreignId('subscription_id')->constrained(); $table->foreignId('status_id')->constrained(); $table->foreignId('member_id')->constrained(); + $table->datetime('last_remembered_at')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2021_08_22_151457_create_memberships_subactivity_id_column.php b/database/migrations/2021_08_22_151457_create_memberships_subactivity_id_column.php deleted file mode 100644 index 0cfceb05..00000000 --- a/database/migrations/2021_08_22_151457_create_memberships_subactivity_id_column.php +++ /dev/null @@ -1,59 +0,0 @@ -foreignId('subactivity_id')->nullable()->constrained(); - $table->unsignedBigInteger('activity_id')->change(); - $table->foreign('activity_id')->references('id')->on('activities'); - }); - - Member::whereNotNull('nami_id')->get()->each(function($member): void { - collect($member->getNamiMemberships(Nami::login(env('NAMI_ADMIN_USER'), env('NAMI_ADMIN_PW'))))->filter( - fn ($membership): bool => dump($membership) && $membership['ends_at'] === null, - )->each(function($membership) use ($member): void { - if ($member->memberships()->where('nami_id', $membership['id'])->exists()) { - return; - } - - $member->memberships()->create([ - 'nami_id' => $membership['id'], - 'activity_id' => Activity::nami($membership['activity_id'])->id, - 'subactivity_id' => $membership['subactivity_id'] - ? Subactivity::nami($membership['subactivity_id'])->id - : null, - 'group_id' => Group::nami($membership['group_id'])->id, - 'created_at' => $membership['starts_at'], - ]); - }); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('memberships', function (Blueprint $table) { - // - }); - } -} diff --git a/database/migrations/2021_08_22_165326_create_activities_slug_column.php b/database/migrations/2021_08_22_165326_create_activities_slug_column.php deleted file mode 100644 index 814c1541..00000000 --- a/database/migrations/2021_08_22_165326_create_activities_slug_column.php +++ /dev/null @@ -1,36 +0,0 @@ -boolean('is_age_group')->default(false)->after('name'); - $table->string('slug')->after('name'); - }); - Subactivity::get()->each(fn ($subactivity) => $subactivity->update([])); - Subactivity::whereIn('nami_id', [1,2,3,4,49])->get()->each(fn ($subactivity) => $subactivity->update(['is_age_group' => true])); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('activities', function (Blueprint $table) { - $table->dropColumn('slug'); - }); - } -} diff --git a/database/migrations/2021_08_22_223227_create_activities_is_leader_column.php b/database/migrations/2021_08_22_223227_create_activities_is_leader_column.php deleted file mode 100644 index cfdd3e72..00000000 --- a/database/migrations/2021_08_22_223227_create_activities_is_leader_column.php +++ /dev/null @@ -1,41 +0,0 @@ -boolean('is_filterable')->after('name')->default(false); - }); - Schema::table('subactivities', function (Blueprint $table) { - $table->boolean('is_filterable')->after('slug')->default(false); - }); - Activity::whereIn('name', ['€ Mitglied', '€ passive Mitgliedschaft', 'Schnuppermitgliedschaft', '€ LeiterIn', '€ KassiererIn', '€ KassenprüferIn']) - ->update(['is_filterable' => true]); - SubActivity::whereIn('name', ['Biber', 'Wölfling', 'Jungpfadfinder', 'Pfadfinder', 'Rover', 'Vorstand', 'Sonstige']) - ->update(['is_filterable' => true]); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('activities', function (Blueprint $table) { - // - }); - } -} diff --git a/database/migrations/2021_08_22_231629_create_activities_is_member_column.php b/database/migrations/2021_08_22_231629_create_activities_is_member_column.php deleted file mode 100644 index 163796d6..00000000 --- a/database/migrations/2021_08_22_231629_create_activities_is_member_column.php +++ /dev/null @@ -1,36 +0,0 @@ -boolean('is_member')->default(false); - }); - Schema::table('activities', function (Blueprint $table) { - $table->boolean('is_try')->default(false); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('activities', function (Blueprint $table) { - $table->dropColumn('is_member'); - }); - } -} diff --git a/database/migrations/2021_10_29_193944_create_payments_last_remembered_at_column.php b/database/migrations/2021_10_29_193944_create_payments_last_remembered_at_column.php deleted file mode 100644 index 80640259..00000000 --- a/database/migrations/2021_10_29_193944_create_payments_last_remembered_at_column.php +++ /dev/null @@ -1,32 +0,0 @@ -datetime('last_remembered_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('payments', function (Blueprint $table) { - $table->dropColumn('last_remembered_at'); - }); - } -} diff --git a/database/migrations/2018_01_18_205354_create_memberships_table.php b/database/migrations/2022_01_18_205354_create_memberships_table.php similarity index 59% rename from database/migrations/2018_01_18_205354_create_memberships_table.php rename to database/migrations/2022_01_18_205354_create_memberships_table.php index 577ed091..352a3883 100644 --- a/database/migrations/2018_01_18_205354_create_memberships_table.php +++ b/database/migrations/2022_01_18_205354_create_memberships_table.php @@ -15,13 +15,15 @@ class CreateMembershipsTable extends Migration { Schema::create('memberships', function (Blueprint $table) { $table->id(); - $table->integer('activity_id'); - $table->integer('group_id')->nullable(); - $table->integer('member_id'); - $table->integer('nami_id')->nullable(); + $table->foreignId('group_id')->constrained(); + $table->foreignId('member_id')->constrained(); + $table->unsignedInteger('nami_id')->nullable(); $table->datetime('from'); $table->timestamps(); - $table->unique(['activity_id', 'group_id', 'member_id', 'nami_id']); + $table->foreignId('activity_id')->constrained(); + $table->foreignId('subactivity_id')->nullable()->constrained(); + $table->unique(['activity_id', 'subactivity_id', 'group_id', 'member_id', 'nami_id'], 'memberships_unique'); + }); }