mysqlknife 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Mysqlknife
4
- class Swap
5
- def initialize(options = {})
6
- databases = options[:databases].split(',')
7
- @db_from = databases[0]
8
- @db_to = databases[1]
9
- @conn_from = Connection.new(options, @db_from)
10
- @conn_to = Connection.new(options, @db_to)
11
- @from = Sql.new(@db_from)
12
- @to = Sql.new(@db_to)
13
- end
14
-
15
- def all
16
- sql = []
17
-
18
- # Swap tables.
19
- tables_from = @conn_from.execute(@from.tables)
20
- tables_from = tables_from.map { |f| f['name'] } if tables_from
21
- tables_to = @conn_to.execute(@to.tables)
22
- tables_to = tables_to.map { |t| t['name'] } if tables_to
23
- views_from = @conn_from.execute(@from.views)
24
- views_to = @conn_to.execute(@to.views)
25
-
26
- if tables_from && tables_to
27
- swap = tables_from & tables_to
28
- rename = (tables_from - tables_to) + (tables_to - tables_from)
29
-
30
- unless swap.empty?
31
- swap.map do | table |
32
- sql << @to.swap_table(@db_from, table)
33
- end
34
- end
35
-
36
- unless rename.empty?
37
- rename.map do | table |
38
- if tables_from.include?(table)
39
- sql << @from.rename_table(@db_to, table)
40
- else
41
- sql << @to.rename_table(@db_from, table)
42
- end
43
- end
44
- end
45
- end
46
-
47
- # Drop views and create new views in another DB.
48
- sql << @from.use
49
- views_from.each do | view |
50
- sql << @from.drop_view(view['name'])
51
- end
52
- views_to.each do | view |
53
- sql << @from.create_view(view['name'], view['code'])
54
- end
55
-
56
- sql << @to.use
57
- views_to.each do | view |
58
- sql << @to.drop_view(view['name'])
59
- end
60
- views_from.each do | view |
61
- sql << @to.create_view(view['name'], view['code'])
62
- end
63
-
64
- sql
65
- end
66
- end
67
- end