Project

General

Profile

newsletters-lite-primary-key.php

Add missing rel_id primary key column to newsletters-lite tables - Boone Gorges, 2020-04-08 12:46 PM

 
1
<?php
2

    
3
global $wpdb;
4

    
5
$tables = $wpdb->get_col( "SHOW TABLES LIKE '%wpmlfieldslists%'" );
6
foreach ( $tables as $table ) {
7
        if ( $wpdb->get_row( "SHOW INDEX FROM {$table} WHERE Key_name = 'PRIMARY'" ) ) {
8
                WP_CLI::log( "$table already has primary key" );
9
                continue;
10
        }
11
        $wpdb->query( "ALTER TABLE {$table} ADD COLUMN rel_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
12
        WP_CLI::log( "Will add primary key to $table" );
13
}