Created
September 19, 2024 06:58
-
-
Save peterjaap/8b3682aa99a044d5d4ca46511a03f25e to your computer and use it in GitHub Desktop.
Query to remove Magento 2 sequence tables for non-existing stores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @tables = NULL; | |
SELECT GROUP_CONCAT(table_schema, '.`', TABLE_NAME, '`') INTO @tables FROM ( | |
SELECT * | |
FROM information_schema.tables AS t | |
WHERE t.table_schema = 'DB NAME' | |
AND t.table_name REGEXP "^sequence_(.+)_[0-9]+" | |
AND SUBSTRING_INDEX(t.table_name, '_', -1) NOT IN (SELECT DISTINCT store_id FROM sales_sequence_meta) | |
) TT; | |
SET @tables = CONCAT('DROP TABLE ', @tables); | |
SELECT @tables; | |
PREPARE stmt1 FROM @tables; | |
EXECUTE stmt1; | |
DEALLOCATE PREPARE stmt1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment