Deliver additive INE demography and authenticated homologation installation
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use App\Services\DemographicInstallation;
|
||||
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 (! app(DemographicInstallation::class)->schemaAllowed()) {
|
||||
throw new RuntimeException('Demografia: instalação exige QA isolado ou a acção autenticada autorizada.');
|
||||
}
|
||||
Schema::create('demographic_imports', function (Blueprint $t) {
|
||||
$t->uuid('id')->primary();
|
||||
$t->char('sha256', 64)->unique();
|
||||
$t->string('file_name');
|
||||
$t->string('source');
|
||||
$t->string('publication_version');
|
||||
$t->string('status')->default('prepared');
|
||||
$t->jsonb('report');
|
||||
$t->char('preview_sha256', 64);
|
||||
$t->foreignId('prepared_by')->constrained('users')->restrictOnDelete();
|
||||
$t->timestampsTz();
|
||||
});
|
||||
Schema::create('demographic_observations', function (Blueprint $t) {
|
||||
$t->bigIncrements('id');
|
||||
$t->foreignUuid('import_id')->constrained('demographic_imports')->restrictOnDelete();
|
||||
$t->foreignUuid('geo_location_id')->constrained('geo_locations')->restrictOnDelete();
|
||||
$t->unsignedSmallInteger('year');
|
||||
$t->string('indicator', 80);
|
||||
$t->string('sex', 10);
|
||||
$t->string('residence', 10);
|
||||
$t->string('age_group', 30);
|
||||
$t->string('unit', 80);
|
||||
$t->string('data_kind', 20);
|
||||
$t->string('original_value', 100);
|
||||
$t->text('numeric_value'); // Exact decimal text, including Excel storage precision.
|
||||
$t->string('sheet');
|
||||
$t->string('cell', 20);
|
||||
$t->string('validation_status', 20);
|
||||
$t->unique(['import_id', 'geo_location_id', 'year', 'indicator', 'sex', 'residence', 'age_group'], 'demography_dimension_unique');
|
||||
$t->index(['geo_location_id', 'year', 'indicator']);
|
||||
});
|
||||
Schema::create('demographic_events', function (Blueprint $t) {
|
||||
$t->bigIncrements('id');
|
||||
$t->foreignUuid('import_id')->constrained('demographic_imports')->restrictOnDelete();
|
||||
$t->foreignId('actor_id')->constrained('users')->restrictOnDelete();
|
||||
$t->string('action', 30);
|
||||
$t->text('reason');
|
||||
$t->jsonb('details');
|
||||
$t->timestampTz('created_at')->useCurrent();
|
||||
});
|
||||
DB::statement("ALTER TABLE demographic_imports ADD CONSTRAINT demographic_import_state CHECK (status IN ('prepared','imported','approved','disabled'))");
|
||||
DB::statement("ALTER TABLE demographic_observations ADD CONSTRAINT demographic_observation_state CHECK (validation_status IN ('valid','warning'))");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! IsolatedQaDatabase::allowsSchemaChanges() || DB::table('demographic_imports')->exists()) {
|
||||
throw new RuntimeException('Preserve originais e histórico demográfico antes de reverter.');
|
||||
}
|
||||
Schema::dropIfExists('demographic_events');
|
||||
Schema::dropIfExists('demographic_observations');
|
||||
Schema::dropIfExists('demographic_imports');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user