diff --git a/database/migrations/create_order_items_table.php.stub b/database/migrations/create_order_items_table.php.stub index 67280b6..60b5969 100644 --- a/database/migrations/create_order_items_table.php.stub +++ b/database/migrations/create_order_items_table.php.stub @@ -27,6 +27,7 @@ return new class extends Migration $table->integer('unit_price'); $table->decimal('tax_percentage', 6, 4); $table->unsignedBigInteger('order_id')->nullable(); + $table->text('metadata')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/create_orders_table.php.stub b/database/migrations/create_orders_table.php.stub index e3ee6c7..25ba6de 100644 --- a/database/migrations/create_orders_table.php.stub +++ b/database/migrations/create_orders_table.php.stub @@ -30,6 +30,7 @@ return new class extends Migration $table->string('mollie_payment_id')->nullable(); $table->string('mollie_payment_status', 16)->nullable(); $table->datetime('processed_at')->nullable(); + $table->text('metadata')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/create_refund_items_table.php.stub b/database/migrations/create_refund_items_table.php.stub index a228178..d85ef73 100644 --- a/database/migrations/create_refund_items_table.php.stub +++ b/database/migrations/create_refund_items_table.php.stub @@ -25,6 +25,7 @@ return new class extends Migration $table->unsignedInteger('quantity'); $table->integer('unit_price'); $table->decimal('tax_percentage', 6, 4); + $table->text('metadata')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/create_refunds_table.php.stub b/database/migrations/create_refunds_table.php.stub index 744a206..3314563 100644 --- a/database/migrations/create_refunds_table.php.stub +++ b/database/migrations/create_refunds_table.php.stub @@ -23,6 +23,7 @@ return new class extends Migration $table->string('mollie_refund_status'); $table->integer('total'); $table->string('currency', 3); + $table->text('metadata')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/create_subscriptions_table.php.stub b/database/migrations/create_subscriptions_table.php.stub index 86dc362..9b5cc49 100644 --- a/database/migrations/create_subscriptions_table.php.stub +++ b/database/migrations/create_subscriptions_table.php.stub @@ -27,6 +27,7 @@ return new class extends Migration $table->datetime('cycle_started_at'); $table->datetime('cycle_ends_at')->nullable(); $table->unsignedBigInteger('scheduled_order_item_id')->nullable(); + $table->text('metadata')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/upgrade_to_cashier_v3.php.stub b/database/migrations/upgrade_to_cashier_v3.php.stub index 5d453ae..fcbc8b2 100644 --- a/database/migrations/upgrade_to_cashier_v3.php.stub +++ b/database/migrations/upgrade_to_cashier_v3.php.stub @@ -6,6 +6,14 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { + const METADATA_FIELD_TABLES = [ + 'orders', + 'order_items', + 'refunds', + 'refund_items', + 'subscriptions', + ]; + /** * Run the migrations. * @@ -13,7 +21,7 @@ return new class extends Migration */ public function up(): void { - // + $this->addMetadataFieldToTables(self::METADATA_FIELD_TABLES); } /** @@ -23,6 +31,20 @@ return new class extends Migration */ public function down(): void { - // + $this->dropMetadataFieldFromTables(self::METADATA_FIELD_TABLES); + } + + protected function addMetadataFieldToTables(array $tables): void + { + collect($tables)->each(fn($table) => Schema::table($table, function (Blueprint $table) { + $table->text('metadata')->nullable(); + })); + } + + protected function dropMetadataFieldFromTables(array $tables): void + { + collect($tables)->each(fn($table) => Schema::table($table, function (Blueprint $table) { + $table->dropColumn('metadata'); + })); } };