Add some if-statements to the migrations.

This commit is contained in:
James Cole 2021-04-05 10:56:56 +02:00
parent f5983f08fd
commit 1cf188ee08
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D

View File

@ -120,8 +120,10 @@ class ChangesForV550 extends Migration
// update budget / transaction journal table. // update budget / transaction journal table.
Schema::table( Schema::table(
'budget_transaction_journal', function (Blueprint $table) { 'budget_transaction_journal', function (Blueprint $table) {
$table->integer('budget_limit_id', false, true)->nullable()->default(null)->after('budget_id'); if (!Schema::hasColumn('budget_transaction_journal', 'budget_limit_id')) {
$table->foreign('budget_limit_id', 'budget_id_foreign')->references('id')->on('budget_limits')->onDelete('set null'); $table->integer('budget_limit_id', false, true)->nullable()->default(null)->after('budget_id');
$table->foreign('budget_limit_id', 'budget_id_foreign')->references('id')->on('budget_limits')->onDelete('set null');
}
} }
); );
@ -130,63 +132,73 @@ class ChangesForV550 extends Migration
Schema::table( Schema::table(
'budget_limits', 'budget_limits',
static function (Blueprint $table) { static function (Blueprint $table) {
$table->string('period', 12)->nullable(); if (!Schema::hasColumn('budget_limits', 'period')) {
$table->boolean('generated')->default(false); $table->string('period', 12)->nullable();
}
if (!Schema::hasColumn('budget_limits', 'generated')) {
$table->boolean('generated')->default(false);
}
} }
); );
// new webhooks table // new webhooks table
Schema::create( if (!Schema::hasTable('webhooks')) {
'webhooks', Schema::create(
static function (Blueprint $table) { 'webhooks',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('user_id', false, true); $table->softDeletes();
$table->string('title', 512)->index(); $table->integer('user_id', false, true);
$table->string('secret', 32)->index(); $table->string('title', 512)->index();
$table->boolean('active')->default(true); $table->string('secret', 32)->index();
$table->unsignedSmallInteger('trigger', false); $table->boolean('active')->default(true);
$table->unsignedSmallInteger('response', false); $table->unsignedSmallInteger('trigger', false);
$table->unsignedSmallInteger('delivery', false); $table->unsignedSmallInteger('response', false);
$table->string('url', 1024); $table->unsignedSmallInteger('delivery', false);
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->string('url', 1024);
$table->unique(['user_id', 'title']); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
} $table->unique(['user_id', 'title']);
); }
);
}
// new webhook_messages table // new webhook_messages table
Schema::create( if (!Schema::hasTable('webhook_messages')) {
'webhook_messages', Schema::create(
static function (Blueprint $table) { 'webhook_messages',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->boolean('sent')->default(false); $table->softDeletes();
$table->boolean('errored')->default(false); $table->boolean('sent')->default(false);
$table->boolean('errored')->default(false);
$table->integer('webhook_id', false, true); $table->integer('webhook_id', false, true);
$table->string('uuid', 64); $table->string('uuid', 64);
$table->longText('message'); $table->longText('message');
$table->foreign('webhook_id')->references('id')->on('webhooks')->onDelete('cascade'); $table->foreign('webhook_id')->references('id')->on('webhooks')->onDelete('cascade');
} }
); );
}
Schema::create( if (!Schema::hasTable('webhook_attempts')) {
'webhook_attempts', Schema::create(
static function (Blueprint $table) { 'webhook_attempts',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('webhook_message_id', false, true); $table->softDeletes();
$table->unsignedSmallInteger('status_code')->default(0); $table->integer('webhook_message_id', false, true);
$table->unsignedSmallInteger('status_code')->default(0);
$table->longText('logs')->nullable(); $table->longText('logs')->nullable();
$table->longText('response')->nullable(); $table->longText('response')->nullable();
$table->foreign('webhook_message_id')->references('id')->on('webhook_messages')->onDelete('cascade'); $table->foreign('webhook_message_id')->references('id')->on('webhook_messages')->onDelete('cascade');
} }
); );
}
} }
} }