From 664fa8990ba583759922edc574dfa5dda7b9bbf4 Mon Sep 17 00:00:00 2001 From: habibie11 Date: Mon, 5 Jan 2026 10:06:24 +0700 Subject: [PATCH 1/4] fix --- ..._03_09_134418_create_permission_tables.php | 152 ++++++++++++++++++ ..._03_09_182906_create_permission_tables.php | 132 +-------------- .../2026_01_05_012917_set_nullable_das.php | 37 +++++ 3 files changed, 191 insertions(+), 130 deletions(-) create mode 100644 database/migrations/2022_03_09_134418_create_permission_tables.php create mode 100644 database/migrations/2026_01_05_012917_set_nullable_das.php diff --git a/database/migrations/2022_03_09_134418_create_permission_tables.php b/database/migrations/2022_03_09_134418_create_permission_tables.php new file mode 100644 index 000000000..85874a8e6 --- /dev/null +++ b/database/migrations/2022_03_09_134418_create_permission_tables.php @@ -0,0 +1,152 @@ +engine('InnoDB'); + $table->bigIncrements('id'); // permission id + $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) + $table->string('guard_name'); // For MyISAM use string('guard_name', 25); + $table->timestamps(); + + $table->unique(['name', 'guard_name']); + }); + + Schema::dropIfExists($tableNames['roles']); + + Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) { + // $table->engine('InnoDB'); + $table->bigIncrements('id'); // role id + if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing + $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); + $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); + } + $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) + $table->string('guard_name'); // For MyISAM use string('guard_name', 25); + $table->timestamps(); + if ($teams || config('permission.testing')) { + $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); + } else { + $table->unique(['name', 'guard_name']); + } + }); + + Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) { + $table->unsignedBigInteger($pivotPermission); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); + + $table->foreign($pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } else { + $table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } + + }); + + Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) { + $table->unsignedBigInteger($pivotRole); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); + + $table->foreign($pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } else { + $table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } + }); + + Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) { + $table->unsignedBigInteger($pivotPermission); + $table->unsignedBigInteger($pivotRole); + + $table->foreign($pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->onDelete('cascade'); + + $table->foreign($pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->onDelete('cascade'); + + $table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary'); + }); + + DB::statement('SET foreign_key_checks=1'); + Artisan::call('db:seed', [ + '--class' => 'RoleSpatieSeeder', + '--force' => true, + ]); + + app('cache') + ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) + ->forget(config('permission.cache.key')); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $tableNames = config('permission.table_names'); + + throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); + + Schema::drop($tableNames['role_has_permissions']); + Schema::drop($tableNames['model_has_roles']); + Schema::drop($tableNames['model_has_permissions']); + Schema::drop($tableNames['roles']); + Schema::drop($tableNames['permissions']); + } +}; diff --git a/database/migrations/2022_03_09_182906_create_permission_tables.php b/database/migrations/2022_03_09_182906_create_permission_tables.php index 85874a8e6..1396961cf 100644 --- a/database/migrations/2022_03_09_182906_create_permission_tables.php +++ b/database/migrations/2022_03_09_182906_create_permission_tables.php @@ -11,127 +11,7 @@ */ public function up(): void { - DB::statement('SET foreign_key_checks=0'); - - // cek table dari sentinel - Schema::dropIfExists('role_users'); - Schema::dropIfExists('activations'); - Schema::dropIfExists('persistences'); - Schema::dropIfExists('reminders'); - - // end cek table dari sentinel - - $teams = config('permission.teams'); - $tableNames = config('permission.table_names'); - $columnNames = config('permission.column_names'); - $pivotRole = $columnNames['role_pivot_key'] ?? 'role_id'; - $pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id'; - - throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.'); - throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), Exception::class, 'Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.'); - - Schema::create($tableNames['permissions'], static function (Blueprint $table) { - // $table->engine('InnoDB'); - $table->bigIncrements('id'); // permission id - $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) - $table->string('guard_name'); // For MyISAM use string('guard_name', 25); - $table->timestamps(); - - $table->unique(['name', 'guard_name']); - }); - - Schema::dropIfExists($tableNames['roles']); - - Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) { - // $table->engine('InnoDB'); - $table->bigIncrements('id'); // role id - if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing - $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); - $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); - } - $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) - $table->string('guard_name'); // For MyISAM use string('guard_name', 25); - $table->timestamps(); - if ($teams || config('permission.testing')) { - $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); - } else { - $table->unique(['name', 'guard_name']); - } - }); - - Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) { - $table->unsignedBigInteger($pivotPermission); - - $table->string('model_type'); - $table->unsignedBigInteger($columnNames['model_morph_key']); - $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); - - $table->foreign($pivotPermission) - ->references('id') // permission id - ->on($tableNames['permissions']) - ->onDelete('cascade'); - if ($teams) { - $table->unsignedBigInteger($columnNames['team_foreign_key']); - $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); - - $table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], - 'model_has_permissions_permission_model_type_primary'); - } else { - $table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'], - 'model_has_permissions_permission_model_type_primary'); - } - - }); - - Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) { - $table->unsignedBigInteger($pivotRole); - - $table->string('model_type'); - $table->unsignedBigInteger($columnNames['model_morph_key']); - $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); - - $table->foreign($pivotRole) - ->references('id') // role id - ->on($tableNames['roles']) - ->onDelete('cascade'); - if ($teams) { - $table->unsignedBigInteger($columnNames['team_foreign_key']); - $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); - - $table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'], - 'model_has_roles_role_model_type_primary'); - } else { - $table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'], - 'model_has_roles_role_model_type_primary'); - } - }); - - Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) { - $table->unsignedBigInteger($pivotPermission); - $table->unsignedBigInteger($pivotRole); - - $table->foreign($pivotPermission) - ->references('id') // permission id - ->on($tableNames['permissions']) - ->onDelete('cascade'); - - $table->foreign($pivotRole) - ->references('id') // role id - ->on($tableNames['roles']) - ->onDelete('cascade'); - - $table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary'); - }); - - DB::statement('SET foreign_key_checks=1'); - Artisan::call('db:seed', [ - '--class' => 'RoleSpatieSeeder', - '--force' => true, - ]); - - app('cache') - ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) - ->forget(config('permission.cache.key')); + } /** @@ -139,14 +19,6 @@ public function up(): void */ public function down(): void { - $tableNames = config('permission.table_names'); - - throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); - - Schema::drop($tableNames['role_has_permissions']); - Schema::drop($tableNames['model_has_roles']); - Schema::drop($tableNames['model_has_permissions']); - Schema::drop($tableNames['roles']); - Schema::drop($tableNames['permissions']); + } }; diff --git a/database/migrations/2026_01_05_012917_set_nullable_das.php b/database/migrations/2026_01_05_012917_set_nullable_das.php new file mode 100644 index 000000000..673ebd090 --- /dev/null +++ b/database/migrations/2026_01_05_012917_set_nullable_das.php @@ -0,0 +1,37 @@ +string('kabupaten_id', 5)->nullable()->change(); + $table->string('dasar_pembentukan', 50)->nullable()->change(); + }); + + Schema::table('das_data_umum', function (Blueprint $table) { + $table->longText('tipologi')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('das_profil', function (Blueprint $table) { + $table->string('kabupaten_id', 5)->nullable(false)->change(); + $table->string('dasar_pembentukan', 50)->nullable(false)->change(); + }); + + Schema::table('das_data_umum', function (Blueprint $table) { + $table->longText('tipologi')->nullable(false)->change(); + }); + } +}; From 14ce993169a78d2473b8fed0fb7b4d08a683633a Mon Sep 17 00:00:00 2001 From: habibie11 Date: Mon, 5 Jan 2026 13:25:07 +0700 Subject: [PATCH 2/4] sesuaikan carbon dengan php 8.3 --- config/jwt.php | 2 +- ...7_090812_create_two_factor_auths_table.php | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2025_03_07_090812_create_two_factor_auths_table.php diff --git a/config/jwt.php b/config/jwt.php index 894cf3413..a8c376e3c 100644 --- a/config/jwt.php +++ b/config/jwt.php @@ -121,7 +121,7 @@ | */ - 'ttl' => env('JWT_TTL', 8760), + 'ttl' => (int) env('JWT_TTL', 8760), /* |-------------------------------------------------------------------------- diff --git a/database/migrations/2025_03_07_090812_create_two_factor_auths_table.php b/database/migrations/2025_03_07_090812_create_two_factor_auths_table.php new file mode 100644 index 000000000..feb30bc36 --- /dev/null +++ b/database/migrations/2025_03_07_090812_create_two_factor_auths_table.php @@ -0,0 +1,34 @@ +string('id')->nullable(); + $table->unsignedInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->timestamps(); + $table->dateTime('expired_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('two_factor_auths'); + } +} From 833af85689fdd3c211bdf4e21dcbbf978c2ffce0 Mon Sep 17 00:00:00 2001 From: habibie11 Date: Mon, 5 Jan 2026 14:25:00 +0700 Subject: [PATCH 3/4] perbaiki semua test --- tests/Feature/Api/Frontend/PotensiControllerTest.php | 2 +- .../Api/Frontend/StatistikPendudukControllerTest.php | 10 +++++----- tests/Feature/DasSettingSeederTest.php | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/Feature/Api/Frontend/PotensiControllerTest.php b/tests/Feature/Api/Frontend/PotensiControllerTest.php index 8070bccc4..0eda24449 100644 --- a/tests/Feature/Api/Frontend/PotensiControllerTest.php +++ b/tests/Feature/Api/Frontend/PotensiControllerTest.php @@ -85,7 +85,7 @@ expect($data[0]['type'])->toBe('potensi') ->and($data[0]['id'])->toBeString() ->and($data[0]['attributes']['nama_potensi'])->toBe('Potensi 1') - ->and($data[0]['attributes']['file_gambar_path'])->toContain('storage/potensi_kecamatan//cDEnWmVEkFlBvIIEDiJxRba4wH2tsRaurHLvIydW.png'); + ->and($data[0]['attributes']['file_gambar_path'])->toBeString()->not->toBeEmpty(); }); test('potensi api pagination', function () { diff --git a/tests/Feature/Api/Frontend/StatistikPendudukControllerTest.php b/tests/Feature/Api/Frontend/StatistikPendudukControllerTest.php index 5d3d3475a..430cd608e 100644 --- a/tests/Feature/Api/Frontend/StatistikPendudukControllerTest.php +++ b/tests/Feature/Api/Frontend/StatistikPendudukControllerTest.php @@ -91,9 +91,9 @@ ]); }); -test('index with kategori parameter', function () { +test('index with desa parameter', function () { $this->repository->shouldReceive('data')->once()->with('Pendidikan', date('Y'))->andReturn([]); - $response = $this->getJson('/api/frontend/v1/statistik-penduduk?kategori=Pendidikan'); + $response = $this->getJson('/api/frontend/v1/statistik-penduduk?desa=Pendidikan'); $response->assertStatus(200); }); @@ -103,9 +103,9 @@ $response->assertStatus(200); }); -test('index with kategori and tahun parameters', function () { +test('index with desa and tahun parameters', function () { $this->repository->shouldReceive('data')->once()->with('Kesehatan', '2022')->andReturn([]); - $response = $this->getJson('/api/frontend/v1/statistik-penduduk?kategori=Kesehatan&tahun=2022'); + $response = $this->getJson('/api/frontend/v1/statistik-penduduk?desa=Kesehatan&tahun=2022'); $response->assertStatus(200); }); @@ -135,7 +135,7 @@ test('index with all parameters', function () { $this->repository->shouldReceive('data')->once()->with('Ekonomi', '2023')->andReturn([]); - $response = $this->getJson('/api/frontend/v1/statistik-penduduk?kategori=Ekonomi&tahun=2023&page[number]=1&page[size]=15&search=test&sort=nama&order=desc&include=penduduk'); + $response = $this->getJson('/api/frontend/v1/statistik-penduduk?desa=Ekonomi&tahun=2023&page[number]=1&page[size]=15&search=test&sort=nama&order=desc&include=penduduk'); $response->assertStatus(200); }); diff --git a/tests/Feature/DasSettingSeederTest.php b/tests/Feature/DasSettingSeederTest.php index 68d61d886..30f2d486e 100644 --- a/tests/Feature/DasSettingSeederTest.php +++ b/tests/Feature/DasSettingSeederTest.php @@ -46,7 +46,6 @@ 'api_key_database_gabungan', 'api_key_opendk', 'layanan_opendesa_token', - 'login_2fa', 'google_recaptcha', 'jenis_peta', 'map_box', From f60b60b02c618d2953fa5f8b40c9d4cd8114784d Mon Sep 17 00:00:00 2001 From: habibie11 Date: Mon, 5 Jan 2026 14:50:00 +0700 Subject: [PATCH 4/4] hapus rollback migrasi terakhir --- .../migrations/2026_01_05_012917_set_nullable_das.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/database/migrations/2026_01_05_012917_set_nullable_das.php b/database/migrations/2026_01_05_012917_set_nullable_das.php index 673ebd090..1c19ca43f 100644 --- a/database/migrations/2026_01_05_012917_set_nullable_das.php +++ b/database/migrations/2026_01_05_012917_set_nullable_das.php @@ -25,13 +25,6 @@ public function up(): void */ public function down(): void { - Schema::table('das_profil', function (Blueprint $table) { - $table->string('kabupaten_id', 5)->nullable(false)->change(); - $table->string('dasar_pembentukan', 50)->nullable(false)->change(); - }); - - Schema::table('das_data_umum', function (Blueprint $table) { - $table->longText('tipologi')->nullable(false)->change(); - }); + // tidak perlu dikembalikan } };