Room Migration: Adding rooms, creating dummy rooms for existing tours, adding room_ids to user bookings
This commit is contained in:
parent
6f6114c55c
commit
1a8a706b50
2 changed files with 248 additions and 1 deletions
|
|
@ -22,8 +22,30 @@ class CreateBookingRooms extends Migration
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::table('bookings', function (Blueprint $table) {
|
Schema::table('bookings', function (Blueprint $table) {
|
||||||
$table->integer('room_id');
|
$table->integer('room_id')->after('user_id');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 1.) Dummy Räume für jede Tour erstellen
|
||||||
|
$result=DB::select("SELECT DISTINCT tour_id FROM bookings;");
|
||||||
|
foreach ($result as $row) {
|
||||||
|
$sql="INSERT INTO booking_rooms(name,tour_id,capacity,created_at,updated_at) VALUES ('Dummy-Raum',".$row->tour_id.",100,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP);";
|
||||||
|
|
||||||
|
DB::insert($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.) room_id in bookings für jeden Teilnehmer nachtragen
|
||||||
|
$tours=DB::select("SELECT id from tours;");
|
||||||
|
foreach($tours as $tour) {
|
||||||
|
$tour_users=DB::select("SELECT user_id FROM bookings WHERE tour_id=".$tour->id.";");
|
||||||
|
$room=DB::select("SELECT id FROM booking_rooms WHERE tour_id=".$tour->id.";");
|
||||||
|
foreach($tour_users as $tour_user) {
|
||||||
|
$sql="UPDATE bookings SET room_id=".$room[0]->id." WHERE tour_id=".$tour->id." and user_id=".$tour_user->user_id.";";
|
||||||
|
print($sql."\n");
|
||||||
|
DB::update($sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
225
tools/motorradig_2022-05-01_141900.sql
Normal file
225
tools/motorradig_2022-05-01_141900.sql
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue