From 33b91e09e52020a3102d3f4ab19a1651b6369a0e Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Thu, 5 Dec 2024 22:33:45 +0100 Subject: [PATCH] feat: migrate old email notification settings from the teams table --- ...notification_settings_from_teams_table.php | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 database/migrations/2024_12_05_212546_migrate_email_notification_settings_from_teams_table.php diff --git a/database/migrations/2024_12_05_212546_migrate_email_notification_settings_from_teams_table.php b/database/migrations/2024_12_05_212546_migrate_email_notification_settings_from_teams_table.php new file mode 100644 index 000000000..243a72b21 --- /dev/null +++ b/database/migrations/2024_12_05_212546_migrate_email_notification_settings_from_teams_table.php @@ -0,0 +1,115 @@ +emailNotificationSettings()->updateOrCreate( + ['team_id' => $team->id], + [ + 'smtp_enabled' => $team->smtp_enabled ?? false, + 'smtp_from_address' => $team->smtp_from_address, + 'smtp_from_name' => $team->smtp_from_name, + 'smtp_recipients' => $team->smtp_recipients, + 'smtp_host' => $team->smtp_host, + 'smtp_port' => $team->smtp_port, + 'smtp_encryption' => $team->smtp_encryption, + 'smtp_username' => $team->smtp_username, + 'smtp_password' => $team->smtp_password, + 'smtp_timeout' => $team->smtp_timeout, + + 'use_instance_email_settings' => $team->use_instance_email_settings ?? false, + + 'resend_enabled' => $team->resend_enabled ?? false, + 'resend_api_key' => $team->resend_api_key, + + 'deployment_success_email_notification' => $team->smtp_notifications_deployments ?? false, + 'deployment_failure_email_notification' => $team->smtp_notifications_deployments ?? true, + 'backup_success_email_notification' => $team->smtp_notifications_database_backups ?? false, + 'backup_failure_email_notification' => $team->smtp_notifications_database_backups ?? true, + 'scheduled_task_success_email_notification' => $team->smtp_notifications_scheduled_tasks ?? false, + 'scheduled_task_failure_email_notification' => $team->smtp_notifications_scheduled_tasks ?? true, + 'status_change_email_notification' => $team->smtp_notifications_status_changes ?? false, + 'server_disk_usage_email_notification' => true, + ] + ); + } + + Schema::table('teams', function (Blueprint $table) { + $table->dropColumn([ + 'smtp_enabled', + 'smtp_from_address', + 'smtp_from_name', + 'smtp_recipients', + 'smtp_host', + 'smtp_port', + 'smtp_encryption', + 'smtp_username', + 'smtp_password', + 'smtp_timeout', + 'use_instance_email_settings', + 'resend_enabled', + 'resend_api_key', + 'smtp_notifications_deployments', + 'smtp_notifications_database_backups', + 'smtp_notifications_scheduled_tasks', + 'smtp_notifications_status_changes', + ]); + }); + } + + public function down(): void + { + Schema::table('teams', function (Blueprint $table) { + $table->boolean('smtp_enabled')->default(false); + $table->string('smtp_from_address')->nullable(); + $table->string('smtp_from_name')->nullable(); + $table->string('smtp_recipients')->nullable(); + $table->string('smtp_host')->nullable(); + $table->integer('smtp_port')->nullable(); + $table->string('smtp_encryption')->nullable(); + $table->text('smtp_username')->nullable(); + $table->text('smtp_password')->nullable(); + $table->integer('smtp_timeout')->nullable(); + $table->boolean('use_instance_email_settings')->default(false); + $table->boolean('resend_enabled')->default(false); + $table->text('resend_api_key')->nullable(); + $table->boolean('smtp_notifications_deployments')->default(false); + $table->boolean('smtp_notifications_database_backups')->default(true); + $table->boolean('smtp_notifications_scheduled_tasks')->default(false); + $table->boolean('smtp_notifications_status_changes')->default(false); + }); + + $teams = Team::with('emailNotificationSettings')->get(); + foreach ($teams as $team) { + if ($settings = $team->emailNotificationSettings) { + $team->update([ + 'smtp_enabled' => $settings->smtp_enabled, + 'smtp_from_address' => $settings->smtp_from_address, + 'smtp_from_name' => $settings->smtp_from_name, + 'smtp_recipients' => $settings->smtp_recipients, + 'smtp_host' => $settings->smtp_host, + 'smtp_port' => $settings->smtp_port, + 'smtp_encryption' => $settings->smtp_encryption, + 'smtp_username' => $settings->smtp_username, + 'smtp_password' => $settings->smtp_password, + 'smtp_timeout' => $settings->smtp_timeout, + 'use_instance_email_settings' => $settings->use_instance_email_settings, + 'resend_enabled' => $settings->resend_enabled, + 'resend_api_key' => $settings->resend_api_key, + 'smtp_notifications_deployments' => $settings->deployment_success_email_notification, + 'smtp_notifications_database_backups' => $settings->backup_success_email_notification, + 'smtp_notifications_scheduled_tasks' => $settings->scheduled_task_success_email_notification, + 'smtp_notifications_status_changes' => $settings->status_change_email_notification, + ]); + } + } + } +};