feat: Board, BoardColumn, Card, User tables
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('users', function (Blueprint $table): void {
|
||||
$table->increments('user_id');
|
||||
$table->string('email', 255);
|
||||
$table->string('password_hash', 255);
|
||||
$table->string('name', 255);
|
||||
$table->timestamp('created_datetime')->useCurrent();
|
||||
$table->timestamp('updated_datetime')->nullable();
|
||||
|
||||
$table->unique('email', 'idx_email');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('boards', function (Blueprint $table): void {
|
||||
$table->increments('board_id');
|
||||
$table->string('title', 255);
|
||||
$table->integer('owner_user_id');
|
||||
$table->boolean('is_public')->default(false);
|
||||
$table->timestamp('created_datetime')->useCurrent();
|
||||
$table->timestamp('updated_datetime')->nullable();
|
||||
|
||||
$table->foreign('owner_user_id')
|
||||
->references('user_id')
|
||||
->on('users')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
Schema::dropIfExists('boards');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('board_columns', function (Blueprint $table): void {
|
||||
$table->increments('column_id');
|
||||
$table->integer('board_id');
|
||||
$table->smallInteger('ordinal_position');
|
||||
$table->string('title', 255);
|
||||
$table->string('color', 6)->nullable();
|
||||
|
||||
$table->index('board_id', 'idx_board_id');
|
||||
|
||||
$table->foreign('board_id')
|
||||
->references('board_id')
|
||||
->on('boards')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
Schema::dropIfExists('board_columns');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('cards', function (Blueprint $table): void {
|
||||
$table->increments('card_id');
|
||||
$table->integer('board_id');
|
||||
$table->integer('column_id');
|
||||
$table->smallInteger('sort_index');
|
||||
$table->string('title', 255);
|
||||
$table->text('content')->nullable();
|
||||
$table->string('color', 6)->nullable();
|
||||
$table->boolean('is_archived')->default(false);
|
||||
$table->timestamp('created_datetime')->useCurrent();
|
||||
$table->timestamp('updated_datetime')->nullable();
|
||||
|
||||
$table->foreign('board_id')
|
||||
->references('board_id')
|
||||
->on('boards')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->foreign('column_id')
|
||||
->references('column_id')
|
||||
->on('board_columns')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
|
||||
DB::statement('create index "idx_active_board_id" on "cards" ("board_id") where "is_archived" = false');
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
Schema::dropIfExists('cards');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
final class Board extends Model {
|
||||
protected $table = 'boards';
|
||||
|
||||
protected $primaryKey = 'board_id';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['title', 'owner_user_id', 'is_public'];
|
||||
|
||||
protected $casts = [
|
||||
'board_id' => 'int',
|
||||
'owner_user_id' => 'int',
|
||||
'is_public' => 'bool',
|
||||
'created_datetime' => 'datetime',
|
||||
'updated_datetime' => 'datetime',
|
||||
];
|
||||
|
||||
public function owner(): BelongsTo {
|
||||
return $this->belongsTo(User::class, 'owner_user_id', 'user_id');
|
||||
}
|
||||
|
||||
public function columns(): HasMany {
|
||||
return $this->hasMany(BoardColumn::class, 'board_id', 'board_id');
|
||||
}
|
||||
|
||||
public function cards(): HasMany {
|
||||
return $this->hasMany(Card::class, 'board_id', 'board_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
final class BoardColumn extends Model {
|
||||
protected $table = 'board_columns';
|
||||
|
||||
protected $primaryKey = 'column_id';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['board_id', 'ordinal_position', 'title', 'color'];
|
||||
|
||||
protected $casts = [
|
||||
'column_id' => 'int',
|
||||
'board_id' => 'int',
|
||||
'ordinal_position' => 'int',
|
||||
];
|
||||
|
||||
public function board(): BelongsTo {
|
||||
return $this->belongsTo(Board::class, 'board_id', 'board_id');
|
||||
}
|
||||
|
||||
public function cards(): HasMany {
|
||||
return $this->hasMany(Card::class, 'column_id', 'column_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
final class Card extends Model {
|
||||
protected $table = 'cards';
|
||||
|
||||
protected $primaryKey = 'card_id';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['board_id', 'column_id', 'sort_index', 'title', 'content', 'color', 'is_archived'];
|
||||
|
||||
protected $casts = [
|
||||
'card_id' => 'int',
|
||||
'board_id' => 'int',
|
||||
'column_id' => 'int',
|
||||
'sort_index' => 'int',
|
||||
'is_archived' => 'bool',
|
||||
'created_datetime' => 'datetime',
|
||||
'updated_datetime' => 'datetime',
|
||||
];
|
||||
|
||||
public function board(): BelongsTo {
|
||||
return $this->belongsTo(Board::class, 'board_id', 'board_id');
|
||||
}
|
||||
|
||||
public function column(): BelongsTo {
|
||||
return $this->belongsTo(BoardColumn::class, 'column_id', 'column_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
final class User extends Model {
|
||||
protected $table = 'users';
|
||||
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['email', 'password_hash', 'name'];
|
||||
|
||||
protected $hidden = ['password_hash'];
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'created_datetime' => 'datetime',
|
||||
'updated_datetime' => 'datetime',
|
||||
];
|
||||
|
||||
public function boards(): HasMany {
|
||||
return $this->hasMany(Board::class, 'owner_user_id', 'user_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user