pelican-panel-banquise/database/migrations/2024_03_14_055537_remove_locations_table.php
Boy132 d555c42644
Update all dependencies (#712)
* update composer.lock

* run pint

* fix phpstan

* update migrations (sqlite `dropForeign`)

* fix migrations

* Reset these back for now

* Alphabetize the rules

* run `php artisan filament:upgrade`

---------

Co-authored-by: Lance Pioch <git@lance.sh>
2024-11-22 09:27:57 +01:00

61 lines
1.8 KiB
PHP

<?php
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::table('nodes', function (Blueprint $table) {
$table->text('tags');
});
DB::table('nodes')->update(['tags' => '[]']);
$nodesWithLocations = DB::table('nodes')
->select(['nodes.id', 'locations.short'])
->join('locations', 'locations.id', '=', 'nodes.location_id')
->get();
foreach ($nodesWithLocations as $node) {
DB::table('nodes')
->where('id', $node->id)
->update(['tags' => "[\"$node->short\"]"]);
}
Schema::table('nodes', function (Blueprint $table) {
$table->dropForeign(['location_id']);
$table->dropColumn('location_id');
});
Schema::drop('locations');
Schema::table('api_keys', function (Blueprint $table) {
$table->dropColumn('r_locations');
});
}
// Not really reversible, but...
public function down(): void
{
Schema::create('locations', function (Blueprint $table) {
$table->increments('id');
$table->string('short');
$table->text('long')->nullable();
$table->timestamps();
});
Schema::table('nodes', function (Blueprint $table) {
$table->unsignedInteger('location_id')->default(0);
$table->foreign('location_id')->references('id')->on('locations');
});
Schema::table('api_keys', function (Blueprint $table) {
$table->unsignedTinyInteger('r_locations')->default(0);
});
}
};