prefix = $wpdb->prefix . 'mailpoet_automation_'; $this->wpdb = $wpdb; } public function createSchema(): void { $this->runQuery(" CREATE TABLE {$this->prefix}workflows ( id int(11) unsigned NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, status varchar(255) NOT NULL, created_at timestamp NOT NULL, updated_at timestamp NOT NULL, deleted_at timestamp NULL, trigger_keys longtext NOT NULL, steps longtext, PRIMARY KEY (id) ); "); $this->runQuery(" CREATE TABLE {$this->prefix}workflow_runs ( id int(11) unsigned NOT NULL AUTO_INCREMENT, workflow_id int(11) unsigned NOT NULL, trigger_key int(11) unsigned NOT NULL, status varchar(255) NOT NULL, created_at timestamp NOT NULL, updated_at timestamp NOT NULL, PRIMARY KEY (id) ); "); } public function deleteSchema(): void { $this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflows"); $this->runQuery("DROP TABLE IF EXISTS {$this->prefix}workflow_runs"); } public function hasSchema(): bool { $pattern = str_replace('_', '\\_', $this->prefix) . '%'; return $this->runQuery("SHOW TABLES LIKE '$pattern'") > 0; } private function runQuery(string $query): int { $this->wpdb->hide_errors(); $result = $this->wpdb->query($query); if ($result === false) { throw Exceptions::migrationFailed($this->wpdb->last_error ?: 'Unknown error'); } return $result === true ? 0 : (int)$result; } }