table_syncer 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/PostInstall.txt +3 -4
- data/lib/table_syncer.rb +34 -20
- data/lib/table_syncer/version.rb +1 -1
- data/script/console +0 -0
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- metadata +8 -8
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
==0.3.1 2008-10-15
|
2
|
+
|
3
|
+
* Add a command --inserts_only which only adds to the target table, not deleting anything from it
|
4
|
+
|
1
5
|
==0.3.0 2008-10-15
|
2
6
|
|
3
7
|
* Now uses the more conservative [and slower] query_with_result = true, instead of the faster and potentially scary query_with_result = false -- see http://betterlogic.com/roger/?p=473
|
data/PostInstall.txt
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
+
Welcome to the wonderful world of table syncer:
|
1
2
|
|
2
3
|
For more information on table_syncer, see http://table_syncer.rubyforge.org
|
4
|
+
run table_syncer --help for more info
|
3
5
|
|
4
|
-
|
5
|
-
You can also delete it if you don't want it.
|
6
|
-
|
7
|
-
|
6
|
+
comments/feedback/suggestions rogerpack2005@gmail.com
|
data/lib/table_syncer.rb
CHANGED
@@ -23,39 +23,39 @@
|
|
23
23
|
end
|
24
24
|
require 'optparse'
|
25
25
|
|
26
|
-
# define some databases and how you connect with them
|
26
|
+
# define some databases and how you connect with them
|
27
|
+
# replace with your own
|
27
28
|
local_db = {:host => '127.0.0.1', :user => 'root', :password => '', :db => 'local_leadgen_dev'}
|
28
|
-
ties_db = {:user => 'db_user_name_ex_root', :password => 'mysql_password_for_that_user', :db => 'wilkboar_ties', :ssh_host => 'my_host.com', :ssh_user => 'ssh_login'} # ssh example -- doesn't take passwords here but attempts to create an ssh tunnel for you to that host.
|
29
29
|
|
30
|
-
#
|
30
|
+
# remote host that we'll use SSH tunnels for
|
31
|
+
ties_db = {:user => 'db_user_name_ex_root', :password => 'mysql_password_for_that_user', :db => 'wilkboar_ties', :ssh_host => 'my_host.com', :ssh_user => 'ssh_login'} # ssh example -- no ssh password allowed [here], but it attempts to create an ssh tunnel for you to that host, whence you can enter one.
|
32
|
+
# note: if you have multiple remote hosts then you'll want to assign a different port for each host via :tunnel_local_port_to_use
|
33
|
+
|
34
|
+
# ex: I suppose you wouldn't need an ssh_user if you had pre-established the tunnel youself [ex: if you had already created a tunnel on port 9000 to the remote Mysql port]
|
31
35
|
ties_db_no_host_even = {:user => 'db_user_name_ex_root', :password => 'mysql_password_for_that_user', :db => 'wilkboar_ties', :tunnel_local_port_to_use => 9000}
|
32
|
-
# if you have multiple remote hosts then you'll want to assign a different port for each host
|
33
36
|
|
37
|
+
# how to setup remote ports, custom ssh port, etc.
|
34
38
|
ties_super_advanced = {:user => 'mysql_user', :password => 'mysql_pass_for_that_user', :ssh_host => 'helpme.com', :ssh_port => 888, :ssh_user => 'ssh_login_name', :ssh_local_to_host => '127.0.0.1 -- change if you want it to connect to a different host "from the remote"', :ssh_local_to_port => '4000 instead of the normal 3306'}
|
35
39
|
# ssh_port is the ssh port [instead of 22] for the remote host
|
36
|
-
|
40
|
+
|
41
|
+
# list of db's
|
37
42
|
all_database_names = ['local_db', 'ties_db', 'ties_db_no_host_even', 'ties_super_advanced'] # only used --help command is more useful and can print out the database connection names available -- not necessary
|
38
43
|
|
39
44
|
|
40
|
-
|
41
45
|
|
42
|
-
# setup defaults -- it will use these databases by default unless you specify otherwise on the command line [or use nil for none]
|
46
|
+
# here we'll setup defaults -- it will use these databases by default unless you specify otherwise on the command line [or use nil for none]
|
47
|
+
my_options = {}
|
43
48
|
db_from_name = 'local_db' # replace with yours
|
44
49
|
db_to_name = 'local_db'
|
45
|
-
actually_run_queries = false # default to just previewing -- use --commit to actually run it
|
50
|
+
actually_run_queries = false # default to just previewing -- force use --commit to actually run it
|
46
51
|
verbose = true
|
47
|
-
default_tables_to_sync = nil # replace with default tables to sync,
|
48
|
-
|
49
|
-
|
50
|
-
my_options = {}
|
51
|
-
auto_create_ssh_tunnels = true
|
52
|
-
tables_to_sync = nil # leave as nil--this will be propagated by yours, above, or those passed from the command line
|
53
|
-
# make sure use normal style options, or nothing :)
|
52
|
+
default_tables_to_sync = nil # replace with default tables to sync, ex: ['users']
|
54
53
|
my_options[:skip_the_warning_prompt_for_commit] = false
|
54
|
+
auto_create_ssh_tunnels = true
|
55
55
|
|
56
|
-
# note that ctrl-c doesn't work too well in the middle of this script, but ctrl-z + kill PID does
|
57
56
|
|
58
57
|
# now parse incoming options
|
58
|
+
tables_to_sync = nil # leave as nil--this will be propagated by the defaults, above, or those passed from the command line
|
59
59
|
|
60
60
|
do_structure_sync_only = false
|
61
61
|
|
@@ -101,6 +101,11 @@
|
|
101
101
|
do_structure_sync_only = true
|
102
102
|
end
|
103
103
|
|
104
|
+
|
105
|
+
opts.on('-i', '--inserts_only', 'do_inserts_only') do
|
106
|
+
my_options[:do_inserts_only] = true
|
107
|
+
end
|
108
|
+
|
104
109
|
end.parse!
|
105
110
|
|
106
111
|
# grab the right db's
|
@@ -318,8 +323,13 @@ end
|
|
318
323
|
puts "This may mean a tunnel is not working" if e.error.include?('127.0.0.1')
|
319
324
|
# note that, if you do add ssh -> ssh, you may still only need one connection!
|
320
325
|
if db_from_info[:ssh_host] or db_to_info[:ssh_host]
|
321
|
-
|
322
|
-
|
326
|
+
|
327
|
+
if (db_from_info[:ssh_host] and db_to_info[:ssh_host]) and (db_from_info[:ssh_host] !=- db_to_info[:ssh_host])
|
328
|
+
if(!db_from_info[:tunnel_local_port_to_use] or !db_to_info[:tunnel_local_port_to_use])
|
329
|
+
raise "if you want to connect to two different remote dbs via ssh, you'll need to assign them each a port so they're distinct" # todo: always require different ports
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
323
333
|
ssh_requiring_connection = db_to_info[:ssh_host] ? db_to_info : db_from_info
|
324
334
|
ssh_port = ssh_requiring_connection[:ssh_port]
|
325
335
|
ssh_local_to_port = ssh_requiring_connection[:ssh_local_to_port] || 3306
|
@@ -424,8 +434,11 @@ end
|
|
424
434
|
print "\n" if (count_updated>0 or count_created>0) if verbose
|
425
435
|
|
426
436
|
|
427
|
-
|
428
|
-
|
437
|
+
if(my_options[:do_inserts_only])
|
438
|
+
print "skipping deletions, as you passed in do_inserts_only\n"
|
439
|
+
else
|
440
|
+
count_deleted = all_to_keys_not_yet_processed.length
|
441
|
+
if count_deleted > 0
|
429
442
|
ids = []
|
430
443
|
for id in all_to_keys_not_yet_processed.keys do
|
431
444
|
ids << id
|
@@ -449,6 +462,7 @@ end
|
|
449
462
|
db_to.query query if actually_run_queries
|
450
463
|
example_out_file.write query + ";\n" unless actually_run_queries
|
451
464
|
end
|
465
|
+
end
|
452
466
|
end
|
453
467
|
|
454
468
|
res.free
|
data/lib/table_syncer/version.rb
CHANGED
data/script/console
CHANGED
File without changes
|
data/script/destroy
CHANGED
File without changes
|
data/script/generate
CHANGED
File without changes
|
data/script/txt2html
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_syncer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Pack
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -63,14 +63,14 @@ files:
|
|
63
63
|
- website/template.html.erb
|
64
64
|
has_rdoc: true
|
65
65
|
homepage: http://table-syncer.rubyforge.org
|
66
|
-
post_install_message:
|
66
|
+
post_install_message: |
|
67
|
+
Welcome to the wonderful world of table syncer:
|
67
68
|
|
68
69
|
For more information on table_syncer, see http://table_syncer.rubyforge.org
|
70
|
+
run table_syncer --help for more info
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
comments/feedback/suggestions rogerpack2005@gmail.com
|
73
|
+
|
74
74
|
rdoc_options:
|
75
75
|
- --main
|
76
76
|
- README.rdoc
|
@@ -96,5 +96,5 @@ signing_key:
|
|
96
96
|
specification_version: 2
|
97
97
|
summary: tool to synchronize data across databases
|
98
98
|
test_files:
|
99
|
-
- test/test_table_syncer.rb
|
100
99
|
- test/test_helper.rb
|
100
|
+
- test/test_table_syncer.rb
|