feat(editorial): preserve public editions and add QA review workflow
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?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('This first-stage migration is authorised only in isolated QA.');
|
||||
}
|
||||
Schema::create('portal_editorial_editions', function (Blueprint $t): void {
|
||||
$t->uuid('id')->primary();
|
||||
$t->foreignId('resource_id')->constrained('portal_resources')->restrictOnDelete();
|
||||
$t->unsignedInteger('revision_no');
|
||||
$t->unsignedInteger('version')->default(1);
|
||||
$t->string('state', 24)->default('draft');
|
||||
$t->jsonb('payload');
|
||||
$t->char('content_hash', 64);
|
||||
$t->foreignId('author_id')->constrained('users')->restrictOnDelete();
|
||||
$t->foreignId('assigned_to')->nullable()->constrained('users')->restrictOnDelete();
|
||||
$t->boolean('legal_required')->default(false);
|
||||
$t->jsonb('approval')->nullable();
|
||||
$t->jsonb('legal_validation')->nullable();
|
||||
$t->timestampTz('published_at')->nullable();
|
||||
$t->timestampsTz();
|
||||
$t->unique(['resource_id', 'revision_no']);
|
||||
$t->index(['state', 'assigned_to']);
|
||||
});
|
||||
Schema::create('portal_editorial_notifications', function (Blueprint $t): void {
|
||||
$t->id();
|
||||
$t->uuid('edition_id');
|
||||
$t->foreign('edition_id')->references('id')->on('portal_editorial_editions')->restrictOnDelete();
|
||||
$t->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
||||
$t->string('action', 40);
|
||||
$t->timestampTz('read_at')->nullable();
|
||||
$t->timestampTz('created_at');
|
||||
$t->index(['user_id', 'read_at']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! IsolatedQaDatabase::allowsSchemaChanges() || DB::table('portal_editorial_editions')->exists() || DB::table('portal_editorial_notifications')->exists()) {
|
||||
throw new RuntimeException('Preserve editions, decisions and history.');
|
||||
}
|
||||
Schema::dropIfExists('portal_editorial_notifications');
|
||||
Schema::dropIfExists('portal_editorial_editions');
|
||||
}
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?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_notifications', function (Blueprint $t): void {
|
||||
$t->uuid('edition_id')->nullable()->change();
|
||||
$t->foreignId('opportunity_id')->nullable()->constrained('opportunities')->restrictOnDelete();
|
||||
$t->unsignedInteger('opportunity_version')->nullable();
|
||||
$t->char('content_hash', 64)->nullable();
|
||||
$t->unique(['user_id', 'opportunity_id', 'opportunity_version', 'action'], 'portal_editorial_op_notice_uq');
|
||||
});
|
||||
DB::statement('ALTER TABLE portal_editorial_notifications ADD CONSTRAINT portal_editorial_notice_subject CHECK ((edition_id IS NOT NULL AND opportunity_id IS NULL) OR (edition_id IS NULL AND opportunity_id IS NOT NULL AND opportunity_version IS NOT NULL))');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! IsolatedQaDatabase::allowsSchemaChanges() || DB::table('portal_editorial_notifications')->whereNotNull('opportunity_id')->exists()) {
|
||||
throw new RuntimeException('Preserve opportunity notification history.');
|
||||
}
|
||||
DB::statement('ALTER TABLE portal_editorial_notifications DROP CONSTRAINT portal_editorial_notice_subject');
|
||||
Schema::table('portal_editorial_notifications', function (Blueprint $t): void {
|
||||
$t->dropUnique('portal_editorial_op_notice_uq');
|
||||
$t->dropForeign(['opportunity_id']);
|
||||
$t->dropColumn(['opportunity_id', 'opportunity_version', 'content_hash']);
|
||||
$t->uuid('edition_id')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user