| | 491 | |
| | 492 | /** |
| | 493 | * @ticket 20263 |
| | 494 | */ |
| | 495 | function test_query_with_backticks_does_not_cause_a_query_to_alter_all_columns_and_indices_to_run_even_if_none_have_changed() { |
| | 496 | global $wpdb; |
| | 497 | |
| | 498 | $schema = " |
| | 499 | CREATE TABLE {$wpdb->prefix}dbdelta_test2 ( |
| | 500 | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| | 501 | `references` varchar(255) NOT NULL, |
| | 502 | PRIMARY KEY (`id`), |
| | 503 | KEY `compound_key` (`id`,`references`) |
| | 504 | ) |
| | 505 | "; |
| | 506 | |
| | 507 | $wpdb->query( $schema ); |
| | 508 | |
| | 509 | $updates = dbDelta( $schema ); |
| | 510 | |
| | 511 | $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$wpdb->prefix}dbdelta_test2" ); |
| | 512 | $compound_key_index = wp_list_filter( $table_indices, array( 'Key_name' => 'compound_key' ) ); |
| | 513 | |
| | 514 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test2" ); |
| | 515 | |
| | 516 | $this->assertCount( 2, $compound_key_index ); |
| | 517 | $this->assertEmpty( $updates ); |
| | 518 | } |
| | 519 | |
| | 520 | /** |
| | 521 | * @ticket 20263 |
| | 522 | */ |
| | 523 | function test_index_with_reserved_keywords_can_be_created() { |
| | 524 | global $wpdb; |
| | 525 | |
| | 526 | $updates = dbDelta( |
| | 527 | " |
| | 528 | CREATE TABLE {$wpdb->prefix}dbdelta_test ( |
| | 529 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 530 | column_1 varchar(255) NOT NULL, |
| | 531 | column_2 text, |
| | 532 | column_3 blob, |
| | 533 | `references` varchar(255) NOT NULL, |
| | 534 | PRIMARY KEY (id), |
| | 535 | KEY key_1 (column_1), |
| | 536 | KEY compound_key (id , column_1), |
| | 537 | KEY compound_key2 (id,`references`), |
| | 538 | FULLTEXT KEY fulltext_key (column_1) |
| | 539 | ) ENGINE=MyISAM |
| | 540 | " |
| | 541 | ); |
| | 542 | |
| | 543 | $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$wpdb->prefix}dbdelta_test" ); |
| | 544 | |
| | 545 | $this->assertCount( 2, wp_list_filter( $table_indices, array( 'Key_name' => 'compound_key2' ) , 'AND' ) ); |
| | 546 | |
| | 547 | $this->assertSame( |
| | 548 | array( |
| | 549 | "{$wpdb->prefix}dbdelta_test.references" => "Added column {$wpdb->prefix}dbdelta_test.references", |
| | 550 | 0 => "Added index {$wpdb->prefix}dbdelta_test KEY `compound_key2` (`id`,`references`)", |
| | 551 | ), |
| | 552 | $updates |
| | 553 | ); |
| | 554 | } |
| | 555 | |
| | 556 | /** |
| | 557 | * @ticket 20263 |
| | 558 | */ |
| | 559 | function test_wp_get_db_schema_does_no_alter_queries_on_existing_install() { |
| | 560 | $updates = dbDelta( wp_get_db_schema() ); |
| | 561 | |
| | 562 | $this->assertEmpty( $updates ); |
| | 563 | } |
| | 564 | |
| | 565 | /** |
| | 566 | * @ticket 34959 |
| | 567 | */ |
| | 568 | function test_index_col_name_with_order_does_not_recreate_index() { |
| | 569 | global $wpdb; |
| | 570 | |
| | 571 | $updates = dbDelta( |
| | 572 | " |
| | 573 | CREATE TABLE {$wpdb->prefix}dbdelta_test ( |
| | 574 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 575 | column_1 varchar(255) NOT NULL, |
| | 576 | column_2 text, |
| | 577 | column_3 blob, |
| | 578 | PRIMARY KEY (id), |
| | 579 | KEY key_1 (column_1 DESC), |
| | 580 | KEY compound_key (id,column_1 ASC), |
| | 581 | FULLTEXT KEY fulltext_key (column_1) |
| | 582 | ) ENGINE=MyISAM |
| | 583 | " |
| | 584 | ); |
| | 585 | |
| | 586 | $this->assertEmpty( $updates ); |
| | 587 | } |
| | 588 | |
| | 589 | /** |
| | 590 | * @ticket 34873 |
| | 591 | */ |
| | 592 | function test_primary_key_with_single_space_does_not_recreate_index() { |
| | 593 | global $wpdb; |
| | 594 | |
| | 595 | $updates = dbDelta( |
| | 596 | " |
| | 597 | CREATE TABLE {$wpdb->prefix}dbdelta_test ( |
| | 598 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 599 | column_1 varchar(255) NOT NULL, |
| | 600 | column_2 text, |
| | 601 | column_3 blob, |
| | 602 | PRIMARY KEY (id), |
| | 603 | KEY key_1 (column_1), |
| | 604 | KEY compound_key (id,column_1), |
| | 605 | FULLTEXT KEY fulltext_key (column_1) |
| | 606 | ) ENGINE=MyISAM |
| | 607 | " |
| | 608 | ); |
| | 609 | |
| | 610 | $this->assertEmpty( $updates ); |
| | 611 | } |
| | 612 | |
| | 613 | /** |
| | 614 | * @ticket 34869 |
| | 615 | */ |
| | 616 | function test_index_definitions_with_spaces_do_not_recreate_indices() { |
| | 617 | global $wpdb; |
| | 618 | |
| | 619 | $updates = dbDelta( |
| | 620 | " |
| | 621 | CREATE TABLE {$wpdb->prefix}dbdelta_test ( |
| | 622 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 623 | column_1 varchar(255) NOT NULL, |
| | 624 | column_2 text, |
| | 625 | column_3 blob, |
| | 626 | PRIMARY KEY (id), |
| | 627 | KEY key_1 (column_1), |
| | 628 | KEY compound_key (id, column_1), |
| | 629 | FULLTEXT KEY fulltext_key (column_1) |
| | 630 | ) ENGINE=MyISAM |
| | 631 | " |
| | 632 | ); |
| | 633 | |
| | 634 | $this->assertEmpty( $updates ); |
| | 635 | } |
| | 636 | |
| | 637 | /** |
| | 638 | * @ticket 34871 |
| | 639 | */ |
| | 640 | function test_index_types_are_not_case_sensitive_and_do_not_recreate_indices() { |
| | 641 | global $wpdb; |
| | 642 | |
| | 643 | $updates = dbDelta( |
| | 644 | " |
| | 645 | CREATE TABLE {$wpdb->prefix}dbdelta_test ( |
| | 646 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 647 | column_1 varchar(255) NOT NULL, |
| | 648 | column_2 text, |
| | 649 | column_3 blob, |
| | 650 | PRIMARY KEY (id), |
| | 651 | key key_1 (column_1), |
| | 652 | key compound_key (id,column_1), |
| | 653 | FULLTEXT KEY fulltext_key (column_1) |
| | 654 | ) ENGINE=MyISAM |
| | 655 | " |
| | 656 | ); |
| | 657 | |
| | 658 | $this->assertEmpty( $updates ); |
| | 659 | } |
| | 660 | |
| | 661 | /** |
| | 662 | * @ticket 34874 |
| | 663 | */ |
| | 664 | function test_index_names_are_not_case_sensitive_and_do_not_recreate_indices() { |
| | 665 | $this->markTestSkipped(); |
| | 666 | global $wpdb; |
| | 667 | |
| | 668 | $updates = dbDelta( |
| | 669 | " |
| | 670 | CREATE TABLE {$wpdb->prefix}dbdelta_test ( |
| | 671 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 672 | column_1 varchar(255) NOT NULL, |
| | 673 | column_2 text, |
| | 674 | column_3 blob, |
| | 675 | PRIMARY KEY (id), |
| | 676 | KEY key_1 (column_1), |
| | 677 | KEY COMPOUND_KEY (id,column_1), |
| | 678 | FULLTEXT KEY fulltext_key (column_1) |
| | 679 | ) ENGINE=MyISAM |
| | 680 | " |
| | 681 | ); |
| | 682 | |
| | 683 | $this->assertEmpty( $updates ); |
| | 684 | } |