Project

General

Profile

ninja-forms-primary-key.php

Set primary key on ninja-forms tables. - Boone Gorges, 2020-04-17 11:47 AM

 
1
<?php
2

    
3
global $wpdb;
4

    
5
$tables = $wpdb->get_col( "SHOW TABLES LIKE '%nf3_%'" );
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
}