Skip to content

Commit

Permalink
Fix for new installments.
Browse files Browse the repository at this point in the history
Fixed so that new installments will use the new naming right away.
But upgrades will migrate the table names.
  • Loading branch information
addgod committed May 8, 2022
1 parent 607d6f1 commit 1827cae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 41 deletions.
6 changes: 3 additions & 3 deletions migrations/2018_01_05_165234_create_transactions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateTransactionsTable extends Migration
*/
public function up()
{
Schema::create('transactions', function (Blueprint $table) {
Schema::create('omnipay_transactions', function (Blueprint $table) {
$table->increments('id');
$table->string('merchant_id');
$table->decimal('amount');
Expand All @@ -24,15 +24,15 @@ public function up()
$table->timestamps();
});

Schema::create('transaction_logs', function (Blueprint $table) {
Schema::create('omnipay_transaction_logs', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('transaction_id');
$table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade');
$table->text('payload')->nullable();
$table->timestamps();
});

Schema::create('merchants', function (Blueprint $table) {
Schema::create('omnipay_merchants', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('gateway');
Expand Down
60 changes: 22 additions & 38 deletions migrations/2020_14_08_165232_update_table_names.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ class UpdateTableNames extends Migration
*/
public function up()
{
Schema::table('transaction_logs', function (Blueprint $table) {
$table->dropForeign(['transaction_id']);
});

Schema::table('merchantables', function (Blueprint $table) {
$table->dropForeign(['merchant_id']);
});

Schema::rename('transactions', 'omnipay_transactions');
Schema::rename('transaction_logs', 'omnipay_transaction_logs');
Schema::rename('merchants', 'omnipay_merchants');

Schema::table('omnipay_transaction_logs', function (Blueprint $table) {
$table->foreign('transaction_id')->references('id')->on('omnipay_transactions')->onDelete('cascade');
});

Schema::table('merchantables', function (Blueprint $table) {
$table->foreign('merchant_id')->references('id')->on('omnipay_merchants')->onDelete('cascade');
});
if (Schema::hasTable('transactions') && Schema::hasTable('transaction_logs') && Schema::hasTable('merchants')) {
Schema::table('transaction_logs', function (Blueprint $table) {
$table->dropForeign(['transaction_id']);
});

Schema::table('merchantables', function (Blueprint $table) {
$table->dropForeign(['merchant_id']);
});

Schema::rename('transactions', 'omnipay_transactions');
Schema::rename('transaction_logs', 'omnipay_transaction_logs');
Schema::rename('merchants', 'omnipay_merchants');

Schema::table('omnipay_transaction_logs', function (Blueprint $table) {
$table->foreign('transaction_id')->references('id')->on('omnipay_transactions')->onDelete('cascade');
});

Schema::table('merchantables', function (Blueprint $table) {
$table->foreign('merchant_id')->references('id')->on('omnipay_merchants')->onDelete('cascade');
});
}
}

/**
Expand All @@ -41,24 +43,6 @@ public function up()
*/
public function down()
{
Schema::table('omnipay_transaction_logs', function (Blueprint $table) {
$table->dropForeign(['transaction_id']);
});

Schema::table('merchantables', function (Blueprint $table) {
$table->dropForeign(['merchant_id']);
});

Schema::rename('omnipay_transactions', 'transactions');
Schema::rename('omnipay_transaction_logs', 'transaction_logs');
Schema::rename('omnipay_merchants', 'merchants');

Schema::table('transaction_logs', function (Blueprint $table) {
$table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade');
});

Schema::table('merchantables', function (Blueprint $table) {
$table->foreign('merchant_id')->references('id')->on('merchants')->onDelete('cascade');
});
// There is no coming back anymore from here.
}
}

0 comments on commit 1827cae

Please sign in to comment.