Repo rebuild

This commit is contained in:
Mark Gregory
2026-09-15 12:33:28 +01:00
commit be28c4feec
5629 changed files with 317074 additions and 0 deletions
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('countries', function (Blueprint $table): void {
$table->id();
$table->char('alpha2', 2)->unique()->comment('ISO 3166-1 alpha-2 country code.');
$table->char('alpha3', 3)->unique()->comment('ISO 3166-1 alpha-3 country code.');
$table->char('numeric', 3)->nullable()->unique()->comment('ISO 3166-1 numeric country code.');
$table->string('name')->comment('Canonical ISO country name.');
$table->string('official_name')->nullable()->comment('Official ISO country name where available.');
$table->string('common_name')->nullable()->comment('Common country name where available.');
$table->string('display_name')->nullable()->comment('Application-specific display name override.');
$table->string('flag_emoji', 16)->nullable()->comment('Regional indicator flag emoji derived from alpha-2 code.');
$table->boolean('is_active')->default(true)->index()->comment('Whether this country is available for selection in business workflows.');
$table->unsignedInteger('sort_order')->default(0)->index()->comment('Optional UI ordering override.');
$table->timestamp('last_synced_at')->nullable()->comment('Last time this row was synced from bundled ISO data.');
$table->timestamps();
$table->index(['is_active', 'sort_order', 'name']);
$table->index(['name']);
});
}
public function down(): void
{
Schema::dropIfExists('countries');
}
};
@@ -0,0 +1,85 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add ISO 3166 governance metadata and ISO 3166-2 subdivision support.
*/
public function up(): void
{
Schema::table('countries', function (Blueprint $table): void {
if (! Schema::hasColumn('countries', 'iso_status')) {
$table->string('iso_status', 32)->default('official')->index()->after('is_active')->comment('ISO 3166-1 lifecycle status: official, reserved, transitional, deleted, user_assigned, exceptionally_reserved.');
}
if (! Schema::hasColumn('countries', 'independent')) {
$table->boolean('independent')->nullable()->after('iso_status')->comment('Whether the ISO 3166-1 entry represents an independent state where known.');
}
if (! Schema::hasColumn('countries', 'region')) {
$table->string('region')->nullable()->index()->after('independent')->comment('UN M49-style broad region for filtering and reporting.');
}
if (! Schema::hasColumn('countries', 'subregion')) {
$table->string('subregion')->nullable()->index()->after('region')->comment('UN M49-style subregion for filtering and reporting.');
}
if (! Schema::hasColumn('countries', 'source')) {
$table->string('source')->nullable()->after('last_synced_at')->comment('Reference data source used for the last sync.');
}
if (! Schema::hasColumn('countries', 'source_version')) {
$table->string('source_version')->nullable()->after('source')->comment('Reference data version/release identifier.');
}
if (! Schema::hasColumn('countries', 'metadata')) {
$table->json('metadata')->nullable()->after('source_version')->comment('Additional non-authoritative metadata, never used as the primary ISO identity.');
}
});
if (! Schema::hasTable('country_subdivisions')) {
Schema::create('country_subdivisions', function (Blueprint $table): void {
$table->id();
$table->foreignId('country_id')->constrained('countries')->cascadeOnDelete();
$table->char('country_alpha2', 2)->index()->comment('Parent ISO 3166-1 alpha-2 code, duplicated for fast lookup and imports.');
$table->string('code', 16)->unique()->comment('Full ISO 3166-2 subdivision code, for example GB-ENG or US-CA.');
$table->string('subdivision_code', 12)->comment('Subdivision part after the country prefix, for example ENG or CA.');
$table->string('name')->comment('ISO 3166-2 subdivision name.');
$table->string('local_name')->nullable()->comment('Optional local-language display name.');
$table->string('type')->nullable()->index()->comment('Subdivision type, for example country, province, state, territory, council area.');
$table->boolean('is_active')->default(true)->index()->comment('Whether this subdivision is currently available in business workflows.');
$table->string('iso_status', 32)->default('official')->index()->comment('ISO 3166-2 lifecycle status.');
$table->unsignedInteger('sort_order')->default(0)->index();
$table->timestamp('last_synced_at')->nullable();
$table->string('source')->nullable();
$table->string('source_version')->nullable();
$table->json('metadata')->nullable();
$table->timestamps();
$table->unique(['country_id', 'subdivision_code']);
$table->index(['country_alpha2', 'is_active', 'sort_order', 'name']);
$table->index(['type', 'is_active']);
});
}
}
/**
* Reverse the ISO 3166 support additions.
*/
public function down(): void
{
Schema::dropIfExists('country_subdivisions');
Schema::table('countries', function (Blueprint $table): void {
foreach (['metadata', 'source_version', 'source', 'subregion', 'region', 'independent', 'iso_status'] as $column) {
if (Schema::hasColumn('countries', $column)) {
$table->dropColumn($column);
}
}
});
}
};
@@ -0,0 +1,144 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add enterprise ISO 3166 support fields used by platform administration,
* address validation, logistics, billing, carrier and compliance workflows.
*/
public function up(): void
{
Schema::table('countries', function (Blueprint $table): void {
$columns = Schema::getColumnListing('countries');
if (! in_array('native_name', $columns, true)) {
$table->string('native_name')->nullable()->after('display_name')->comment('Native/local country name where available.');
}
if (! in_array('capital', $columns, true)) {
$table->string('capital')->nullable()->after('native_name')->comment('Administrative capital city where applicable.');
}
if (! in_array('continent', $columns, true)) {
$table->string('continent', 64)->nullable()->index()->after('capital')->comment('Continent used for reporting and regional grouping.');
}
if (! in_array('intermediate_region', $columns, true)) {
$table->string('intermediate_region')->nullable()->index()->after('subregion')->comment('UN M49 intermediate region where applicable.');
}
if (! in_array('sovereignty_status', $columns, true)) {
$table->string('sovereignty_status', 64)->nullable()->index()->after('independent')->comment('Sovereignty or territory status.');
}
if (! in_array('un_member', $columns, true)) {
$table->boolean('un_member')->nullable()->index()->after('sovereignty_status')->comment('Whether the country is a United Nations member state.');
}
if (! in_array('calling_code', $columns, true)) {
$table->string('calling_code', 16)->nullable()->index()->after('flag_emoji')->comment('Primary international phone calling code, for example +44.');
}
if (! in_array('tld', $columns, true)) {
$table->string('tld', 16)->nullable()->index()->after('calling_code')->comment('Primary country-code top-level domain, for example .uk.');
}
if (! in_array('currency_code', $columns, true)) {
$table->char('currency_code', 3)->nullable()->index()->after('tld')->comment('Primary ISO 4217 currency code.');
}
if (! in_array('currency_name', $columns, true)) {
$table->string('currency_name')->nullable()->after('currency_code')->comment('Primary currency display name.');
}
if (! in_array('currency_symbol', $columns, true)) {
$table->string('currency_symbol', 16)->nullable()->after('currency_name')->comment('Primary currency symbol.');
}
if (! in_array('languages', $columns, true)) {
$table->json('languages')->nullable()->after('currency_symbol')->comment('Language metadata as JSON array/object.');
}
if (! in_array('timezones', $columns, true)) {
$table->json('timezones')->nullable()->after('languages')->comment('Timezone metadata as JSON array.');
}
if (! in_array('latitude', $columns, true)) {
$table->decimal('latitude', 10, 7)->nullable()->after('timezones')->comment('Approximate latitude for maps and geo grouping.');
}
if (! in_array('longitude', $columns, true)) {
$table->decimal('longitude', 10, 7)->nullable()->after('latitude')->comment('Approximate longitude for maps and geo grouping.');
}
if (! in_array('flag_svg_url', $columns, true)) {
$table->string('flag_svg_url')->nullable()->after('longitude')->comment('Optional externally hosted SVG flag URL.');
}
if (! in_array('flag_png_url', $columns, true)) {
$table->string('flag_png_url')->nullable()->after('flag_svg_url')->comment('Optional externally hosted PNG flag URL.');
}
if (! in_array('ioc_code', $columns, true)) {
$table->string('ioc_code', 8)->nullable()->index()->after('flag_png_url')->comment('IOC country code where applicable.');
}
if (! in_array('fifa_code', $columns, true)) {
$table->string('fifa_code', 8)->nullable()->index()->after('ioc_code')->comment('FIFA country code where applicable.');
}
if (! in_array('postal_code_format', $columns, true)) {
$table->string('postal_code_format')->nullable()->after('fifa_code')->comment('Human-readable postal-code format/pattern.');
}
if (! in_array('address_format', $columns, true)) {
$table->text('address_format')->nullable()->after('postal_code_format')->comment('Country-specific address formatting guidance.');
}
if (! in_array('deleted_at', $columns, true)) {
$table->softDeletes()->comment('Soft deletion for retired/custom country records.');
}
});
}
/**
* Reverse enterprise ISO 3166 support fields.
*/
public function down(): void
{
Schema::table('countries', function (Blueprint $table): void {
foreach ([
'deleted_at',
'address_format',
'postal_code_format',
'fifa_code',
'ioc_code',
'flag_png_url',
'flag_svg_url',
'longitude',
'latitude',
'timezones',
'languages',
'currency_symbol',
'currency_name',
'currency_code',
'tld',
'calling_code',
'un_member',
'sovereignty_status',
'intermediate_region',
'continent',
'capital',
'native_name',
] as $column) {
if (Schema::hasColumn('countries', $column)) {
$table->dropColumn($column);
}
}
});
}
};