Feature #12598 » newsletters-lite-primary-key.php
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 |
}
|