get_charset_collate(); $prefix = $wpdb->prefix; // The baseline shape plus the two new columns. Both default, so every existing row stays // valid without being rewritten. $history = "CREATE TABLE {$prefix}wpwand_history ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, template_name varchar(255) NOT NULL, title varchar(255) NOT NULL DEFAULT '', source varchar(32) NOT NULL DEFAULT '', prompt_info longtext NOT NULL, response longtext NOT NULL, created_at timestamp DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) ) {$charset_collate};"; dbDelta($history); // Only rows the column default left empty. A row already carrying a source was written by // the code that knows its own source, and that is the truth. $table = $prefix . 'wpwand_history'; $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL "UPDATE {$table} SET source = 'editor' WHERE source = ''" ); } }