feat(editorial): preserve public portfolio fiches during private review
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use App\Support\IsolatedQaDatabase;
|
||||
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
|
||||
{
|
||||
if (! IsolatedQaDatabase::allowsSchemaChanges()) {
|
||||
throw new RuntimeException('Only isolated QA is authorised.');
|
||||
}
|
||||
Schema::table('portal_editorial_editions', function (Blueprint $t): void {
|
||||
$t->unsignedBigInteger('resource_id')->nullable()->change();
|
||||
$t->foreignUuid('dossier_id')->nullable()->constrained('investment_dossiers')->restrictOnDelete();
|
||||
$t->unique(['dossier_id', 'revision_no']);
|
||||
});
|
||||
DB::statement('ALTER TABLE portal_editorial_editions ADD CONSTRAINT portal_editorial_edition_subject CHECK (num_nonnulls(resource_id,dossier_id)=1)');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! IsolatedQaDatabase::allowsSchemaChanges() || DB::table('portal_editorial_editions')->whereNotNull('dossier_id')->exists()) {
|
||||
throw new RuntimeException('Preserve portfolio editorial history.');
|
||||
}
|
||||
DB::statement('ALTER TABLE portal_editorial_editions DROP CONSTRAINT portal_editorial_edition_subject');
|
||||
Schema::table('portal_editorial_editions', function (Blueprint $t): void {
|
||||
$t->dropUnique(['dossier_id', 'revision_no']);
|
||||
$t->dropForeign(['dossier_id']);
|
||||
$t->dropColumn('dossier_id');
|
||||
$t->unsignedBigInteger('resource_id')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user