Project

General

Profile

Feature #12598 » sign-up-sheets-primary-key.php

Create primary keys on sign-up-sheets tables - Boone Gorges, 2020-04-17 10:57 AM

 
1
<?php
2

    
3
global $wpdb;
4

    
5
$tables = $wpdb->get_col( "SHOW TABLES LIKE '%dls_sus%'" );
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 PRIMARY KEY (id)" );
12
	WP_CLI::log( $table );
13
}
(8-8/9)