Server IP : 66.29.132.124 / Your IP : 18.219.158.84 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/database/migrations/ |
Upload File : |
<?php use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Wallet; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; class CreateWalletsTable extends Migration { /** * @return string */ protected function table(): string { return (new Wallet())->getTable(); } /** * @return void */ public function up(): void { Schema::create($this->table(), function (Blueprint $table) { $table->engine = "InnoDB"; $table->bigIncrements('id'); $table->morphs('holder'); $table->string('name'); $table->string('slug')->index(); $table->string('description')->nullable(); $table->decimal('balance', 64, 0)->default(0); $table->timestamps(); $table->integer('create_user')->nullable(); $table->integer('update_user')->nullable(); $table->unique(['holder_type', 'holder_id', 'slug']); }); /** * migrate v1 to v2 */ $default = config('wallet.wallet.default.name', 'Default Wallet'); $slug = config('wallet.wallet.default.slug', 'default'); $now = time(); $query = Transaction::query()->distinct() ->selectRaw('payable_type as holder_type') ->selectRaw('payable_id as holder_id') ->selectRaw('? as name', [$default]) ->selectRaw('? as slug', [$slug]) ->selectRaw('sum(amount) as balance') ->selectRaw('? as created_at', [$now]) ->selectRaw('? as updated_at', [$now]) ->groupBy('holder_type', 'holder_id') ->orderBy('holder_type'); DB::transaction(function () use ($query) { $query->chunk(1000, function (Collection $transactions) { DB::table((new Wallet())->getTable()) ->insert($transactions->toArray()); }); }); } /** * @return void */ public function down(): void { Schema::dropIfExists($this->table()); } }