Project

General

Profile

Feature #12598 » statpress-primary-key.php

Add primary key to statpress tables - Boone Gorges, 2020-04-08 11:37 AM

 
1
<?php
2

    
3
global $wpdb;
4

    
5
$tables = $wpdb->get_col( "SHOW TABLES LIKE '%statpress%'" );
6
foreach ( $tables as $table ) {
7
	if ( $wpdb->get_row( "SHOW INDEX FROM {$table} WHERE Key_name = 'PRIMARY'" ) ) {
8
		continue;
9
	}
10
	$wpdb->query( "ALTER TABLE {$table} ADD PRIMARY KEY (id)" );
11
	WP_CLI::log( $table );
12
}
(5-5/9)