pelican-panel-banquise/database/migrations/2024_03_12_154408_remove_nests_table.php
Lance Pioch 8261184b57
Officially support PostgreSQL database (#1066)
* Just skip this table because it no longer exists

* Add postgresql

* This no longer needs to be there

* These are the same output in mysql, but different in postgresql

* Fix these migrations for postgresql

* This table no longer exists

* This is expected to be a json column for json operations, required for postgresql

* Shoot for the stars

* Fix pint

* Why was this missing

* Updates

* Restore this

* This needs to be explicit

* Don’t like strings

* Fix these classes

* Use different method to compare dates

* Apparently postgresql doesn’t like case insensitivity

* Postgresql orders it backwards

* Ordered different by postgresql

* Unnecessary and breaking

* Make sure the order is correct for postresql

* Fix this with the order too

* Remove this

* Force email to be lowercased

* Update app/Models/User.php
2025-03-30 14:44:03 -04:00

86 lines
2.6 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('eggs', function (Blueprint $table) {
$table->text('tags');
});
DB::table('eggs')->update(['tags' => '[]']);
$eggsWithNests = DB::table('eggs')
->select(['eggs.id', 'nests.name'])
->join('nests', 'nests.id', '=', 'eggs.nest_id')
->get();
foreach ($eggsWithNests as $egg) {
DB::table('eggs')
->where('id', $egg->id)
->update(['tags' => "[\"$egg->name\"]"]);
}
Schema::table('eggs', function (Blueprint $table) {
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('service_options_nest_id_foreign');
} else {
$table->dropForeign(['nest_id']);
}
$table->dropColumn('nest_id');
});
Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['nest_id']);
$table->dropColumn('nest_id');
});
Schema::drop('nests');
Schema::table('api_keys', function (Blueprint $table) {
$table->dropColumn('r_nests');
});
}
// Not really reversible, but...
public function down(): void
{
Schema::table('api_keys', function (Blueprint $table) {
$table->unsignedTinyInteger('r_nests')->default(0);
});
Schema::create('nests', function (Blueprint $table) {
$table->increments('id');
$table->string('uuid', 36)->unique();
$table->string('author');
$table->string('name');
$table->text('description')->nullable();
$table->timestamps();
});
Schema::table('eggs', function (Blueprint $table) {
$table->dropColumn('tags');
$table->mediumInteger('nest_id')->unsigned();
$table->foreign(['nest_id'], 'service_options_nest_id_foreign');
});
Schema::table('servers', function (Blueprint $table) {
$table->mediumInteger('nest_id')->unsigned();
$table->foreign(['nest_id'], 'servers_nest_id_foreign');
});
if (class_exists('Database\Seeders\NestSeeder')) {
Artisan::call('db:seed', [
'--class' => 'NestSeeder',
]);
}
}
};