# Update Process

This guide walks you through the process of updating MailTrixy to a newer version. Always review the Change Log before updating to understand what has changed and whether there are any breaking changes.

## Before Updating

Before starting the update process, create backups of all critical data. This ensures you can restore your installation if anything goes wrong.

> IMPORTANT: Never skip the backup step. Updates may include database migrations that alter your data structure, and a backup is the only way to fully recover if issues arise.

You can create backups from your hosting control panel (most hosting providers have a one-click backup feature in cPanel / hPanel):

- Back up your database - Use phpMyAdmin (available in cPanel/hPanel) to export your database.
- Back up your .env file - Download the `.env` file from your hosting root directory to your computer. This contains your database credentials, API keys, email account settings, and AI provider configurations.
- Back up your storage folder - Download or compress the `storage/app` directory which contains all uploaded files (attachments, contact imports, avatars, etc.).
- Back up any customized files - If you have modified any Blade views, configuration files, or other application files, note them down and back them up separately
- Note your current version - Check your current version so you can reference the changelog for all changes between your version and the latest

## In-App Update

MailTrixy includes a built-in updater accessible from the admin panel. This is the recommended method for most users.

### Step 1: Backup

Before proceeding, ensure you have created a full backup of your database, `.env` file, and `storage/` directory as described in the Before Updating section above.

### Step 2: Upload the Update ZIP

Download the latest version ZIP from CodeCanyon. In the admin panel, navigate to Settings → System Update and upload the update ZIP file using the provided uploader.

### Step 3: Apply the Update

Click the "Apply Update" button. The system will extract the update files and replace the application code. Your `.env` file and `storage/` directory will not be modified.

### Step 4: Run Migrations

After the files are updated, the system will prompt you to run database migrations. Click "Run Migrations" to apply any new database schema changes. This will only run migrations that have not been executed yet.

### Step 5: Finalize

The updater will automatically clear application caches and restart queue workers. Verify that the admin dashboard loads correctly and key features (email sync, campaigns, AI replies) are working as expected.

## Rollback (In-App Update)

If something goes wrong during the in-app update, restore your previous installation from the backups you created:

1. Restore your database backup using phpMyAdmin
2. Restore the previous application files from your backup
3. Verify the admin dashboard loads correctly and key features are working

## Manual Update

If the in-app updater is not available or you prefer manual control, follow these steps.

### Step 1: Download the Latest Version

Download the latest version of MailTrixy from CodeCanyon. Go to your CodeCanyon downloads page and click the "Download" button for MailTrixy.

### Step 2: Extract Files

Extract the downloaded ZIP archive to a temporary directory on your computer.

### Step 3: Replace Application Files

Upload the new files from the update ZIP to your hosting using your hosting File Manager (cPanel/hPanel), overwriting the existing files. Do not overwrite or delete the following:

- `.env` - Your environment configuration (database credentials, app key, API keys, etc.)
- `storage/` - Your uploaded files, email attachments, logs, and cached data

> Note: All PHP dependencies and frontend assets are pre-built and included in the update package. You do not need to run Composer or NPM commands.

### Step 4: Import the Database Upgrade File

For upgrading from version 1.0 to 1.1, import the following SQL file into your database using phpMyAdmin (available in cPanel/hPanel):

`database/upgrade-1.0-to-1.1.sql`

Open phpMyAdmin, select your MailTrixy database, click the Import tab, choose the `upgrade-1.0-to-1.1.sql` file from the update package, and click Go. This will apply the schema changes required for version 1.1.

> IMPORTANT: Make sure you have backed up your database before importing this file. The upgrade SQL modifies your existing data structure.

### Step 5: Clear Application Caches

From the admin panel, navigate to Settings → System and click Clear Cache to clear all application caches. This ensures the new code runs with fresh configuration.

### Step 6: Verify the Update

Verify the following after completing the update:

- Admin dashboard loads correctly
- You can log in and navigate all sections
- Email sync is functioning (check connected accounts)
- Campaign sending works as expected
- AI features are generating replies
- Queue workers are processing jobs
- Payment gateways are functional (test a checkout flow if possible)

## Important Notes

> Critical: Pay close attention to these guidelines to avoid data loss.

- Never delete your .env file during updates - This file contains your database credentials, API keys, email account configurations, AI provider settings, and application key. Losing it will break your installation
- Never delete the storage directory - This directory contains all uploaded files (email attachments, contact imports, avatars), application logs, and cached files. Deleting it means losing all user-uploaded content
- Always import the database upgrade file after updating - New versions may include database schema changes. Skipping the upgrade SQL will cause errors
- Clear all caches after update - Stale cached configurations, routes, and views can cause unexpected behavior with new code
- Check the changelog for breaking changes - Some updates may require additional manual steps such as new environment variables, configuration changes, or data migrations. Always review the Change Log before updating