osb/database/migrations/2021_07_23_164158_rework_payments.php
2021-07-23 17:36:53 +10:00

57 lines
1.6 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ReworkPayments extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('ab_payment_item', function (Blueprint $table) {
$table->dropUnique('UNIQUE');
$table->dropForeign('fk_pi_pay');
$table->dropPrimary(['id','payment_id','site_id']);
$table->dropIndex('fk_pi_pay_idx');
});
DB::statement('ALTER TABLE ab_payment_item RENAME TO payment_items');
Schema::table('ab_payment', function (Blueprint $table) {
$table->dropPrimary(['id','checkout_id','account_id','site_id']);
$table->dropUnique('UNIQUE');
});
DB::statement('ALTER TABLE ab_payment RENAME TO payments');
DB::statement('ALTER TABLE payment_items ADD PRIMARY KEY (id,site_id), MODIFY COLUMN id bigint auto_increment');
DB::statement('ALTER TABLE payments ADD PRIMARY KEY (id,site_id), MODIFY COLUMN id bigint auto_increment');
DB::statement('ALTER TABLE payments RENAME COLUMN date_payment TO payment_date');
Schema::table('payment_items', function (Blueprint $table) {
$table->unique(['site_id','payment_id','invoice_id']);
$table->foreign(['payment_id','site_id'])->references(['id','site_id'])->on('payments');
});
Schema::table('payments', function (Blueprint $table) {
$table->unique(['site_id','id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
abort(500,'cant go back');
}
}