mina-db_sync 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/README.md +24 -13
- data/lib/mina/db_sync/tasks.rb +39 -4
- data/lib/mina/db_sync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4cde69c976780f629f0c5403d2c8e1353925f0e
|
4
|
+
data.tar.gz: a3863dcae3b267d93a794ca6936dd066975030d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e417dde99c699899f7b38a8b167498f13115256ac45988ca44185044d9f7fb86d2a1b38a2ea7a7c84bd813451099d31b42aa04c90a112a9e10548a1503cc1f03
|
7
|
+
data.tar.gz: 6433cf5a8c85c26c9b627d1bac555d13947036f4d9c29272e25b170f491f2bcfc359633d6fe1086577afefcc686dfc16ab0c4b01d2db5dbfaff1bd10ed5298e9
|
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Copy specific tables between your production and development databases
|
4
4
|
using [Mina](https://github.com/mina-deploy/mina) for your Rails app.
|
5
|
+
All authentication is based on your database.yml files.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
* rsync
|
5
9
|
|
6
10
|
## Installation
|
7
11
|
|
@@ -19,40 +23,47 @@ Or install it yourself as:
|
|
19
23
|
|
20
24
|
$ gem install mina-db_sync
|
21
25
|
|
26
|
+
Now add the following to your config/deploy.rb file:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'mina/db_sync'
|
30
|
+
|
31
|
+
# configure which database you're using:
|
32
|
+
set :db_sync_database, 'postgres' #or 'mysql'
|
33
|
+
|
34
|
+
# optionally turn on debugging, which leaves the sql file after sync:
|
35
|
+
set :db_sync_debug, true
|
36
|
+
```
|
37
|
+
|
22
38
|
## Usage
|
23
39
|
|
24
40
|
Get data from the server to your local db:
|
25
41
|
|
26
42
|
```
|
27
|
-
|
43
|
+
mina db:get_tables
|
28
44
|
```
|
29
45
|
|
30
46
|
Get data from your local db to the server:
|
31
47
|
|
32
48
|
```
|
33
|
-
|
49
|
+
mina db:put_tables
|
34
50
|
```
|
35
51
|
|
36
52
|
You'll be asked to supply the name(s) of any database tables you'd like
|
37
53
|
to be copied over. All data in the target table(s) will be removed as part
|
38
54
|
of the process, so make sure you backup first if you're paranoid.
|
39
55
|
|
40
|
-
|
56
|
+
Or you can specify the tables you want from the beginning:
|
41
57
|
|
42
|
-
|
43
|
-
bundle binstubs mina
|
44
|
-
```
|
58
|
+
$ mina db:get_tables[table1,table2,table3]
|
45
59
|
|
46
|
-
|
60
|
+
If you're using Zsh:
|
47
61
|
|
48
|
-
|
49
|
-
bin/mina db:get_tables
|
50
|
-
bin/mina db:put_tables
|
51
|
-
```
|
62
|
+
$ mina db:get_tables\[table1,table2,table3\]
|
52
63
|
|
53
64
|
## Database Support
|
54
|
-
|
55
|
-
|
65
|
+
* MySQL
|
66
|
+
* Postgresql
|
56
67
|
|
57
68
|
## License
|
58
69
|
|
data/lib/mina/db_sync/tasks.rb
CHANGED
@@ -46,14 +46,15 @@ end
|
|
46
46
|
|
47
47
|
def backup_tables(table_names)
|
48
48
|
db_credentials
|
49
|
-
|
49
|
+
backup_command(table_names)
|
50
50
|
command "gzip -f #{db_file}"
|
51
51
|
end
|
52
52
|
|
53
53
|
def restore_tables
|
54
54
|
db_credentials
|
55
55
|
command %{gunzip -f #{db_archive}}
|
56
|
-
|
56
|
+
restore_command
|
57
|
+
command %{rm #{db_file}} unless fetch(:db_sync_debug)
|
57
58
|
end
|
58
59
|
|
59
60
|
def db_archive
|
@@ -68,11 +69,45 @@ end
|
|
68
69
|
|
69
70
|
def tweak_tables(table_names)
|
70
71
|
if table_names.to_a.empty?
|
71
|
-
STDOUT.write "
|
72
|
+
STDOUT.write "Enter table name(s), separated by a space: "
|
72
73
|
tables = STDIN.gets.strip
|
73
74
|
else
|
74
75
|
tables = table_names.to_a.join(' ')
|
75
76
|
end
|
76
77
|
|
77
|
-
tables
|
78
|
+
return tables if mysql?
|
79
|
+
|
80
|
+
if postgres?
|
81
|
+
return tables.split(' ').map { |table| "--table=#{table}" }.join(' ')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def postgres?
|
86
|
+
fetch(:db_sync_database) == 'postgres'
|
87
|
+
end
|
88
|
+
|
89
|
+
def mysql?
|
90
|
+
fetch(:db_sync_database) == 'mysql'
|
91
|
+
end
|
92
|
+
|
93
|
+
def backup_command(table_names)
|
94
|
+
if postgres?
|
95
|
+
command %{pg_dump --format=c --no-owner #{tweak_tables(table_names)} $DATABASE > #{db_file}}
|
96
|
+
return
|
97
|
+
end
|
98
|
+
|
99
|
+
if mysql?
|
100
|
+
command %{mysqldump -u$USERNAME -p$PASSWORD $DATABASE #{tweak_tables(table_names)} > #{db_file}}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def restore_command
|
105
|
+
if postgres?
|
106
|
+
command %{pg_restore --no-owner --username=$USERNAME --clean --dbname=$DATABASE #{db_file}}
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
if mysql?
|
111
|
+
command %{mysql -u$USERNAME --password=$PASSWORD $DATABASE < #{db_file}}
|
112
|
+
end
|
78
113
|
end
|
data/lib/mina/db_sync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-db_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Floyd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mina
|