Since I'm lazy all I want to do is a show tables; and then copy this output to some variable inside of some script. Well, and then this script should generate me the statement list I will execute with the MySQL commandline client:
OLD_PREFIX = ""
NEW_PREFIX = "newprefix_"
data=<<-EOD
| aggregator_category_item |
| aggregator_feed |
| aggregator_item |
| search_total |
| sequences |
EOD
tables = []
data.each_line do |line|
if line=~/(#{OLD_PREFIX}\w+)/
puts "RENAME TABLE #{$1} TO #{NEW_PREFIX}#{$1};"
end
end
The data variable here holds the output I got from show tables;. The output of this script will look like this:
RENAME TABLE aggregator_category_item TO newprefix_aggregator_category_item; RENAME TABLE aggregator_feed TO newprefix_aggregator_feed; RENAME TABLE aggregator_item TO newprefix_aggregator_item; RENAME TABLE search_total TO newprefix_search_total; RENAME TABLE sequences TO newprefix_sequences;
Variable regex are ugly ... but sometimes they make things sooooo easy ;)
blog comments powered by Disqus