Skip to content

Commit

Permalink
Adapts frontend to have a copy of domains, to ease its development.
Browse files Browse the repository at this point in the history
  • Loading branch information
ijpatricio committed Dec 1, 2020
1 parent 4218828 commit 4b919bd
Show file tree
Hide file tree
Showing 22 changed files with 517 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/Actions/ApiCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public function __construct()
}
}

public function migrateFreshSeed($output = true)
public function migrateFresh($output = true)
{
$this->run('php artisan migrate:fresh --seed --force', $output);
$this->run('php artisan migrate:fresh --force', $output);
}

public function websiteTesting($output = true)
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/FrontendHelperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ private function main()
$this->warn('Available:');
$this->table(['method', 'description'],
[
['method' => 'mfs', 'description' => 'It will migrate:fresh, with seed option on.'],
['method' => 'mf', 'description' => 'It will migrate:fresh.'],
['method' => 'wt', 'description' => 'Seeds a set for E2E testing.'],
]
);
}

private function mfs()
private function mf()
{
resolve(ApiCommands::class)->migrateFreshSeed();
resolve(ApiCommands::class)->migrateFresh();
}

private function wt()
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
"Database\\Seeders\\": "database/seeders/",
"Domains\\":"domains/"
}
},
"autoload-dev": {
Expand Down
12 changes: 6 additions & 6 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_FE_HOST', '127.0.0.1'),
'port' => env('DB_FE_PORT', '3306'),
'database' => env('DB_FE_DATABASE', 'forge'),
'username' => env('DB_FE_USERNAME', 'forge'),
'password' => env('DB_FE_PASSWORD', ''),
'unix_socket' => env('DB_FE_SOCKET', ''),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
Expand Down
69 changes: 53 additions & 16 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,68 @@
namespace Database\Factories;

use App\Models\User;
use Domains\Accounts\Enums\AccountTypeEnum;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Hash;

class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
public function definition(): array
{
return [
'account_type' => AccountTypeEnum::USER,
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'email' => $this->faker->safeEmail,
'password' => Hash::make($this->faker->password(8)),
'email_verified_at' => Carbon::now(),
'trusted' => false,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}

public function unverified(): self
{
return $this->state([
'email_verified_at' => null,
]);
}

public function editor(): self
{
return $this->state([
'account_type' => AccountTypeEnum::EDITOR,
]);
}

public function admin(): self
{
return $this->state([
'account_type' => AccountTypeEnum::ADMIN,
]);
}

public function deleted(): self
{
return $this->state([
'deleted_at' => Carbon::now(),
]);
}

public function trusted(): self
{
return $this->state([
'trusted' => true,
]);
}

public function withRole(string $role): self
{
return $this->state([
'account_type' => $role,
]);
}
}
18 changes: 18 additions & 0 deletions database/migrations/2020_03_15_093618_add_tags_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

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

class AddTagsTable extends Migration
{
public function up(): void
{
Schema::create('tags', static function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
$table->softDeletes();
});
}
}
23 changes: 23 additions & 0 deletions database/migrations/2020_03_19_201343_add_links_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

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

class AddLinksTable extends Migration
{
public function up(): void
{
Schema::create('links', static function (Blueprint $table) {
$table->id();
$table->text('link');
$table->text('description');
$table->string('author_name');
$table->string('author_email');
$table->string('cover_image');
$table->timestamps();
$table->softDeletes();
$table->timestamp('approved_at')->nullable();
});
}
}
17 changes: 17 additions & 0 deletions database/migrations/2020_03_19_202800_add_link_tag_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

class AddLinkTagTable extends Migration
{
public function up(): void
{
Schema::create('link_tag', static function (Blueprint $table) {
$table->id();
$table->foreignId('link_id')->constrained();
$table->foreignId('tag_id')->constrained();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

class AddTitleColumnToLinksTable extends Migration
{
public function up(): void
{
Schema::table('links', function (Blueprint $table) {
$table->string('title')->nullable()->index();
});
}
}
23 changes: 23 additions & 0 deletions database/migrations/2020_10_04_140743_create_users_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

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

class CreateUsersTable extends Migration
{
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name')->index();
$table->string('email')->unique();
$table->string('password');
$table->boolean('trusted')->default(false);
$table->timestampTz('email_verified_at')->nullable();

$table->timestampsTz();
$table->softDeletesTz();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

class AlterTimestampsColumnsToTagsTable extends Migration
{
public function up(): void
{
Schema::table('tags', function (Blueprint $table) {
$table->dateTimeTz("created_at")->change();
$table->dateTimeTz("updated_at")->change();
$table->dateTimeTz("deleted_at")->change();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

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

class AlterTimestampsColumnsToLinksTable extends Migration
{
public function up(): void
{
Schema::table('links', function (Blueprint $table) {
$table->dateTimeTz("approved_at")->nullable()->change();
$table->dateTimeTz("created_at")->change();
$table->dateTimeTz("updated_at")->change();
$table->dateTimeTz("deleted_at")->change();
});
}
}

25 changes: 25 additions & 0 deletions database/migrations/2020_10_12_104113_create_questions_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Domains\Accounts\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestionsTable extends Migration
{
public function up(): void
{
Schema::create('questions', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('author_id');
$table->string('title')->index();
$table->string('slug');
$table->text('description');
$table->timestampsTz();
$table->softDeletesTz();
$table->timestampTz('resolved_at')->nullable();

$table->index('author_id');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

class AddAccountTypeToUsersTable extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->enum('account_type', ['user', 'editor', 'admin'])->default('user')->after('id');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Domains\Accounts\Models\User;
use Domains\Discussions\Models\Question;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestionAnswersTable extends Migration
{
public function up(): void
{
Schema::create('question_answers', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('author_id');
$table->unsignedInteger('question_id');
$table->text('content');
$table->timestampsTz();
$table->softDeletesTz();

$table->index('question_id');
$table->index('author_id');
$table->index('created_at');
});
}
}
6 changes: 5 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// User::factory(10)->create();
if (app()->environment('production')) {
abort(1, 'I will not run in production, period!');
}
$this->call(LinksTableSeeder::class);
$this->call(UsersTableSeeder::class);
}
}
Loading

0 comments on commit 4b919bd

Please sign in to comment.