Archived
1
0
Fork 0

Initial Commit

This commit is contained in:
Henrik Hautakoski 2021-10-18 11:53:33 +02:00
commit ddf09fe00c
113 changed files with 187148 additions and 0 deletions

1
database/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.sqlite*

View file

@ -0,0 +1,62 @@
<?php
namespace Database\Factories;
use App\Models\Character;
use App\Models\Raid;
use App\Models\Card as Model;
use Illuminate\Database\Eloquent\Factories\Factory;
class CardFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$words = $this->faker->words(10);
$words[rand(0, count($words)-1)] = '?';
return [
'raid_id' => null,
'character_id' => null,
'body' => join(" ", $words)
];
}
public function random_character()
{
return $this->state(function (array $attributes) {
return [
'raid_id' => Character::all()->random()->id,
];
});
}
public function random_class()
{
return $this->state(function (array $attributes) {
return [
'class' => $this->faker->randomElement(['warrior', 'rogue', 'paladin', 'mage', 'warlock', 'shaman', 'druid', 'priest']),
];
});
}
public function random_raid()
{
return $this->state(function (array $attributes) {
return [
'raid_id' => Raid::factory(),
];
});
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Database\Factories;
use App\Models\Card;
use App\Models\Character as Model;
use Illuminate\Database\Eloquent\Factories\Factory;
class CharacterFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->firstName(),
];
}
public function cards($count)
{
$cards = Card::factory()
->count($count)
->state(function (array $attr) {
return ['class' => null ];
});
return $this->has($cards);
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\Raid as Model;
use Illuminate\Database\Eloquent\Factories\Factory;
class RaidFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->unique()->text(64),
];
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\Setting as Model;
use Illuminate\Database\Eloquent\Factories\Factory;
class SettingFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'value' => [ 'asdf' => 123]
];
}
}

View file

@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Base extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->timestamp('created_at')->useCurrent();
$table->json('value');
});
Schema::create('characters', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->softDeletes();
});
Schema::create('raids', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->softDeletes();
});
Schema::create('cards', function (Blueprint $table) {
$table->id();
$table->foreignId('character_id')->nullable()->constrained();
$table->foreignId('raid_id')->nullable()->constrained();
$table->enum('role', ['tank', 'healer', 'dps'])->nullable();
$table->enum('class', ['warrior', 'rogue', 'paladin', 'hunter', 'mage', 'warlock', 'shaman', 'druid', 'priest'])->nullable();
$table->string('body');
$table->softDeletes();
});
Schema::create('card_raids', function (Blueprint $table) {
$table->id();
$table->foreignId('raid_id')->constrained();
$table->foreignId('card_id')->constrained();
});
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Database\Seeders;
use App\Models\Card;
use Illuminate\Database\Seeder;
class CardSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
Card::factory(25)
->random_class()
->create();
Card::factory(10)
->random_class()
->random_raid()
->create();
Card::factory(15)
->random_raid()
->create();
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Database\Seeders;
use App\Models\Character;
use App\Models\Setting;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call(RaidSeeder::class);
$this->call(CardSeeder::class);
Character::factory(30)
->cards(10)
->create();
Setting::factory(10)->create();
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Database\Seeders;
use App\Models\Raid;
use Illuminate\Database\Seeder;
class RaidSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
//$raids = [ 'Karazhan', 'Grul\'s Lair', 'Magtheridon', 'SSC', 'TK' ];
//foreach($raids as $name) {
//Raid::insert(['name' => $name ]);
//}
}
}