Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade #212

Merged
merged 7 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build:

environment:
php:
version: 7.2
version: 7.3
pecl_extensions:
- memcached
memcached: true
Expand All @@ -17,9 +17,8 @@ build:
tests:
override:
- php-scrutinizer-run
- command: vendor/bin/phpunit --dump-xdebug-filter xdebug-filter.php
-
command: vendor/bin/phpunit --prepend xdebug-filter.php --coverage-clover=clover.xml
command: vendor/bin/phpunit --coverage-clover=clover.xml
coverage:
file: clover.xml
format: php-clover
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- '7.2'
- '7.3'
- '7.4'
- 'nightly'
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
}
],
"require": {
"php": "^7.2|^8.0",
"php": "^7.3|^8.0",
"ext-pdo": "*",
"illuminate/database": "^6.0|^7.0|^8.0",
"doctrine/dbal": "^2.8|^3.0",
"ramsey/uuid": "^3.0|^4.0"
},
"require-dev": {
"infection/infection": "0.15.*|0.16.*|0.17.*",
"orchestra/testbench": "^4.0|^5.0",
"infection/infection": "0.17.*",
"laravel/cashier": "^10.0|^11.0|^12.0",
"laravel/legacy-factories": "^1.0",
"orchestra/testbench": "^4.0|^5.0|^6.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.0|^9.0",
"laravel/cashier": "^10.0|^11.0|^12.0"
"phpunit/phpunit": "^8.0|^9.0"
},
"suggest": {
"ext-bcmath": "Used for accurate calculations of large numbers",
Expand Down
20 changes: 10 additions & 10 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?php

use Bavix\Wallet\Models\Transaction;
use Bavix\Wallet\Models\Transfer;
use Bavix\Wallet\Models\Wallet;
use Bavix\Wallet\Objects\Bring;
use Bavix\Wallet\Objects\Cart;
use Bavix\Wallet\Objects\EmptyLock;
use Bavix\Wallet\Objects\Operation;
use Bavix\Wallet\Services\ExchangeService;
use Bavix\Wallet\Services\CommonService;
use Bavix\Wallet\Services\WalletService;
use Bavix\Wallet\Services\ExchangeService;
use Bavix\Wallet\Services\LockService;
use Bavix\Wallet\Models\Transaction;
use Bavix\Wallet\Models\Transfer;
use Bavix\Wallet\Models\Wallet;
use Bavix\Wallet\Simple\Rate;
use Bavix\Wallet\Simple\Store;
use Bavix\Wallet\Services\WalletService;
use Bavix\Wallet\Simple\BCMath;
use Bavix\Wallet\Simple\Math;
use Bavix\Wallet\Simple\Rate;
use Bavix\Wallet\Simple\Store;

$bcLoaded = extension_loaded('bcmath');

return [
/**
* This parameter is necessary for more accurate calculations.
* PS, Arbitrary Precision Calculations
* PS, Arbitrary Precision Calculations.
*/
'math' => [
'scale' => 64,
Expand All @@ -40,7 +40,7 @@
],

/**
* Lock settings for highload projects
* Lock settings for highload projects.
*
* If you want to replace the default cache with another,
* then write the name of the driver cache in the key `wallet.lock.cache`.
Expand All @@ -57,7 +57,7 @@

/**
* Sometimes a slug may not match the currency and you need the ability to add an exception.
* The main thing is that there are not many exceptions)
* The main thing is that there are not many exceptions).
*
* Syntax:
* 'slug' => 'currency'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class CreateTransactionsTable extends Migration
{

/**
* @return void
*/
Expand Down Expand Up @@ -70,5 +69,4 @@ public function down(): void
{
Schema::drop($this->table());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class CreateTransfersTable extends Migration
{

/**
* @return void
*/
Expand Down Expand Up @@ -58,5 +57,4 @@ public function down(): void
{
Schema::drop($this->table());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class UpdateTransfersTable extends Migration
{

/**
* @return void
*/
Expand Down Expand Up @@ -40,7 +39,7 @@ protected function table(): string
public function down(): void
{
Schema::table($this->table(), function (Blueprint $table) {
if (!(DB::connection() instanceof SQLiteConnection)) {
if (! (DB::connection() instanceof SQLiteConnection)) {
$table->dropIndex('from_to_refund_ind');
$table->dropIndex('from_refund_ind');
$table->dropIndex('to_refund_ind');
Expand All @@ -49,5 +48,4 @@ public function down(): void
$table->dropColumn('refund');
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class CreateWalletsTable extends Migration
{

/**
* @return string
*/
Expand All @@ -37,7 +36,7 @@ public function up(): void
});

/**
* migrate v1 to v2
* migrate v1 to v2.
*/
$default = config('wallet.wallet.default.name', 'Default Wallet');
$slug = config('wallet.wallet.default.slug', 'default');
Expand Down Expand Up @@ -68,5 +67,4 @@ public function down(): void
{
Schema::drop($this->table());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
use Bavix\Wallet\Models\Wallet;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\SQLiteConnection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\SQLiteConnection;

class UpdateTransactionsTable extends Migration
{

/**
* @return string
*/
Expand Down Expand Up @@ -60,11 +59,10 @@ public function up(): void
public function down(): void
{
Schema::table($this->table(), function (Blueprint $table) {
if (!(DB::connection() instanceof SQLiteConnection)) {
if (! (DB::connection() instanceof SQLiteConnection)) {
$table->dropForeign(['wallet_id']);
}
$table->dropColumn('wallet_id');
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class AddFeeTransfersTable extends Migration
{

/**
* @return string
*/
Expand Down Expand Up @@ -37,5 +36,4 @@ public function down(): void
$table->dropColumn('fee');
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class AddStatusTransfersTable extends Migration
{

/**
* @return string
*/
Expand Down Expand Up @@ -53,11 +52,10 @@ public function down(): void
{
DB::table($this->table())
->where('status', Transfer::STATUS_REFUND)
->update(['refund' => true,]);
->update(['refund' => true]);

Schema::table($this->table(), function (Blueprint $table) {
$table->dropColumn(['status', 'status_last']);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class DropRefundTransfersTable extends Migration
{

/**
* @return string
*/
Expand All @@ -24,7 +23,7 @@ protected function table(): string
public function up(): void
{
Schema::table($this->table(), function (Blueprint $table) {
if (!(DB::connection() instanceof SQLiteConnection)) {
if (! (DB::connection() instanceof SQLiteConnection)) {
$table->dropIndex('from_to_refund_ind');
$table->dropIndex('from_refund_ind');
$table->dropIndex('to_refund_ind');
Expand All @@ -49,5 +48,4 @@ public function down(): void
$table->index(['to_type', 'to_id', 'refund'], 'to_refund_ind');
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class UpdateStatusTransfersTable extends Migration
{

/**
* @return string
*/
Expand All @@ -32,21 +31,23 @@ public function up(): void
];

if (DB::connection() instanceof MySqlConnection) {
$table = DB::getTablePrefix() . $this->table();
$table = DB::getTablePrefix().$this->table();
$enumString = implode('\', \'', $enums);
$default = Transfer::STATUS_TRANSFER;
DB::statement("ALTER TABLE $table CHANGE COLUMN status status ENUM('$enumString') NOT NULL DEFAULT '$default'");
DB::statement("ALTER TABLE $table CHANGE COLUMN status_last status_last ENUM('$enumString') NULL");

return;
}

if (DB::connection() instanceof PostgresConnection) {
$this->alterEnum(DB::getTablePrefix() . $this->table(), 'status', $enums);
$this->alterEnum(DB::getTablePrefix() . $this->table(), 'status_last', $enums);
$this->alterEnum(DB::getTablePrefix().$this->table(), 'status', $enums);
$this->alterEnum(DB::getTablePrefix().$this->table(), 'status_last', $enums);

return;
}

Schema::table($this->table(), function (Blueprint $table) use ($enums) {
Schema::table($this->table(), function (Blueprint $table) {
$table->string('status')
->default(Transfer::STATUS_TRANSFER)
->change();
Expand Down Expand Up @@ -77,21 +78,23 @@ public function down(): void
];

if (DB::connection() instanceof MySqlConnection) {
$table = DB::getTablePrefix() . $this->table();
$table = DB::getTablePrefix().$this->table();
$enumString = implode('\', \'', $enums);
$default = Transfer::STATUS_PAID;
DB::statement("ALTER TABLE $table CHANGE COLUMN status status ENUM('$enumString') NOT NULL DEFAULT '$default'");
DB::statement("ALTER TABLE $table CHANGE COLUMN status_last status_last ENUM('$enumString') NULL");

return;
}

if (DB::connection() instanceof PostgresConnection) {
$this->alterEnum(DB::getTablePrefix() . $this->table(), 'status', $enums);
$this->alterEnum(DB::getTablePrefix() . $this->table(), 'status_last', $enums);
$this->alterEnum(DB::getTablePrefix().$this->table(), 'status', $enums);
$this->alterEnum(DB::getTablePrefix().$this->table(), 'status_last', $enums);

return;
}

Schema::table($this->table(), function (Blueprint $table) use ($enums) {
Schema::table($this->table(), function (Blueprint $table) {
$table->string('status')
->default(Transfer::STATUS_PAID)
->change();
Expand All @@ -103,7 +106,7 @@ public function down(): void
}

/**
* Alter an enum field constraints
* Alter an enum field constraints.
* @param $table
* @param $field
* @param array $options
Expand All @@ -120,10 +123,9 @@ protected function alterEnum($table, $field, array $options): void

$enumString = implode(', ', $enumList);

DB::transaction(function () use ($table, $field, $check, $options, $enumString) {
DB::transaction(function () use ($table, $field, $check , $enumString) {
DB::statement(sprintf('ALTER TABLE %s DROP CONSTRAINT %s;', $table, $check));
DB::statement(sprintf('ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s::TEXT = ANY (ARRAY[%s]::TEXT[]))', $table, $check, $field, $enumString));
});
}

}
Loading