您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

2023_09_04_103821_create_accounts_table.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. use App\Enums\AccountStatus;
  3. use App\Enums\AccountType;
  4. use Illuminate\Database\Migrations\Migration;
  5. use Illuminate\Database\Schema\Blueprint;
  6. use Illuminate\Support\Facades\Schema;
  7. return new class extends Migration
  8. {
  9. /**
  10. * Run the migrations.
  11. */
  12. public function up(): void
  13. {
  14. Schema::create('accounts', function (Blueprint $table) {
  15. $table->id();
  16. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  17. $table->string('type')->default(AccountType::DEFAULT);
  18. $table->string('name', 100)->index();
  19. $table->string('number', 20);
  20. $table->string('currency_code');
  21. $table->bigInteger('opening_balance')->default(0);
  22. $table->bigInteger('balance')->default(0);
  23. $table->string('description')->nullable();
  24. $table->text('notes')->nullable();
  25. $table->string('status')->default(AccountStatus::DEFAULT);
  26. $table->string('bank_name', 100)->nullable();
  27. $table->string('bank_phone', 20)->nullable();
  28. $table->text('bank_address')->nullable();
  29. $table->string('bank_website', 255)->nullable();
  30. $table->string('bic_swift_code', 11)->nullable();
  31. $table->string('iban', 34)->nullable();
  32. $table->string('aba_routing_number', 9)->nullable();
  33. $table->string('ach_routing_number', 9)->nullable();
  34. $table->boolean('enabled')->default(true);
  35. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  36. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  37. $table->timestamps();
  38. $table->unique(['company_id', 'number']);
  39. $table->foreign(['company_id', 'currency_code'])
  40. ->references(['company_id', 'code'])
  41. ->on('currencies')
  42. ->restrictOnDelete();
  43. });
  44. }
  45. /**
  46. * Reverse the migrations.
  47. */
  48. public function down(): void
  49. {
  50. Schema::dropIfExists('accounts');
  51. }
  52. };