| @@ 855-876 (lines=22) @@ | ||
| 852 | { |
|
| 853 | $instructions = new AlterInstructions(); |
|
| 854 | ||
| 855 | foreach ($columns as $column) { |
|
| 856 | $rows = $this->fetchAll(sprintf( |
|
| 857 | "SELECT |
|
| 858 | tc.constraint_name, |
|
| 859 | tc.table_name, kcu.column_name, |
|
| 860 | ccu.table_name AS referenced_table_name, |
|
| 861 | ccu.column_name AS referenced_column_name |
|
| 862 | FROM |
|
| 863 | information_schema.table_constraints AS tc |
|
| 864 | JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name |
|
| 865 | JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name |
|
| 866 | WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s' and ccu.column_name='%s' |
|
| 867 | ORDER BY kcu.ordinal_position", |
|
| 868 | $tableName, |
|
| 869 | $column |
|
| 870 | )); |
|
| 871 | foreach ($rows as $row) { |
|
| 872 | $instructions->merge( |
|
| 873 | $this->getDropForeignKeyInstructions($tableName, $row['constraint_name']) |
|
| 874 | ); |
|
| 875 | } |
|
| 876 | } |
|
| 877 | ||
| 878 | return $instructions; |
|
| 879 | } |
|
| @@ 669-686 (lines=18) @@ | ||
| 666 | { |
|
| 667 | $instructions = new AlterInstructions(); |
|
| 668 | ||
| 669 | foreach ($columns as $column) { |
|
| 670 | $rows = $this->fetchAll(sprintf( |
|
| 671 | "SELECT |
|
| 672 | CONSTRAINT_NAME |
|
| 673 | FROM information_schema.KEY_COLUMN_USAGE |
|
| 674 | WHERE REFERENCED_TABLE_SCHEMA = DATABASE() |
|
| 675 | AND REFERENCED_TABLE_NAME IS NOT NULL |
|
| 676 | AND TABLE_NAME = '%s' |
|
| 677 | AND COLUMN_NAME = '%s' |
|
| 678 | ORDER BY POSITION_IN_UNIQUE_CONSTRAINT", |
|
| 679 | $tableName, |
|
| 680 | $column |
|
| 681 | )); |
|
| 682 | ||
| 683 | foreach ($rows as $row) { |
|
| 684 | $instructions->merge($this->getDropForeignKeyInstructions($tableName, $row['CONSTRAINT_NAME'])); |
|
| 685 | } |
|
| 686 | } |
|
| 687 | ||
| 688 | if (empty($instructions->getAlterParts())) { |
|
| 689 | throw new \InvalidArgumentException(sprintf( |
|
| @@ 693-710 (lines=18) @@ | ||
| 690 | ||
| 691 | return; |
|
| 692 | } else { |
|
| 693 | foreach ($columns as $column) { |
|
| 694 | $rows = $this->fetchAll(sprintf( |
|
| 695 | "SELECT a.CONSTRAINT_NAME, a.TABLE_NAME, b.COLUMN_NAME, |
|
| 696 | (SELECT c.TABLE_NAME from ALL_CONS_COLUMNS c |
|
| 697 | WHERE c.CONSTRAINT_NAME = a.R_CONSTRAINT_NAME) referenced_table_name, |
|
| 698 | (SELECT c.COLUMN_NAME from ALL_CONS_COLUMNS c |
|
| 699 | WHERE c.CONSTRAINT_NAME = a.R_CONSTRAINT_NAME) referenced_column_name |
|
| 700 | FROM all_constraints a JOIN ALL_CONS_COLUMNS b ON a.CONSTRAINT_NAME = b.CONSTRAINT_NAME |
|
| 701 | WHERE a.table_name = '%s' |
|
| 702 | AND CONSTRAINT_TYPE = 'R' |
|
| 703 | AND COLUMN_NAME = '%s'", |
|
| 704 | $tableName, |
|
| 705 | $column |
|
| 706 | )); |
|
| 707 | foreach ($rows as $row) { |
|
| 708 | $this->dropForeignKey($tableName, $columns, $row['CONSTRAINT_NAME']); |
|
| 709 | } |
|
| 710 | } |
|
| 711 | } |
|
| 712 | } |
|
| 713 | ||