| @@ 733-757 (lines=25) @@ | ||
| 730 | /** |
|
| 731 | * {@inheritdoc} |
|
| 732 | */ |
|
| 733 | protected function getDropForeignKeyByColumnsInstructions($tableName, $columns) |
|
| 734 | { |
|
| 735 | $instructions = new AlterInstructions(); |
|
| 736 | ||
| 737 | foreach ($columns as $column) { |
|
| 738 | $rows = $this->fetchAll(sprintf( |
|
| 739 | "SELECT CONSTRAINT_NAME |
|
| 740 | FROM information_schema.KEY_COLUMN_USAGE |
|
| 741 | WHERE TABLE_SCHEMA = CURRENT_SCHEMA() |
|
| 742 | AND TABLE_NAME IS NOT NULL |
|
| 743 | AND TABLE_NAME = '%s' |
|
| 744 | AND COLUMN_NAME = '%s' |
|
| 745 | ORDER BY POSITION_IN_UNIQUE_CONSTRAINT", |
|
| 746 | $tableName, |
|
| 747 | $column |
|
| 748 | )); |
|
| 749 | ||
| 750 | foreach ($rows as $row) { |
|
| 751 | $newInstr = $this->getDropForeignKeyInstructions($tableName, $row['constraint_name']); |
|
| 752 | $instructions->merge($newInstr); |
|
| 753 | } |
|
| 754 | } |
|
| 755 | ||
| 756 | return $instructions; |
|
| 757 | } |
|
| 758 | ||
| 759 | /** |
|
| 760 | * {@inheritdoc} |
|
| @@ 851-879 (lines=29) @@ | ||
| 848 | /** |
|
| 849 | * {@inheritdoc} |
|
| 850 | */ |
|
| 851 | protected function getDropForeignKeyByColumnsInstructions($tableName, $columns) |
|
| 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 | } |
|
| 880 | ||
| 881 | /** |
|
| 882 | * {@inheritdoc} |
|