From 317335e79ff40c27169e28b41c87cc13e1b0ec46 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 23 Mar 2023 17:40:03 -0700 Subject: [PATCH] Allow the migration of sqlite databases --- .../2021_04_14_180125_add_ids_to_tables.php | 7 +++++- ..._adds_webhook_option_to_settings_table.php | 23 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/database/migrations/2021_04_14_180125_add_ids_to_tables.php b/database/migrations/2021_04_14_180125_add_ids_to_tables.php index 07172164fe..bac56466ce 100644 --- a/database/migrations/2021_04_14_180125_add_ids_to_tables.php +++ b/database/migrations/2021_04_14_180125_add_ids_to_tables.php @@ -22,7 +22,7 @@ class AddIdsToTables extends Migration Schema::table('password_resets', function (Blueprint $table) { // Add the id column to the password_resets table if it doesn't yet have one - if (! Schema::hasColumn('password_resets', 'id')) { + if (! Schema::hasColumn('password_resets', 'id') && $this->notUsingSqlite()) { $table->increments('id'); } }); @@ -47,4 +47,9 @@ class AddIdsToTables extends Migration } }); } + + private function notUsingSqlite() + { + return Schema::connection($this->getConnection())->getConnection()->getDriverName() !== 'sqlite'; + } } diff --git a/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.php b/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.php index c3409c9d6f..269a625182 100644 --- a/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.php +++ b/database/migrations/2023_02_28_173527_adds_webhook_option_to_settings_table.php @@ -13,12 +13,27 @@ class AddsWebhookOptionToSettingsTable extends Migration */ public function up() { + /** + * So...you're probably wondering why this isn't all in one Schema::table()... + * Turns out we'll get the following error: + * "SQLite doesn't support multiple calls to dropColumn / renameColumn in a single modification." + * if we're running sqlite so a solution is to make multiple calls. + * ¯\_(ツ)_/¯ + */ Schema::table('settings', function (Blueprint $table) { - $table->string('webhook_selected')->after('slack_botname')->default('slack')->nullable(); - $table->renameColumn('slack_botname', 'webhook_botname'); - $table->renameColumn('slack_endpoint', 'webhook_endpoint'); - $table->renameColumn('slack_channel', 'webhook_channel'); + $table->string('webhook_selected')->after('slack_botname')->default('slack')->nullable(); + }); + Schema::table('settings', function (Blueprint $table) { + $table->renameColumn('slack_botname', 'webhook_botname'); + }); + + Schema::table('settings', function (Blueprint $table) { + $table->renameColumn('slack_endpoint', 'webhook_endpoint'); + }); + + Schema::table('settings', function (Blueprint $table) { + $table->renameColumn('slack_channel', 'webhook_channel'); }); }