Rombak Database

This commit is contained in:
Stephen Gesityan 2025-05-08 17:44:24 +07:00
parent 4e1dfd6f24
commit 49d4a07895
6 changed files with 145 additions and 61 deletions

View File

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
// Hanya menambahkan kolom venue_id dengan foreign key
$table->unsignedBigInteger('venue_id')->nullable()->after('role');
$table->foreign('venue_id')->references('id')->on('venues')->onDelete('set null');
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
// Menghapus foreign key dan kolom venue_id
if (Schema::hasColumn('users', 'venue_id')) {
$table->dropForeign(['venue_id']); // Menghapus foreign key constraint
$table->dropColumn('venue_id'); // Menghapus kolom venue_id
}
});
}
};

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
if (!Schema::hasColumn('users', 'role')) {
$table->string('role')->default('user');
}
if (!Schema::hasColumn('users', 'venue_id')) {
$table->foreignId('venue_id')->nullable()->constrained('venues')->onDelete('set null');
}
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['venue_id']);
$table->dropColumn(['role', 'venue_id']);
});
}
};

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('venues', function (Blueprint $table) {
$table->string('phone');
$table->text('description');
$table->time('open_time');
$table->time('close_time');
$table->dropColumn(['location', 'price']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('venues', function (Blueprint $table) {
$table->dropColumn(['phone', 'description', 'open_time', 'close_time']);
$table->string('location');
$table->integer('price');
});
}
};

View File

@ -18,5 +18,10 @@ public function run(): void
// 'name' => 'Test User',
// 'email' => 'test@example.com',
// ]);
$this->call([
VenueSeeder::class,
UsersTableSeeder::class
]);
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Create admin user
User::create([
'name' => 'Admin',
'email' => 'admin@admin.com',
'password' => Hash::make('password'),
'role' => 'admin',
'venue_id' => 1 // Connect to the first venue
]);
// Create regular user
User::create([
'name' => 'User',
'email' => 'user@user.com',
'password' => Hash::make('password'),
'role' => 'user'
]);
}
}

View File

@ -14,50 +14,56 @@ public function run(): void
$venues = [
'capitano' => [
'name' => 'Capitano Billiard',
'location' => 'Genteng',
'address' => 'Jl. Hasanudin No.II, Dusun Krajan, Genteng Wetan, Kec. Genteng, Kabupaten Banyuwangi',
'price' => 100000,
'phone' => '08123456789',
'description' => 'Tempat billiard terbaik di Genteng',
'open_time' => '09:00',
'close_time' => '23:00',
'image' => 'images/billiard2.jpg',
'tables' => [
['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available'],
['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked'],
['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available'],
['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Available'],
['name' => 'Table 5', 'brand' => 'A Plus Premier', 'status' => 'Booked'],
['name' => 'Table 6', 'brand' => 'A Plus Premier', 'status' => 'Booked'],
['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available', 'price_per_hour' => 50000],
['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked', 'price_per_hour' => 50000],
['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available', 'price_per_hour' => 50000],
['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Available', 'price_per_hour' => 50000],
['name' => 'Table 5', 'brand' => 'A Plus Premier', 'status' => 'Booked', 'price_per_hour' => 60000],
['name' => 'Table 6', 'brand' => 'A Plus Premier', 'status' => 'Booked', 'price_per_hour' => 60000],
],
],
'osing' => [
'name' => 'Osing Billiard Center',
'location' => 'Lidah',
'address' => 'Dusun Krajan, Kalirejo, Kec. Kabat, Kabupaten Banyuwangi',
'price' => 90000,
'phone' => '08123456790',
'description' => 'Tempat billiard terbaik di Kabat',
'open_time' => '09:00',
'close_time' => '23:00',
'image' => 'images/billiard3.jpg',
'tables' => [
['name' => 'Table 1', 'brand' => 'Xingjue', 'status' => 'Booked'],
['name' => 'Table 2', 'brand' => 'Xingjue', 'status' => 'Booked'],
['name' => 'Table 3', 'brand' => 'Xingjue', 'status' => 'Available'],
['name' => 'Table 4', 'brand' => 'Xingjue', 'status' => 'Available'],
['name' => 'Table 5', 'brand' => 'Xingjue', 'status' => 'Booked'],
['name' => 'Table 6', 'brand' => 'Xingjue', 'status' => 'Available'],
['name' => 'Table 7', 'brand' => 'Xingjue', 'status' => 'Available'],
['name' => 'Table 1', 'brand' => 'Xingjue', 'status' => 'Booked', 'price_per_hour' => 45000],
['name' => 'Table 2', 'brand' => 'Xingjue', 'status' => 'Booked', 'price_per_hour' => 45000],
['name' => 'Table 3', 'brand' => 'Xingjue', 'status' => 'Available', 'price_per_hour' => 45000],
['name' => 'Table 4', 'brand' => 'Xingjue', 'status' => 'Available', 'price_per_hour' => 45000],
['name' => 'Table 5', 'brand' => 'Xingjue', 'status' => 'Booked', 'price_per_hour' => 45000],
['name' => 'Table 6', 'brand' => 'Xingjue', 'status' => 'Available', 'price_per_hour' => 45000],
['name' => 'Table 7', 'brand' => 'Xingjue', 'status' => 'Available', 'price_per_hour' => 45000],
],
],
'das' => [
'name' => 'DAS Game & Billiard',
'location' => 'Jalen',
'address' => 'Jl. Samiran, Jalen Parungan, Setail, Kec. Genteng, Kabupaten Banyuwangi',
'price' => 95000,
'phone' => '08123456791',
'description' => 'Tempat billiard terbaik di Genteng',
'open_time' => '09:00',
'close_time' => '23:00',
'image' => 'images/billiard4.jpg',
'tables' => [
['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available'],
['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked'],
['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available'],
['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Booked'],
['name' => 'Table 5', 'brand' => 'Cosmic', 'status' => 'Booked'],
['name' => 'Table 6', 'brand' => 'Cosmic', 'status' => 'Available'],
['name' => 'Table 7', 'brand' => 'Cosmic', 'status' => 'Available'],
['name' => 'Table 8', 'brand' => 'Cosmic', 'status' => 'Booked'],
['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available', 'price_per_hour' => 47500],
['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked', 'price_per_hour' => 47500],
['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available', 'price_per_hour' => 47500],
['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Booked', 'price_per_hour' => 47500],
['name' => 'Table 5', 'brand' => 'Cosmic', 'status' => 'Booked', 'price_per_hour' => 47500],
['name' => 'Table 6', 'brand' => 'Cosmic', 'status' => 'Available', 'price_per_hour' => 47500],
['name' => 'Table 7', 'brand' => 'Cosmic', 'status' => 'Available', 'price_per_hour' => 47500],
['name' => 'Table 8', 'brand' => 'Cosmic', 'status' => 'Booked', 'price_per_hour' => 47500],
],
],
];
@ -66,15 +72,17 @@ public function run(): void
// Membuat venue baru
$venue = Venue::create([
'name' => $venueData['name'],
'location' => $venueData['location'],
'address' => $venueData['address'],
'price' => $venueData['price'],
'phone' => $venueData['phone'],
'description' => $venueData['description'],
'open_time' => $venueData['open_time'],
'close_time' => $venueData['close_time'],
'image' => $venueData['image'],
]);
// Menambahkan tabel untuk setiap venue
foreach ($venueData['tables'] as $tableData) {
$venue->tables()->create($tableData); // Menambahkan meja ke venue
$venue->tables()->create($tableData);
}
}
}