Files
Investidor-V2/database/migrations/2026_09_24_002000_investmoz_content.php
T
nala 250ac35fd1
tests / ci (push) Canceled after 0s
first commit
2026-09-28 10:01:09 +02:00

71 lines
2.4 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
// Laravel's migration ledger provides idempotency; object drift fails explicitly.
public function up(): void
{
if (DB::connection()->getDriverName() !== 'pgsql') {
throw new RuntimeException('InvestMoz requires PostgreSQL with PostGIS. Use the isolated pgsql test environment.');
}
DB::statement(<<<'SQL'
CREATE TABLE public.documents (
id uuid DEFAULT gen_random_uuid() NOT NULL,
source_system text NOT NULL DEFAULT 'investmoz',
external_id text,
version_no integer NOT NULL DEFAULT 1,
data_classification text NOT NULL DEFAULT 'internal',
correlation_id uuid,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz,
file_name text NOT NULL,
media_type text NOT NULL,
storage_key text NOT NULL,
sha256 char(64) NOT NULL,
status text NOT NULL,
CONSTRAINT imz_documents_pk PRIMARY KEY (id),
CONSTRAINT imz_documents_check_01 CHECK (version_no > 0),
CONSTRAINT imz_documents_check_02 CHECK (data_classification IN ('public','internal','confidential','restricted')),
CONSTRAINT imz_documents_check_03 CHECK (status IN ('active','quarantined','deleted')),
CONSTRAINT imz_documents_check_04 CHECK (sha256 ~ '^[0-9a-f]{64}$')
);
SQL);
}
public function down(): void
{
if (DB::connection()->getDriverName() !== 'pgsql') {
throw new RuntimeException('InvestMoz rollback requires PostgreSQL.');
}
DB::statement(<<<'SQL'
ALTER TABLE IF EXISTS public.documents DROP CONSTRAINT IF EXISTS imz_documents_pk RESTRICT;
SQL);
DB::statement(<<<'SQL'
ALTER TABLE IF EXISTS public.documents DROP CONSTRAINT IF EXISTS imz_documents_check_01 RESTRICT;
SQL);
DB::statement(<<<'SQL'
ALTER TABLE IF EXISTS public.documents DROP CONSTRAINT IF EXISTS imz_documents_check_02 RESTRICT;
SQL);
DB::statement(<<<'SQL'
ALTER TABLE IF EXISTS public.documents DROP CONSTRAINT IF EXISTS imz_documents_check_03 RESTRICT;
SQL);
DB::statement(<<<'SQL'
ALTER TABLE IF EXISTS public.documents DROP CONSTRAINT IF EXISTS imz_documents_check_04 RESTRICT;
SQL);
DB::statement(<<<'SQL'
DROP TABLE IF EXISTS public.documents RESTRICT;
SQL);
}
};