HEX
Server: Apache/2
System: Linux server-80-13-140-150.da.direct 5.14.0-362.24.1.el9_3.0.1.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Apr 4 22:31:43 UTC 2024 x86_64
User: cpt (1004)
PHP: 8.1.24
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/cpt/public_html/wp-content/plugins/mailpoet/lib/Migrations/Db/Migration_20221110_151621.php
<?php declare(strict_types = 1);

namespace MailPoet\Migrations\Db;

if (!defined('ABSPATH')) exit;


use MailPoet\Migrator\DbMigration;

/**
 * The "created_at" column must be NULL in some tables to avoid "there can be only one
 * TIMESTAMP column with CURRENT_TIMESTAMP" error on MySQL version < 5.6.5 that occurs
 * even when other timestamp is simply "NOT NULL".
 *
 * Additionally, having multiple timestamp columns with "NOT NULL" seems to produce the
 * following error in some SQL modes:
 *   SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at'"
 */
class Migration_20221110_151621 extends DbMigration {
  public function run(): void {
    $this->createTable('automations', [
      'id int(11) unsigned NOT NULL AUTO_INCREMENT',
      'name varchar(191) NOT NULL',
      'author bigint NOT NULL',
      'status varchar(191) NOT NULL',
      'created_at timestamp NULL', // must be NULL, see comment at the top
      'updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
      'activated_at timestamp NULL',
      'deleted_at timestamp NULL',
      'PRIMARY KEY (id)',
    ]);

    $this->createTable('automation_versions', [
      'id int(11) unsigned NOT NULL AUTO_INCREMENT',
      'automation_id int(11) unsigned NOT NULL',
      'steps longtext',
      'created_at timestamp NULL', // must be NULL, see comment at the top
      'updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
      'PRIMARY KEY (id)',
      'INDEX (automation_id)',
    ]);

    $this->createTable('automation_triggers', [
      'automation_id int(11) unsigned NOT NULL',
      'trigger_key varchar(191)',
      'PRIMARY KEY (automation_id, trigger_key)',
    ]);

    $this->createTable('automation_runs', [
      'id int(11) unsigned NOT NULL AUTO_INCREMENT',
      'automation_id int(11) unsigned NOT NULL',
      'version_id int(11) unsigned NOT NULL',
      'trigger_key varchar(191) NOT NULL',
      'status varchar(191) NOT NULL',
      'created_at timestamp NULL', // must be NULL, see comment at the top
      'updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
      'subjects longtext',
      'next_step_id varchar(191)',
      'PRIMARY KEY (id)',
      'INDEX (automation_id, status)',
    ]);

    $this->createTable('automation_run_logs', [
      'id int(11) unsigned NOT NULL AUTO_INCREMENT',
      'automation_run_id int(11) unsigned NOT NULL',
      'step_id varchar(191) NOT NULL',
      'status varchar(191) NOT NULL',
      'started_at timestamp NOT NULL',
      'completed_at timestamp NULL DEFAULT NULL',
      'error longtext',
      'data longtext',
      'PRIMARY KEY (id)',
      'INDEX (automation_run_id)',
    ]);
  }
}