migrate to ulid

v1
Aji Kamaludin 11 months ago
parent 3327637eeb
commit 1840e5ff47
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -1,4 +1,4 @@
APP_NAME='Template App'
APP_NAME='App Name'
APP_ENV=local
APP_KEY=
APP_DEBUG=true

@ -32,8 +32,13 @@ RUN apt-get update && apt-get dist-upgrade -y && \
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo mysqli pdo_mysql mbstring exif pcntl bcmath gd intl zip pgsql pdo_pgsql curl xml
# Install PHP extensions (default version)
# RUN docker-php-ext-install pdo mysqli pdo_mysql mbstring exif pcntl bcmath gd intl zip pgsql pdo_pgsql curl xml
# Install PHP extension with install php extension
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions
RUN install-php-extensions pdo mysqli pdo_mysql mbstring exif pcntl bcmath gd intl zip pgsql pdo_pgsql curl xml
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

@ -41,7 +41,7 @@ class RoleController extends Controller
$request->validate([
'name' => 'string|required|max:255',
'permissions' => 'array|required',
'permissions.*.id' => 'uuid|required|exists:permissions,id',
'permissions.*.id' => 'ulid|required|exists:permissions,id',
]);
DB::beginTransaction();
@ -71,7 +71,7 @@ class RoleController extends Controller
$request->validate([
'name' => 'string|required|max:255',
'permissions' => 'array|required',
'permissions.*.id' => 'uuid|required|exists:permissions,id',
'permissions.*.id' => 'ulid|required|exists:permissions,id',
]);
if ($role->flag == 1) {

@ -30,7 +30,7 @@ class UserController extends Controller
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email',
'password' => 'required|string|max:255',
'role_id' => 'required|uuid|exists:roles,id',
'role_id' => 'required|ulid|exists:roles,id',
]);
User::create([
@ -48,13 +48,13 @@ class UserController extends Controller
{
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email,'.$user->id,
'email' => 'required|email|unique:users,email,' . $user->id,
'password' => 'nullable|string|max:255',
]);
if ($user->role != null) {
$request->validate([
'role_id' => 'required|uuid|exists:roles,id',
'role_id' => 'required|ulid|exists:roles,id',
]);
}

@ -4,14 +4,14 @@ namespace App\Models;
use App\Models\Traits\CascadeSoftDeletes;
use App\Models\Traits\UserTrackable;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;
class Model extends BaseModel
{
use HasFactory, HasUuids, UserTrackable, SoftDeletes, CascadeSoftDeletes;
use HasFactory, HasUlids, UserTrackable, SoftDeletes, CascadeSoftDeletes;
public $cascadeDeletes = [];
}

@ -2,13 +2,13 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
use HasFactory, HasUuids;
use HasFactory, HasUlids;
protected $fillable = [
'name',

@ -2,14 +2,14 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class RolePermission extends Model
{
use HasFactory, SoftDeletes, HasUuids;
use HasFactory, SoftDeletes, HasUlids;
protected $fillable = [
'role_id',

@ -2,14 +2,14 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Setting extends Model
{
use HasFactory, SoftDeletes, HasUuids;
use HasFactory, SoftDeletes, HasUlids;
protected $fillable = [
'key',

@ -4,7 +4,7 @@ namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@ -12,7 +12,7 @@ use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasUuids;
use HasApiTokens, HasFactory, Notifiable, HasUlids;
/**
* The attributes that are mass assignable.

@ -14,13 +14,13 @@ return new class extends Migration
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->ulid('id')->primary();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('reset_token')->nullable();
$table->uuid('role_id')->nullable();
$table->ulid('role_id')->nullable();
$table->rememberToken();
$table->timestamps();
});

@ -14,7 +14,7 @@ return new class extends Migration
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->ulid('id')->primary();
$table->string('key');
$table->text('value');
$table->string('type');

@ -14,13 +14,13 @@ return new class extends Migration
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->ulid('id')->primary();
$table->string('name');
$table->timestamps();
$table->softDeletes();
$table->uuid('created_by')->nullable();
$table->uuid('updated_by')->nullable();
$table->uuid('deleted_by')->nullable();
$table->ulid('created_by')->nullable();
$table->ulid('updated_by')->nullable();
$table->ulid('deleted_by')->nullable();
});
}

@ -14,9 +14,9 @@ return new class extends Migration
public function up()
{
Schema::create('role_permissions', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->uuid('role_id');
$table->uuid('permission_id');
$table->ulid('id')->primary();
$table->ulid('role_id');
$table->ulid('permission_id');
$table->timestamps();
$table->softDeletes();
});

@ -19,27 +19,27 @@ class PermissionSeeder extends Seeder
public function run()
{
$permissions = [
['id' => Str::uuid(), 'label' => 'View Dashboard', 'name' => 'view-dashboard'],
['id' => Str::ulid(), 'label' => 'View Dashboard', 'name' => 'view-dashboard'],
['id' => Str::uuid(), 'label' => 'Create User', 'name' => 'create-user'],
['id' => Str::uuid(), 'label' => 'Update User', 'name' => 'update-user'],
['id' => Str::uuid(), 'label' => 'View User', 'name' => 'view-user'],
['id' => Str::uuid(), 'label' => 'Delete User', 'name' => 'delete-user'],
['id' => Str::ulid(), 'label' => 'Create User', 'name' => 'create-user'],
['id' => Str::ulid(), 'label' => 'Update User', 'name' => 'update-user'],
['id' => Str::ulid(), 'label' => 'View User', 'name' => 'view-user'],
['id' => Str::ulid(), 'label' => 'Delete User', 'name' => 'delete-user'],
['id' => Str::uuid(), 'label' => 'Create Role', 'name' => 'create-role'],
['id' => Str::uuid(), 'label' => 'Update Role', 'name' => 'update-role'],
['id' => Str::uuid(), 'label' => 'View Role', 'name' => 'view-role'],
['id' => Str::uuid(), 'label' => 'Delete Role', 'name' => 'delete-role'],
['id' => Str::ulid(), 'label' => 'Create Role', 'name' => 'create-role'],
['id' => Str::ulid(), 'label' => 'Update Role', 'name' => 'update-role'],
['id' => Str::ulid(), 'label' => 'View Role', 'name' => 'view-role'],
['id' => Str::ulid(), 'label' => 'Delete Role', 'name' => 'delete-role'],
];
foreach($permissions as $permission) {
foreach ($permissions as $permission) {
Permission::insert($permission);
}
$role = Role::create(['name' => 'admin']);
$permissions = Permission::all();
foreach($permissions as $permission) {
foreach ($permissions as $permission) {
$role->rolePermissions()->create(['permission_id' => $permission->id]);
}
@ -56,8 +56,7 @@ class PermissionSeeder extends Seeder
'role_id' => $role->id,
]);
$setting = [
];
$setting = [];
Setting::insert($setting);
}

Loading…
Cancel
Save