|
| 1 | +<?php |
| 2 | + |
| 3 | +use Illuminate\Database\Migrations\Migration; |
| 4 | +use Illuminate\Support\Facades\Schema; |
| 5 | + |
| 6 | +class CreateLegacyTables extends Migration |
| 7 | +{ |
| 8 | + /** |
| 9 | + * Run the migrations. |
| 10 | + * Drop all legacy tables in reverse dependency order to respect foreign key constraints. |
| 11 | + * |
| 12 | + * @return void |
| 13 | + */ |
| 14 | + public function up() |
| 15 | + { |
| 16 | + Schema::create('legacy_applications', function ($table) { |
| 17 | + $table->increments('id'); |
| 18 | + $table->integer('tenant_id'); |
| 19 | + $table->string('tenant_user_id'); |
| 20 | + $table->string('name'); |
| 21 | + $table->text('description')->nullable(); |
| 22 | + $table->string('key')->unique('legacy_applications_key_unique'); |
| 23 | + $table->timestamp('created_at')->nullable(); |
| 24 | + $table->timestamp('updated_at')->nullable(); |
| 25 | + $table->timestamp('deleted_at')->nullable(); |
| 26 | + $table->bigInteger('estimated_users_count')->nullable(); |
| 27 | + }); |
| 28 | + Schema::table('legacy_applications', function ($table) { |
| 29 | + $table->index(['tenant_id', 'tenant_user_id'], 'legacy_applications_tenant_id_tenant_user_id_index'); |
| 30 | + }); |
| 31 | + |
| 32 | + Schema::create('legacy_organisations', function ($table) { |
| 33 | + $table->increments('id'); |
| 34 | + $table->string('country_code', 3); |
| 35 | + $table->string('org_name'); |
| 36 | + $table->string('oid_code'); |
| 37 | + $table->string('attribution_url')->nullable(); |
| 38 | + $table->string('attribution_file_name')->nullable(); |
| 39 | + }); |
| 40 | + Schema::table('legacy_organisations', function ($table) { |
| 41 | + $table->index('country_code', 'legacy_organisations_country_code_index'); |
| 42 | + }); |
| 43 | + |
| 44 | + Schema::create('legacy_organisation_details', function ($table) { |
| 45 | + $table->increments('id'); |
| 46 | + $table->unsignedInteger('org_id'); |
| 47 | + $table->string('language_code', 10)->nullable(); |
| 48 | + $table->string('org_name'); |
| 49 | + $table->text('attribution_message')->nullable(); |
| 50 | + $table->tinyInteger('published'); |
| 51 | + $table->unique(['org_id', 'language_code'], 'legacy_organisation_details_org_id_language_code_unique'); |
| 52 | + $table->foreign('org_id', 'legacy_organisation_details_org_id_foreign') |
| 53 | + ->references('id')->on('legacy_organisations') |
| 54 | + ->onDelete('cascade'); |
| 55 | + }); |
| 56 | + |
| 57 | + Schema::create('legacy_region_translations', function ($table) { |
| 58 | + $table->increments('id'); |
| 59 | + $table->unsignedInteger('region_id'); |
| 60 | + $table->string('language_code', 10)->nullable(); |
| 61 | + $table->string('title'); |
| 62 | + $table->text('description')->nullable(); |
| 63 | + $table->timestamp('created_at')->nullable(); |
| 64 | + $table->timestamp('updated_at')->nullable(); |
| 65 | + $table->index('region_id', 'legacy_region_translations_region_id_index'); |
| 66 | + }); |
| 67 | + |
| 68 | + Schema::create('legacy_regions', function ($table) { |
| 69 | + $table->increments('id'); |
| 70 | + $table->unsignedInteger('organisation_id'); |
| 71 | + $table->string('title'); |
| 72 | + $table->string('slug'); |
| 73 | + $table->timestamp('created_at')->nullable(); |
| 74 | + $table->timestamp('updated_at')->nullable(); |
| 75 | + $table->index('organisation_id', 'legacy_regions_organisation_id_index'); |
| 76 | + $table->index('slug', 'legacy_regions_slug_index'); |
| 77 | + }); |
| 78 | + |
| 79 | + Schema::create('legacy_whatnow_entities', function ($table) { |
| 80 | + $table->increments('id'); |
| 81 | + $table->unsignedInteger('org_id'); |
| 82 | + $table->integer('region_id')->nullable(); |
| 83 | + $table->string('event_type'); |
| 84 | + $table->timestamp('created_at')->nullable(); |
| 85 | + $table->timestamp('updated_at')->nullable(); |
| 86 | + $table->unique(['org_id', 'event_type', 'region_id'], 'legacy_whatnow_entities_org_id_event_type_region_id_unique'); |
| 87 | + $table->index(['org_id', 'event_type'], 'legacy_whatnow_entities_org_id_event_type_index'); |
| 88 | + $table->index('region_id', 'legacy_whatnow_entities_region_id_index'); |
| 89 | + }); |
| 90 | + |
| 91 | + Schema::create('legacy_whatnow_entity_translations', function ($table) { |
| 92 | + $table->increments('id'); |
| 93 | + $table->unsignedInteger('entity_id'); |
| 94 | + $table->string('language_code', 10)->nullable(); |
| 95 | + $table->string('title')->nullable(); |
| 96 | + $table->text('description')->nullable(); |
| 97 | + $table->string('web_url', 512)->nullable(); |
| 98 | + $table->timestamp('created_at')->nullable(); |
| 99 | + $table->timestamp('published_at')->nullable(); |
| 100 | + $table->foreign('entity_id', 'legacy_whatnow_entity_translations_entity_id_foreign') |
| 101 | + ->references('id')->on('legacy_whatnow_entities') |
| 102 | + ->onDelete('cascade'); |
| 103 | + }); |
| 104 | + |
| 105 | + Schema::create('legacy_whatnow_entity_stages', function ($table) { |
| 106 | + $table->increments('id'); |
| 107 | + $table->unsignedInteger('translation_id'); |
| 108 | + $table->string('language_code', 10)->nullable(); |
| 109 | + $table->enum('stage', ['warning', 'watch', 'immediate', 'recover', 'mitigation', 'seasonalForecast']); |
| 110 | + $table->json('content')->nullable(); |
| 111 | + $table->foreign('translation_id', 'legacy_whatnow_entity_stages_translation_id_foreign') |
| 112 | + ->references('id')->on('legacy_whatnow_entity_translations') |
| 113 | + ->onDelete('cascade'); |
| 114 | + $table->index('translation_id', 'legacy_whatnow_entity_stages_translation_id_index'); |
| 115 | + }); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Reverse the migrations. |
| 120 | + * Drop all legacy tables in reverse dependency order to respect foreign key constraints. |
| 121 | + * |
| 122 | + * @return void |
| 123 | + */ |
| 124 | + public function down() |
| 125 | + { |
| 126 | + Schema::disableForeignKeyConstraints(); |
| 127 | + |
| 128 | + Schema::dropIfExists('legacy_whatnow_entity_stages'); |
| 129 | + Schema::dropIfExists('legacy_whatnow_entity_translations'); |
| 130 | + Schema::dropIfExists('legacy_whatnow_entities'); |
| 131 | + Schema::dropIfExists('legacy_region_translations'); |
| 132 | + Schema::dropIfExists('legacy_regions'); |
| 133 | + Schema::dropIfExists('legacy_organisation_details'); |
| 134 | + Schema::dropIfExists('legacy_organisations'); |
| 135 | + Schema::dropIfExists('legacy_applications'); |
| 136 | + |
| 137 | + Schema::enableForeignKeyConstraints(); |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | + |
0 commit comments