commit16
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?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('investment_notifications', function (Blueprint $table) {
|
||||
$table->uuid('submission_id')->nullable()->change();
|
||||
$table->foreignId('opportunity_id')->nullable()->constrained('opportunities')->restrictOnDelete();
|
||||
});
|
||||
DB::statement('ALTER TABLE investment_notifications ADD CONSTRAINT investment_notification_origin CHECK ((submission_id IS NOT NULL)::integer + (opportunity_id IS NOT NULL)::integer = 1)');
|
||||
Schema::create('investment_alert_preferences', function (Blueprint $table) {
|
||||
$table->uuid('id')->unique();
|
||||
$table->foreignId('user_id')->primary()->constrained('users')->restrictOnDelete();
|
||||
$table->unsignedInteger('version');
|
||||
$table->boolean('enabled')->default(false);
|
||||
$table->string('frequency');
|
||||
$table->string('channel')->default('in_app');
|
||||
$table->text('criteria');
|
||||
$table->timestampTz('consented_at')->nullable();
|
||||
$table->timestampTz('next_run_at')->nullable();
|
||||
$table->timestampsTz();
|
||||
$table->index(['enabled', 'next_run_at']);
|
||||
});
|
||||
DB::statement("ALTER TABLE investment_alert_preferences ADD CHECK (frequency IN ('as_available','daily','weekly')), ADD CHECK (channel = 'in_app'), ADD CHECK (NOT enabled OR consented_at IS NOT NULL)");
|
||||
Schema::create('investment_alert_seen', function (Blueprint $table) {
|
||||
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignId('opportunity_id')->constrained('opportunities')->restrictOnDelete();
|
||||
$table->foreignUuid('notification_id')->nullable()->constrained('investment_notifications')->restrictOnDelete();
|
||||
$table->timestampTz('observed_at')->useCurrent();
|
||||
$table->primary(['user_id', 'opportunity_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (DB::table('investment_alert_preferences')->exists() || DB::table('investment_alert_seen')->exists()
|
||||
|| DB::table('investment_notifications')->whereNotNull('opportunity_id')->exists()) {
|
||||
throw new RuntimeException('Preserve alert preferences and notification history before rollback.');
|
||||
}
|
||||
Schema::drop('investment_alert_seen');
|
||||
Schema::drop('investment_alert_preferences');
|
||||
DB::statement('ALTER TABLE investment_notifications DROP CONSTRAINT investment_notification_origin');
|
||||
Schema::table('investment_notifications', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('opportunity_id');
|
||||
$table->uuid('submission_id')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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('investment_alert_preferences', function (Blueprint $table) {
|
||||
$table->jsonb('sources')->default('["opportunities"]');
|
||||
});
|
||||
DB::statement("ALTER TABLE investment_alert_preferences ADD CONSTRAINT investment_alert_sources CHECK (jsonb_typeof(sources)='array' AND jsonb_array_length(sources) BETWEEN 1 AND 2 AND sources <@ '[\"opportunities\",\"tenders\"]'::jsonb)");
|
||||
Schema::table('investment_notifications', function (Blueprint $table) {
|
||||
$table->foreignUuid('tender_version_id')->nullable()->constrained('portal_tender_versions')->restrictOnDelete();
|
||||
});
|
||||
DB::statement('ALTER TABLE investment_notifications DROP CONSTRAINT investment_notification_origin');
|
||||
DB::statement('ALTER TABLE investment_notifications ADD CONSTRAINT investment_notification_origin CHECK ((submission_id IS NOT NULL)::integer + (opportunity_id IS NOT NULL)::integer + (tender_version_id IS NOT NULL)::integer = 1)');
|
||||
Schema::create('investment_tender_alert_seen', function (Blueprint $table) {
|
||||
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignUuid('tender_version_id')->constrained('portal_tender_versions')->restrictOnDelete();
|
||||
$table->foreignUuid('notification_id')->nullable()->constrained('investment_notifications')->restrictOnDelete();
|
||||
$table->timestampTz('observed_at')->useCurrent();
|
||||
$table->primary(['user_id', 'tender_version_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (DB::table('investment_tender_alert_seen')->exists() || DB::table('investment_notifications')->whereNotNull('tender_version_id')->exists()
|
||||
|| DB::table('investment_alert_preferences')->whereJsonContains('sources', 'tenders')->exists()) {
|
||||
throw new RuntimeException('Preserve tender alert preferences and notification history before rollback.');
|
||||
}
|
||||
Schema::drop('investment_tender_alert_seen');
|
||||
DB::statement('ALTER TABLE investment_notifications DROP CONSTRAINT investment_notification_origin');
|
||||
Schema::table('investment_notifications', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('tender_version_id');
|
||||
});
|
||||
DB::statement('ALTER TABLE investment_notifications ADD CONSTRAINT investment_notification_origin CHECK ((submission_id IS NOT NULL)::integer + (opportunity_id IS NOT NULL)::integer = 1)');
|
||||
DB::statement('ALTER TABLE investment_alert_preferences DROP CONSTRAINT investment_alert_sources');
|
||||
Schema::table('investment_alert_preferences', function (Blueprint $table) {
|
||||
$table->dropColumn('sources');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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::create('funding_programmes', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('code', 80)->unique();
|
||||
$table->unsignedInteger('version')->default(1);
|
||||
$table->jsonb('draft');
|
||||
$table->uuid('published_version_id')->nullable();
|
||||
$table->foreignId('created_by')->constrained('users')->restrictOnDelete();
|
||||
$table->timestampsTz();
|
||||
});
|
||||
Schema::create('funding_programme_versions', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('programme_id')->constrained('funding_programmes')->restrictOnDelete();
|
||||
$table->unsignedInteger('version');
|
||||
$table->jsonb('payload');
|
||||
$table->text('reason');
|
||||
$table->foreignId('actor_id')->constrained('users')->restrictOnDelete();
|
||||
$table->timestampTz('published_at')->useCurrent();
|
||||
$table->unique(['programme_id', 'version']);
|
||||
});
|
||||
Schema::create('funding_programme_interests', function (Blueprint $table) {
|
||||
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignUuid('programme_id')->constrained('funding_programmes')->restrictOnDelete();
|
||||
$table->foreignUuid('version_id')->constrained('funding_programme_versions')->restrictOnDelete();
|
||||
$table->timestampTz('saved_at')->useCurrent();
|
||||
$table->timestampTz('removed_at')->nullable();
|
||||
$table->primary(['user_id', 'programme_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (DB::table('funding_programmes')->exists() || DB::table('funding_programme_versions')->exists() || DB::table('funding_programme_interests')->exists()) {
|
||||
throw new RuntimeException('Preserve funding programmes, published versions and saved interests before rollback.');
|
||||
}
|
||||
Schema::drop('funding_programme_interests');
|
||||
Schema::drop('funding_programme_versions');
|
||||
Schema::drop('funding_programmes');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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
|
||||
{
|
||||
DB::statement('ALTER TABLE investment_alert_preferences DROP CONSTRAINT investment_alert_sources');
|
||||
DB::statement("ALTER TABLE investment_alert_preferences ADD CONSTRAINT investment_alert_sources CHECK (jsonb_typeof(sources)='array' AND jsonb_array_length(sources) BETWEEN 1 AND 3 AND sources <@ '[\"opportunities\",\"tenders\",\"funding\"]'::jsonb)");
|
||||
Schema::table('investment_notifications', function (Blueprint $table) {
|
||||
$table->foreignUuid('funding_version_id')->nullable()->constrained('funding_programme_versions')->restrictOnDelete();
|
||||
});
|
||||
DB::statement('ALTER TABLE investment_notifications DROP CONSTRAINT investment_notification_origin');
|
||||
DB::statement('ALTER TABLE investment_notifications ADD CONSTRAINT investment_notification_origin CHECK ((submission_id IS NOT NULL)::integer + (opportunity_id IS NOT NULL)::integer + (tender_version_id IS NOT NULL)::integer + (funding_version_id IS NOT NULL)::integer = 1)');
|
||||
Schema::create('investment_funding_alert_seen', function (Blueprint $table) {
|
||||
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignUuid('funding_version_id')->constrained('funding_programme_versions')->restrictOnDelete();
|
||||
$table->foreignUuid('notification_id')->nullable()->constrained('investment_notifications')->restrictOnDelete();
|
||||
$table->timestampTz('observed_at')->useCurrent();
|
||||
$table->primary(['user_id', 'funding_version_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (DB::table('investment_funding_alert_seen')->exists() || DB::table('investment_notifications')->whereNotNull('funding_version_id')->exists()
|
||||
|| DB::table('investment_alert_preferences')->whereJsonContains('sources', 'funding')->exists()) {
|
||||
throw new RuntimeException('Preserve funding alert preferences and notification history before rollback.');
|
||||
}
|
||||
Schema::drop('investment_funding_alert_seen');
|
||||
DB::statement('ALTER TABLE investment_notifications DROP CONSTRAINT investment_notification_origin');
|
||||
Schema::table('investment_notifications', fn (Blueprint $table) => $table->dropConstrainedForeignId('funding_version_id'));
|
||||
DB::statement('ALTER TABLE investment_notifications ADD CONSTRAINT investment_notification_origin CHECK ((submission_id IS NOT NULL)::integer + (opportunity_id IS NOT NULL)::integer + (tender_version_id IS NOT NULL)::integer = 1)');
|
||||
DB::statement('ALTER TABLE investment_alert_preferences DROP CONSTRAINT investment_alert_sources');
|
||||
DB::statement("ALTER TABLE investment_alert_preferences ADD CONSTRAINT investment_alert_sources CHECK (jsonb_typeof(sources)='array' AND jsonb_array_length(sources) BETWEEN 1 AND 2 AND sources <@ '[\"opportunities\",\"tenders\"]'::jsonb)");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user