Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tonning committed Sep 2, 2024
1 parent 5c1d49f commit 6eb5492
Show file tree
Hide file tree
Showing 42 changed files with 1,129 additions and 234 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
}
],
"repositories": [
{
"type": "path",
"url": "/users/Tonning/Code/packages/astrogoat/strata"
},
{
"type": "composer",
"url": "https://packages.hlx.dev"
Expand All @@ -25,7 +29,7 @@
"require": {
"php": "^8.3",
"astrogoat/cashier": "^0.3.0",
"astrogoat/strata": "^0.7.7",
"astrogoat/strata": "dev-update-index-filtering as 0.7.39",
"illuminate/contracts": "^10.0",
"spatie/laravel-package-tools": "^1.4.3"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::table('plays', function (Blueprint $table) {
$table->string('description')->after('published_year');
});
}

public function down(): void
{
Schema::table('plays', function (Blueprint $table) {
$table->dropColumn('description');
});
}
};
21 changes: 21 additions & 0 deletions database/migrations/2024_08_25_115806_create_genres_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::create('genres', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('genres');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Astrogoat\Monologues\Models\Genre;
use Astrogoat\Monologues\Models\Monologue;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::create('genre_monologue', function (Blueprint $table) {
$table->foreignIdFor(Genre::class)->constrained();
$table->foreignIdFor(Monologue::class)->constrained();
});
}

public function down(): void
{
Schema::dropIfExists('genre_monologue');
}
};
21 changes: 21 additions & 0 deletions database/migrations/2024_08_25_185539_create_identities_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::create('identities', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('identities');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Astrogoat\Monologues\Models\Monologue;
use Illuminate\Database\Migrations\Migration;
use Astrogoat\Monologues\Models\Identity;

return new class extends Migration {
public function up(): void
{
Schema::create('identity_monologue', function (Blueprint $table) {
$table->foreignIdFor(Identity::class)->constrained();
$table->foreignIdFor(Monologue::class)->constrained();
});
}

public function down(): void
{
Schema::dropIfExists('identity_monologue');
}
};
21 changes: 21 additions & 0 deletions database/migrations/2024_08_25_190152_create_ages_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::create('ages', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('ages');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Astrogoat\Monologues\Models\Monologue;
use Illuminate\Database\Migrations\Migration;
use Astrogoat\Monologues\Models\Age;

return new class extends Migration {
public function up(): void
{
Schema::create('age_monologue', function (Blueprint $table) {
$table->foreignIdFor(Age::class)->constrained();
$table->foreignIdFor(Monologue::class)->constrained();
});
}

public function down(): void
{
Schema::dropIfExists('age_monologue');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::create('play_sources', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('play_sources');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Astrogoat\Monologues\Models\Play;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Astrogoat\Monologues\Models\PlaySource;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::create('play_play_source', function (Blueprint $table) {
$table->foreignIdFor(Play::class)->constrained();
$table->foreignIdFor(PlaySource::class)->constrained();
$table->string('url')->nullable();
});
}

public function down(): void
{
Schema::dropIfExists('play_play_source');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
Schema::create('gender_identities', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('gender_identities');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Astrogoat\Monologues\Models\Monologue;
use Illuminate\Database\Migrations\Migration;
use Astrogoat\Monologues\Models\GenderIdentity;

return new class extends Migration {
public function up(): void
{
Schema::create('gender_identity_monologue', function (Blueprint $table) {
$table->foreignIdFor(GenderIdentity::class)->constrained();
$table->foreignIdFor(Monologue::class)->constrained();
});
}

public function down(): void
{
Schema::dropIfExists('gender_identity_monologue');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

use Astrogoat\Monologues\Models\Play;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Astrogoat\Monologues\Models\Monologue;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration {
public function up(): void
{
foreach (Monologue::withoutGlobalScopes()->get() as $monologue) {
$this->convertSexToGenderIdentity($monologue);
$this->convertIdentities($monologue);
$this->convertAges($monologue);
}

foreach (Play::all() as $play) {
$this->convertWhereToFindToSource($play);
$this->convertPlayTypeToMonologueGenre($play);
}

Schema::table('plays', function (Blueprint $table) {
$table->dropColumn('where_to_find');
$table->dropColumn('type');
});

Schema::table('monologues', function (Blueprint $table) {
$table->dropColumn('sex');
$table->dropColumn('identity');
$table->dropColumn('type');
});
}

public function down(): void
{
// Schema::table('plays', function (Blueprint $table) {
// $table->string('where_to_find')->nullable();
// });
}

public function convertSexToGenderIdentity(Monologue $monologue): void
{
$monologue->genderIdentities()->firstOrCreate(['name' => $monologue->sex->fullName()]);
}

public function convertAges(Monologue $monologue): void
{
if ($monologue->age) {
$monologue->ages()->firstOrCreate(['name' => trim($monologue->age)]);
}
}

public function convertIdentities(Monologue $monologue): void
{
$identities = Str::of($monologue->identity)
->replace(',', ';')
->explode(';')
->filter()
->map(fn ($identity) => trim($identity))
->filter();

foreach ($identities as $identity) {
$monologue->identities()->firstOrCreate(['name' => $identity]);
}
}

public function convertWhereToFindToSource(Play $play): void
{
$sources = Str::of($play->where_to_find)
->replace(',', ';')
->explode(';')
->filter()
->map(fn ($source) => trim($source))
->filter();

foreach ($sources as $source) {
$play->playSources()->firstOrCreate(['name' => $source]);
}
}

public function convertPlayTypeToMonologueGenre(Play $play): void
{
foreach ($play->monologues()->withoutGlobalScopes()->get() as $monologue) {
$monologue->genres()->firstOrCreate(['name' => $play->type]);
}
}
};
Loading

0 comments on commit 6eb5492

Please sign in to comment.