1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-23 00:05:29 +00:00

Add postgres migration

This commit is contained in:
Daniel Supernault 2023-05-02 20:55:45 -06:00
parent 670b3ba868
commit 79b6a17e44
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$type = config('database.default');
if($type === 'pgsql') {
DB::statement("ALTER TABLE statuses DROP CONSTRAINT statuses_visibility_check");
$types = ['public', 'unlisted', 'private', 'direct', 'draft'];
$result = join( ', ', array_map(function ($value){
return sprintf("'%s'::character varying", $value);
}, $types));
DB::statement("ALTER TABLE statuses ADD CONSTRAINT statuses_visibility_check CHECK (visibility::text = ANY (ARRAY[$result]::text[]))");
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};