diff --git a/app/Database/Query/Grammars/MySqlGrammar.php b/app/Database/Query/Grammars/MySqlGrammar.php new file mode 100644 index 0000000..1d23512 --- /dev/null +++ b/app/Database/Query/Grammars/MySqlGrammar.php @@ -0,0 +1,11 @@ + 'App\Models\Joined', - 'owned' => 'App\Models\Owned', - 'wish' => 'App\Models\Wish', - ]); + 'joined' => 'App\Models\Joined', + 'owned' => 'App\Models\Owned', + 'wish' => 'App\Models\Wish', + ]); - Paginator::defaultView('vendor.pagination.default'); - Paginator::defaultSimpleView('vendor.pagination.simple-default'); + Paginator::defaultView('vendor.pagination.default'); + Paginator::defaultSimpleView('vendor.pagination.simple-default'); + + DB::connection()->setQueryGrammar(new \App\Database\Query\Grammars\MySqlGrammar()); } } diff --git a/database/factories/OwnedFactory.php b/database/factories/OwnedFactory.php new file mode 100644 index 0000000..0f15cb4 --- /dev/null +++ b/database/factories/OwnedFactory.php @@ -0,0 +1,44 @@ + + */ +class OwnedFactory extends Factory +{ + public function configure() + { + return $this->afterMaking(function (Owned $owned) { + if ($owned->status == 'current') { + $owned->opened = $this->faker->dateTimeThisMonth(); + } + }); + } + + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + $statuses = collect(['current', 'upcoming']); + + return [ + 'collective_id' => Collective::first(), + 'subject' => $this->faker->word(), + 'status' => $statuses->random(), + 'slug' => $this->faker->slug(2, false), + 'title' => $this->faker->words(3, true), + 'image' => $this->faker->image(), + 'hold_member_updates' => $this->faker->boolean(), + 'notify_pending' => $this->faker->boolean(), + 'sort_by' => 'country', + ]; + } +} diff --git a/database/migrations/01_create_collectives_table.php b/database/migrations/01_create_collectives_table.php index f0a1e50..4c22df3 100644 --- a/database/migrations/01_create_collectives_table.php +++ b/database/migrations/01_create_collectives_table.php @@ -4,32 +4,27 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. - * - * @return void */ public function up() { Schema::create('collectives', function (Blueprint $table) { $table->id(); $table->rememberToken(); - $table->timestamps(); + $table->timestamps(6); $table->string('name'); $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('title'); + $table->timestamp('email_verified_at', 6)->nullable(); + $table->string('title'); $table->string('password'); - $table->integer('per_page')->unsigned()->default(15); + $table->integer('per_page')->unsigned()->default(15); }); } /** * Reverse the migrations. - * - * @return void */ public function down() { diff --git a/database/migrations/01_create_failed_jobs_table.php b/database/migrations/01_create_failed_jobs_table.php index 1719198..4436a33 100644 --- a/database/migrations/01_create_failed_jobs_table.php +++ b/database/migrations/01_create_failed_jobs_table.php @@ -4,12 +4,9 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. - * - * @return void */ public function up() { @@ -20,14 +17,12 @@ public function up() $table->text('queue'); $table->longText('payload'); $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); + $table->timestamp('failed_at', 6)->useCurrent(); }); } /** * Reverse the migrations. - * - * @return void */ public function down() { diff --git a/database/migrations/01_create_password_resets_table.php b/database/migrations/01_create_password_resets_table.php index fcacb80..1925009 100644 --- a/database/migrations/01_create_password_resets_table.php +++ b/database/migrations/01_create_password_resets_table.php @@ -4,26 +4,21 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. - * - * @return void */ public function up() { Schema::create('password_resets', function (Blueprint $table) { $table->string('email')->index(); $table->string('token'); - $table->timestamp('created_at')->nullable(); + $table->timestamp('created_at', 6)->nullable(); }); } /** * Reverse the migrations. - * - * @return void */ public function down() { diff --git a/database/migrations/10_create_categories_table.php b/database/migrations/10_create_categories_table.php index b643d1b..73a9140 100644 --- a/database/migrations/10_create_categories_table.php +++ b/database/migrations/10_create_categories_table.php @@ -4,31 +4,26 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. - * - * @return void */ public function up() { Schema::create('categories', function (Blueprint $table) { $table->id(); - $table->timestamps(); - $table->foreignId('parent_id') - ->nullable() - ->constrained('categories') - ->onUpdate('cascade') - ->onDelete('cascade'); - $table->string('name'); + $table->timestamps(6); + $table->foreignId('parent_id') + ->nullable() + ->constrained('categories') + ->onUpdate('cascade') + ->onDelete('cascade'); + $table->string('name'); }); } /** * Reverse the migrations. - * - * @return void */ public function down() { diff --git a/database/migrations/10_create_joined_table.php b/database/migrations/10_create_joined_table.php index 2fbeacb..a8ade29 100644 --- a/database/migrations/10_create_joined_table.php +++ b/database/migrations/10_create_joined_table.php @@ -12,7 +12,7 @@ public function up() { Schema::create('joined', function (Blueprint $table) { $table->id(); - $table->timestamps(); + $table->timestamps(6); $table->foreignId('collective_id') ->constrained('collectives') ->onUpdate('cascade') diff --git a/database/migrations/10_create_owned_table.php b/database/migrations/10_create_owned_table.php new file mode 100644 index 0000000..737f2df --- /dev/null +++ b/database/migrations/10_create_owned_table.php @@ -0,0 +1,39 @@ +id(); + $table->timestamps(6); + $table->foreignId('collective_id') + ->constrained('collectives') + ->onUpdate('cascade') + ->onDelete('cascade'); + $table->string('subject'); + $table->enum('status', ['current', 'upcoming']); + $table->string('slug')->nullable(); + $table->string('title')->nullable(); + $table->string('image')->nullable(); + $table->timestamp('opened', 6)->nullable(); + $table->boolean('hold_member_updates')->default(true); + $table->boolean('notify_pending')->default(true); + $table->string('sort_by')->default('country'); + }); + } + + /** + * Reverse the migrations. + */ + public function down() + { + Schema::dropIfExists('owned'); + } +}; diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php index fd235f8..1608b8b 100644 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -4,12 +4,9 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. - * - * @return void */ public function up() { @@ -19,15 +16,13 @@ public function up() $table->string('name'); $table->string('token', 64)->unique(); $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamps(); + $table->timestamp('last_used_at', 6)->nullable(); + $table->timestamps(6); }); } /** * Reverse the migrations. - * - * @return void */ public function down() { diff --git a/database/migrations/20_create_categorizables_table.php b/database/migrations/20_create_categorizables_table.php index ead2e63..e14509c 100644 --- a/database/migrations/20_create_categorizables_table.php +++ b/database/migrations/20_create_categorizables_table.php @@ -4,31 +4,26 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. - * - * @return void */ public function up() { Schema::create('categorizables', function (Blueprint $table) { $table->id(); - $table->timestamps(); - $table->foreignId('category_id') - ->constrained('categories') - ->onUpdate('cascade') - ->onDelete('restrict'); - $table->unsignedBigInteger('categorizable_id'); - $table->string('categorizable_type'); + $table->timestamps(6); + $table->foreignId('category_id') + ->constrained('categories') + ->onUpdate('cascade') + ->onDelete('restrict'); + $table->unsignedBigInteger('categorizable_id'); + $table->string('categorizable_type'); }); } /** * Reverse the migrations. - * - * @return void */ public function down() { diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index bb310b3..d1a6da9 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,7 +2,6 @@ namespace Database\Seeders; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -10,23 +9,22 @@ class DatabaseSeeder extends Seeder { /** * Seed the application's database. - * - * @return void */ public function run() { - DB::table('collectives')->insert([ - 'created_at' => now(), - 'updated_at' => now(), - 'name' => 'marley', - 'email' => 'mar@m.punkfairie.net', - 'title' => 'aeipathy', - 'password' => bcrypt('marfan4'), - ]); + DB::table('collectives')->insert([ + 'created_at' => now(), + 'updated_at' => now(), + 'name' => 'marley', + 'email' => 'mar@m.punkfairie.net', + 'title' => 'aeipathy', + 'password' => bcrypt('marfan4'), + ]); $this->call([ - CategorySeeder::class, - JoinedSeeder::class - ]); + CategorySeeder::class, + JoinedSeeder::class, + OwnedSeeder::class, + ]); } } diff --git a/database/seeders/OwnedSeeder.php b/database/seeders/OwnedSeeder.php new file mode 100644 index 0000000..983bdcd --- /dev/null +++ b/database/seeders/OwnedSeeder.php @@ -0,0 +1,48 @@ +count(50) + ->create(); + + $pivots = []; + $cats = Category::inRandomOrder()->select('id')->get(); + + $i = 1; + + while ($i <= 50) { + $pivots[] = [ + 'category_id' => $cats->random()->id, + 'categorizable_id' => $i, + 'categorizable_type' => 'owned', + ]; + ++$i; + } + + $i = 1; + + while ($i <= rand(20, 100)) { + $pivots[] = [ + 'category_id' => $cats->random()->id, + 'categorizable_id' => rand(1, 50), + 'categorizable_type' => 'owned', + ]; + ++$i; + } + + DB::table('categorizables')->insert($pivots); + } +} diff --git a/tests/Feature/Models/OwnedTest.php b/tests/Feature/Models/OwnedTest.php new file mode 100644 index 0000000..b46239f --- /dev/null +++ b/tests/Feature/Models/OwnedTest.php @@ -0,0 +1,7 @@ +get('/'); + + $response->assertStatus(200); +});