OwlCyberSecurity - MANAGER
Edit File: 2050_08_14_103502_create_foreign_keys_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('users',function (Blueprint $table){ $table->foreign('credit_id')->references('id')->on('credits')->onDelete('restrict'); }); Schema::table('users_roles',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('role_id')->references('id')->on('roles')->onDelete('restrict'); }); Schema::table('sms_items',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); }); Schema::table('users_addresses',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('state_id')->references('id')->on('states')->onDelete('restrict'); $table->foreign('city_id')->references('id')->on('cities')->onDelete('restrict'); }); Schema::table('calculatorconfigs',function (Blueprint $table){ $table->foreign('region_id')->references('id')->on('regions')->onDelete('restrict'); }); Schema::table('sources',function (Blueprint $table){ $table->foreign('exchange_id')->references('id')->on('exchanges')->onDelete('restrict'); }); Schema::table('departments_users',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('department_id')->references('id')->on('departments')->onDelete('restrict'); }); Schema::table('costs',function (Blueprint $table){ $table->foreign('registrant')->references('id')->on('users')->onDelete('restrict'); $table->foreign('costtype_id')->references('id')->on('costtypes')->onDelete('restrict'); $table->foreign('bankcard_id')->references('id')->on('bankcards')->onDelete('restrict'); }); Schema::table('articles',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('article_category_id')->references('id')->on('articles_categories')->onDelete('restrict'); }); Schema::table('invoices',function (Blueprint $table){ $table->foreign('agent_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('discount_id')->references('id')->on('discounts')->onDelete('restrict'); $table->foreign('address_id')->references('id')->on('users_addresses')->onDelete('restrict'); }); Schema::table('exchanges_invoices',function (Blueprint $table){ $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('restrict'); $table->foreign('exchange_id')->references('id')->on('exchanges')->onDelete('restrict'); }); Schema::table('cities',function (Blueprint $table){ $table->foreign('state_id')->references('id')->on('states')->onDelete('restrict'); }); Schema::table('tickets',function (Blueprint $table){ // $table->foreign('status_id')->references('id')->on('ticket_status'); // $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('restrict'); // $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); // $table->foreign('department_id')->references('id')->on('departments')->onDelete('restrict'); }); Schema::table('ticket_logs',function (Blueprint $table){ // $table->foreign('ticket_id')->references('id')->on('tickets')->onDelete('restrict'); // $table->foreign('status_id')->references('id')->on('ticket_status')->onDelete('restrict'); // $table->foreign('agent_id')->references('id')->on('users')->onDelete('restrict'); // $table->foreign('attachment_id')->references('id')->on('files')->onDelete('restrict'); // $table->foreign('department_id')->references('id')->on('departments')->onDelete('restrict'); }); Schema::table('invoice_items',function (Blueprint $table){ $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('restrict'); $table->foreign('exchange_id')->references('id')->on('exchanges')->onDelete('restrict'); $table->foreign('region_id')->references('id')->on('regions')->onDelete('restrict'); }); Schema::table('othercosts',function (Blueprint $table){ $table->foreign('invoice_id')->references('id')->on('invoice_items')->onDelete('restrict'); $table->foreign('exchange_id')->references('id')->on('exchanges')->onDelete('restrict'); }); Schema::table('logistics',function (Blueprint $table){ $table->foreign('carrier_id')->references('id')->on('carriers')->onDelete('restrict'); $table->foreign('source_id')->references('id')->on('sources')->onDelete('restrict'); $table->foreign('account_id')->references('id')->on('accounts')->onDelete('restrict'); $table->foreign('agent_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('invoice_item_id')->references('id')->on('invoice_items')->onDelete('restrict'); $table->foreign('exchange_id')->references('id')->on('exchanges')->onDelete('restrict'); $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('restrict'); // $table->foreign('base_id')->references('id')->on('bases')->onDelete('restrict'); // $table->foreign('transitionreason')->references('id')->on('cancel_reasons')->onDelete('restrict'); }); Schema::table('credits',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('restrict'); $table->foreign('user_bank_id')->references('id')->on('user_bank_accounts')->onDelete('restrict'); }); Schema::table('categories',function (Blueprint $table){ $table->foreign('parent_id')->references('id')->on('categories')->onDelete('restrict'); }); Schema::table('user_bank_accounts',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); }); Schema::table('user_wallets',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); }); Schema::table('transition_histories',function (Blueprint $table){ $table->foreign('transition_agent_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('logistic_id')->references('id')->on('logistics')->onDelete('restrict'); }); Schema::table('products',function (Blueprint $table){ // $table->foreign('exchange_id')->references('id')->on('exchanges')->onDelete('restrict'); // $table->foreign('category_id')->references('id')->on('categories')->onDelete('restrict'); // $table->foreign('region_id')->references('id')->on('regions')->onDelete('restrict'); // $table->foreign('product_images_id')->references('id')->on('product_images')->onDelete('restrict'); }); Schema::table('devices',function (Blueprint $table){ $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); }); Schema::table('transactions',function (Blueprint $table){ $table->foreign('payment_method_id')->references('id')->on('payment_methods')->onDelete('restrict'); $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); }); Schema::table('invoices_othercosts',function (Blueprint $table){ $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('restrict'); $table->foreign('exchange_id')->references('id')->on('exchanges')->onDelete('restrict'); }); /* Schema::connection('mysql_log')->table('hit_logs',function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('restrict'); }); Schema::connection('mysql_log')->table('payment_logs',function (Blueprint $table){ $table->foreign('registrant_id')->references('id')->on('users')->onDelete('restrict'); $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('restrict'); }); Schema::connection('mysql_log')->table('source_paylogs',function (Blueprint $table){ $table->foreign('source_id')->references('id')->on('sources')->onDelete('restrict'); $table->foreign('cost_id')->references('id')->on('costs')->onDelete('restrict'); });*/ } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('users',function (Blueprint $table){ $table->dropForeign('credit_id'); }); Schema::table('users_roles',function (Blueprint $table){ $table->dropForeign('user_id'); $table->dropForeign('role_id'); }); Schema::table('sms_items',function (Blueprint $table){ $table->dropForeign('user_id'); }); Schema::table('users_addresses',function (Blueprint $table){ $table->dropForeign('user_id'); $table->dropForeign('state_id'); $table->dropForeign('city_id'); }); Schema::table('calculatorconfigs',function (Blueprint $table){ $table->dropForeign('region_id'); }); Schema::table('sources',function (Blueprint $table){ $table->dropForeign('region_id'); }); Schema::table('departments_users',function (Blueprint $table){ $table->dropForeign('user_id'); $table->dropForeign('department_id'); }); Schema::table('costs',function (Blueprint $table){ $table->dropForeign('registrant'); $table->dropForeign('costtype_id'); $table->dropForeign('bankcard_id'); }); Schema::table('articles',function (Blueprint $table){ $table->dropForeign('user_id'); $table->dropForeign('article_category_id'); }); Schema::table('invoices',function (Blueprint $table){ $table->dropForeign('agent_id'); $table->dropForeign('user_id'); $table->dropForeign('discount_id'); $table->dropForeign('address_id'); }); Schema::table('exchanges_invoices',function (Blueprint $table){ $table->dropForeign('invoice_id'); $table->dropForeign('exchange_id'); }); Schema::table('cities',function (Blueprint $table){ $table->dropForeign('state_id'); }); Schema::table('tickets',function (Blueprint $table){ $table->dropForeign('invoice_id'); $table->dropForeign('Parent_id'); $table->dropForeign('user_id'); $table->dropForeign('agent_id'); $table->dropForeign('attachment_id'); $table->dropForeign('department_id'); }); Schema::table('invoice_items',function (Blueprint $table){ $table->dropForeign('invoice_id'); $table->dropForeign('exchange_id'); $table->dropForeign('region_id'); }); Schema::table('othercosts',function (Blueprint $table){ $table->dropForeign('invoice_id'); $table->dropForeign('exchange_id'); }); Schema::table('logistics',function (Blueprint $table){ $table->dropForeign('carrier_id'); $table->dropForeign('source_id'); $table->dropForeign('account_id'); $table->dropForeign('agent_id'); $table->dropForeign('invoice_item_id'); $table->dropForeign('exchange_id'); $table->dropForeign('invoice_id'); $table->dropForeign('base_id'); $table->dropForeign('transitionreason'); }); Schema::table('credits',function (Blueprint $table){ $table->dropForeign('user_id'); $table->dropForeign('invoice_id'); $table->dropForeign('user_bank_id'); }); Schema::table('categories',function (Blueprint $table){ $table->dropForeign('parent_id'); $table->dropForeign('file_id'); }); Schema::table('user_bank_accounts',function (Blueprint $table){ $table->dropForeign('user_id'); }); Schema::table('user_wallets',function (Blueprint $table){ $table->dropForeign('user_id'); }); Schema::table('files',function (Blueprint $table){ $table->dropForeign('user_id'); $table->dropForeign('entity_type'); }); Schema::table('transition_histories',function (Blueprint $table){ $table->dropForeign('transition_agent_id'); $table->dropForeign('logistic_id'); }); Schema::table('products',function (Blueprint $table){ $table->dropForeign('exchange_id'); $table->dropForeign('category_id'); $table->dropForeign('region_id'); $table->dropForeign('product_images_id'); }); Schema::table('devices',function (Blueprint $table){ $table->dropForeign('user_id'); }); Schema::table('transactions',function (Blueprint $table){ $table->dropForeign('user_id'); $table->dropForeign('payment_method_id'); }); Schema::connection('mysql_log')->table('hit_logs',function (Blueprint $table){ $table->dropForeign('user_id'); }); Schema::connection('mysql_log')->table('payment_logs',function (Blueprint $table){ $table->dropForeign('registrant_id'); $table->dropForeign('invoice_id'); }); Schema::connection('mysql_log')->table('source_paylogs',function (Blueprint $table){ $table->dropForeign('source_id'); $table->dropForeign('cost_id'); }); Schema::table('invoices_othercosts',function (Blueprint $table){ $table->dropForeign('invoice_id'); $table->dropForeign('exchange_id'); }); } };