Mod migrations

This commit is contained in:
philipp lang 2022-02-12 01:06:44 +01:00
parent 7e5c4a7aff
commit cb3ec60c59
22 changed files with 58 additions and 424 deletions

View File

@ -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);
}

View File

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateNationalitiesTable extends Migration
{
@ -16,7 +16,7 @@ class CreateNationalitiesTable extends Migration
Schema::create('nationalities', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('nami_id');
$table->unsignedInteger('nami_id');
$table->timestamps();
});
}

View File

@ -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');
}
}

View File

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCountriesTable extends Migration
{
@ -16,7 +16,7 @@ class CreateCountriesTable extends Migration
Schema::create('countries', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('nami_id')->nullable();
$table->unsignedInteger('nami_id')->nullable();
});
}

View File

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateActivitiesTable extends Migration
{
@ -16,7 +16,24 @@ class CreateActivitiesTable extends Migration
Schema::create('activities', function (Blueprint $table) {
$table->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']);
});
}

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFeesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('fees', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('nami_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('fees');
}
}

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSubactivitiesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('subactivities', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('nami_id')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('groups');
}
}

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateActivitySubactivityTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('activity_subactivity', function (Blueprint $table) {
$table->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');
}
}

View File

@ -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();
});

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMembersConfirmedAtColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('members', function (Blueprint $table) {
$table->datetime('confirmed_at')->nullable()->after('version');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('members', function (Blueprint $table) {
$table->dropColumn('confirmed_at');
});
}
}

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMembersChildrenPhoneColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('members', function (Blueprint $table) {
$table->string('children_phone')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('members', function (Blueprint $table) {
$table->dropColumn('children_phone');
});
}
}

View File

@ -1,44 +0,0 @@
<?php
use App\Fee;
use App\Member\Member;
use App\Payment\Subscription;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSubscriptionsRelationColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('subscriptions', function (Blueprint $table) {
$table->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()
{
//
}
}

View File

@ -1,9 +1,9 @@
<?php
use App\Payment\Status;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Payment\Status;
class CreatePaymentsTable extends Migration
{
@ -31,6 +31,7 @@ class CreatePaymentsTable extends Migration
$table->foreignId('subscription_id')->constrained();
$table->foreignId('status_id')->constrained();
$table->foreignId('member_id')->constrained();
$table->datetime('last_remembered_at')->nullable();
$table->timestamps();
});
}

View File

@ -1,59 +0,0 @@
<?php
use App\Activity;
use App\Group;
use App\Member\Member;
use App\Subactivity;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Zoomyboy\LaravelNami\Nami;
class CreateMembershipsSubactivityIdColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('memberships', function (Blueprint $table) {
$table->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) {
//
});
}
}

View File

@ -1,36 +0,0 @@
<?php
use App\Subactivity;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateActivitiesSlugColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('subactivities', function (Blueprint $table) {
$table->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');
});
}
}

View File

@ -1,41 +0,0 @@
<?php
use App\Activity;
use App\Subactivity;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateActivitiesIsLeaderColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activities', function (Blueprint $table) {
$table->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) {
//
});
}
}

View File

@ -1,36 +0,0 @@
<?php
use App\Activity;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateActivitiesIsMemberColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activities', function (Blueprint $table) {
$table->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');
});
}
}

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePaymentsLastRememberedAtColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('payments', function (Blueprint $table) {
$table->datetime('last_remembered_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('payments', function (Blueprint $table) {
$table->dropColumn('last_remembered_at');
});
}
}

View File

@ -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');
});
}