2025_11_26_132239_create_subscriptions_tables.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. use App\Database\Migrations\TenantMigration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends TenantMigration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. Schema::create('subscriptions', function (Blueprint $table) {
  15. $table->id();
  16. $table->string('name');
  17. $table->unsignedBigInteger('causal_id')->nullable();
  18. $table->unsignedBigInteger('sub_causal_id')->nullable();
  19. $table->decimal('subscription_price', 8, 2);
  20. $table->longText('prices')->nullable();
  21. $table->boolean('enabled')->default(1);
  22. $table->softDeletes();
  23. $table->timestamps();
  24. $table->foreign('causal_id')->nullable()->references('id')->on('causals')->onUpdate('cascade')->onDelete('cascade');
  25. $table->foreign('sub_causal_id')->nullable()->references('id')->on('causals')->onUpdate('cascade')->onDelete('cascade');
  26. });
  27. Schema::table('records_rows', function (Blueprint $table) {
  28. $table->unsignedBigInteger('subscription_id')->nullable();
  29. $table->foreign('subscription_id')->nullable()->references('id')->on('subscriptions')->onUpdate('cascade')->onDelete('cascade');
  30. });
  31. Schema::table('receipts_rows', function (Blueprint $table) {
  32. $table->unsignedBigInteger('subscription_id')->nullable();
  33. $table->foreign('subscription_id')->nullable()->references('id')->on('subscriptions')->onUpdate('cascade')->onDelete('cascade');
  34. });
  35. Schema::create('member_subscriptions', function (Blueprint $table) {
  36. $table->id();
  37. $table->unsignedBigInteger('member_id');
  38. $table->unsignedBigInteger('subscription_id');
  39. $table->date('date_from')->nullable();
  40. $table->date('date_to')->nullable();
  41. $table->decimal('price', 8, 2);
  42. $table->unsignedBigInteger('course_subscription_id')->nullable();
  43. $table->decimal('subscription_price', 8, 2);
  44. $table->string('notes')->nullable();
  45. $table->timestamps();
  46. $table->foreign('member_id')->nullable()->references('id')->on('members')->onUpdate('cascade')->onDelete('cascade');
  47. $table->foreign('subscription_id')->nullable()->references('id')->on('subscriptions')->onUpdate('cascade')->onDelete('cascade');
  48. $table->foreign('course_subscription_id')->nullable()->references('id')->on('course_subscriptions')->onUpdate('cascade')->onDelete('cascade');
  49. });
  50. Schema::table('rates', function (Blueprint $table) {
  51. $table->unsignedBigInteger('member_subscription_id')->nullable();
  52. $table->foreign('member_subscription_id')->nullable()->references('id')->on('member_subscriptions')->onUpdate('cascade')->onDelete('cascade');
  53. });
  54. }
  55. /**
  56. * Reverse the migrations.
  57. *
  58. * @return void
  59. */
  60. public function down()
  61. {
  62. Schema::table('rates', function (Blueprint $table) {
  63. $table->dropColumn('member_subscription_id');
  64. });
  65. Schema::dropIfExists('member_subscriptions');
  66. Schema::table('records_rows', function (Blueprint $table) {
  67. $table->dropColumn('subscription_id');
  68. });
  69. Schema::table('receipts_rows', function (Blueprint $table) {
  70. $table->dropColumn('subscription_id');
  71. });
  72. Schema::dropIfExists('subscriptions');
  73. }
  74. };