Skip to:
Content

BuddyPress.org

Ticket #6346: 6346.01.patch

File 6346.01.patch, 5.6 KB (added by johnjamesjacoby, 10 years ago)

First pass

  • src/bp-core/admin/bp-core-admin-schema.php

     
    2727}
    2828
    2929/**
     30 * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be
     31 * concerned about that. As of 4.2, however, we moved to utf8mb4, which uses
     32 * 4 bytes per character. This means that an index which used to have room for
     33 * floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
     34 *
     35 * @since BuddyPress (2.3.0)
     36 *
     37 * @return int
     38 */
     39function bp_get_max_index_length() {
     40        return 191;
     41}
     42
     43/**
    3044 * Main installer
    3145 *
    3246 * Can be passed an optional array of components to explicitly run installation
     
    95109        $sql             = array();
    96110        $charset_collate = bp_core_set_charset();
    97111        $bp_prefix       = bp_core_get_table_prefix();
     112        $max_index       = bp_get_max_index_length();
    98113
    99114        $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications (
    100115                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    115130                        ) {$charset_collate};";
    116131
    117132        $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications_meta (
    118                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     133                                id bigint(20) unsigned NOT NULL auto_increment,
    119134                                notification_id bigint(20) NOT NULL,
    120135                                meta_key varchar(255) DEFAULT NULL,
    121136                                meta_value longtext DEFAULT NULL,
     137                                PRIMARY KEY (id),
    122138                                KEY notification_id (notification_id),
    123                                 KEY meta_key (meta_key)
     139                                KEY meta_key (meta_key({$max_index}))
    124140                        ) {$charset_collate};";
    125141
    126142        dbDelta( $sql );
     
    139155        $sql             = array();
    140156        $charset_collate = bp_core_set_charset();
    141157        $bp_prefix       = bp_core_get_table_prefix();
     158        $max_index       = bp_get_max_index_length();
    142159
    143160        $sql[] = "CREATE TABLE {$bp_prefix}bp_activity (
    144161                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    168185                        ) {$charset_collate};";
    169186
    170187        $sql[] = "CREATE TABLE {$bp_prefix}bp_activity_meta (
    171                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     188                                id bigint(20) unsigned NOT NULL auto_increment,
    172189                                activity_id bigint(20) NOT NULL,
    173190                                meta_key varchar(255) DEFAULT NULL,
    174191                                meta_value longtext DEFAULT NULL,
     192                                PRIMARY KEY (id),
    175193                                KEY activity_id (activity_id),
    176                                 KEY meta_key (meta_key)
     194                                KEY meta_key (meta_key({$max_index}))
    177195                        ) {$charset_collate};";
    178196
    179197        dbDelta( $sql );
     
    220238        $sql             = array();
    221239        $charset_collate = bp_core_set_charset();
    222240        $bp_prefix       = bp_core_get_table_prefix();
     241        $max_index       = bp_get_max_index_length();
    223242
    224243        $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
    225244                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    256275                        ) {$charset_collate};";
    257276
    258277        $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_groupmeta (
    259                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     278                                id bigint(20) unsigned NOT NULL auto_increment,
    260279                                group_id bigint(20) NOT NULL,
    261280                                meta_key varchar(255) DEFAULT NULL,
    262281                                meta_value longtext DEFAULT NULL,
     282                                PRIMARY KEY (id),
    263283                                KEY group_id (group_id),
    264                                 KEY meta_key (meta_key)
     284                                KEY meta_key (meta_key({$max_index}))
    265285                        ) {$charset_collate};";
    266286
    267287        dbDelta( $sql );
     
    280300        $sql             = array();
    281301        $charset_collate = bp_core_set_charset();
    282302        $bp_prefix       = bp_core_get_table_prefix();
     303        $max_index       = bp_get_max_index_length();
    283304
    284305        $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
    285306                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    316337                        ) {$charset_collate};";
    317338
    318339        $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_meta (
    319                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     340                                id bigint(20) unsigned NOT NULL auto_increment,
    320341                                message_id bigint(20) NOT NULL,
    321342                                meta_key varchar(255) DEFAULT NULL,
    322343                                meta_value longtext DEFAULT NULL,
     344                                PRIMARY KEY (id),
    323345                                KEY message_id (message_id),
    324                                 KEY meta_key (meta_key)
     346                                KEY meta_key (meta_key({$max_index}))
    325347                        ) {$charset_collate};";
    326348
    327349        dbDelta( $sql );
     
    342364        $sql             = array();
    343365        $charset_collate = bp_core_set_charset();
    344366        $bp_prefix       = bp_core_get_table_prefix();
     367        $max_index       = bp_get_max_index_length();
    345368
    346369        // These values should only be updated if they are not already present
    347370        if ( ! bp_get_option( 'bp-xprofile-base-group-name' ) ) {
     
    392415                        ) {$charset_collate};";
    393416
    394417        $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta (
    395                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     418                                id bigint(20) unsigned NOT NULL auto_increment,
    396419                                object_id bigint(20) NOT NULL,
    397420                                object_type varchar(150) NOT NULL,
    398421                                meta_key varchar(255) DEFAULT NULL,
    399422                                meta_value longtext DEFAULT NULL,
     423                                PRIMARY KEY (id),
    400424                                KEY object_id (object_id),
    401                                 KEY meta_key (meta_key)
     425                                KEY meta_key (meta_key({$max_index}))
    402426                        ) {$charset_collate};";
    403427
    404428        dbDelta( $sql );
     
    430454        $sql             = array();
    431455        $charset_collate = bp_core_set_charset();
    432456        $bp_prefix       = bp_core_get_table_prefix();
     457        $max_index       = bp_get_max_index_length();
    433458
    434459        $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
    435460                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     
    440465                        ) {$charset_collate};";
    441466
    442467        $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta (
    443                                 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     468                                id bigint(20) unsigned NOT NULL auto_increment,
    444469                                blog_id bigint(20) NOT NULL,
    445470                                meta_key varchar(255) DEFAULT NULL,
    446471                                meta_value longtext DEFAULT NULL,
     472                                PRIMARY KEY (id),
    447473                                KEY blog_id (blog_id),
    448                                 KEY meta_key (meta_key)
     474                                KEY meta_key (meta_key({$max_index}))
    449475                        ) {$charset_collate};";
    450476
    451477        dbDelta( $sql );