monkey_butler 1.2.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 +7 -0
- data/.bundle/config +2 -0
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +28 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +122 -0
- data/Guardfile +8 -0
- data/LICENSE +202 -0
- data/README.md +221 -0
- data/Rakefile +16 -0
- data/bin/mb +6 -0
- data/lib/monkey_butler.rb +1 -0
- data/lib/monkey_butler/actions.rb +38 -0
- data/lib/monkey_butler/cli.rb +354 -0
- data/lib/monkey_butler/databases/abstract_database.rb +49 -0
- data/lib/monkey_butler/databases/cassandra_database.rb +69 -0
- data/lib/monkey_butler/databases/sqlite_database.rb +105 -0
- data/lib/monkey_butler/migrations.rb +52 -0
- data/lib/monkey_butler/project.rb +90 -0
- data/lib/monkey_butler/targets/base.rb +85 -0
- data/lib/monkey_butler/targets/cassandra/cassandra_target.rb +72 -0
- data/lib/monkey_butler/targets/cassandra/create_schema_migrations.cql.erb +16 -0
- data/lib/monkey_butler/targets/cassandra/migration.cql.erb +0 -0
- data/lib/monkey_butler/targets/cocoapods/cocoapods_target.rb +43 -0
- data/lib/monkey_butler/targets/cocoapods/podspec.erb +12 -0
- data/lib/monkey_butler/targets/maven/maven_target.rb +60 -0
- data/lib/monkey_butler/targets/maven/project/.gitignore +6 -0
- data/lib/monkey_butler/targets/maven/project/MonkeyButler.iml +19 -0
- data/lib/monkey_butler/targets/maven/project/build.gradle +54 -0
- data/lib/monkey_butler/targets/sqlite/create_monkey_butler_tables.sql.erb +15 -0
- data/lib/monkey_butler/targets/sqlite/migration.sql.erb +11 -0
- data/lib/monkey_butler/targets/sqlite/sqlite_target.rb +91 -0
- data/lib/monkey_butler/templates/Gemfile.erb +4 -0
- data/lib/monkey_butler/templates/gitignore.erb +1 -0
- data/lib/monkey_butler/util.rb +71 -0
- data/lib/monkey_butler/version.rb +3 -0
- data/logo.jpg +0 -0
- data/monkey_butler.gemspec +33 -0
- data/spec/cli_spec.rb +700 -0
- data/spec/databases/cassandra_database_spec.rb +241 -0
- data/spec/databases/sqlite_database_spec.rb +181 -0
- data/spec/migrations_spec.rb +4 -0
- data/spec/project_spec.rb +128 -0
- data/spec/sandbox/cassandra/.gitignore +2 -0
- data/spec/sandbox/cassandra/.monkey_butler.yml +7 -0
- data/spec/sandbox/cassandra/migrations/20140523123443021_create_sandbox.cql.sql +14 -0
- data/spec/sandbox/cassandra/sandbox.cql +0 -0
- data/spec/sandbox/sqlite/.gitignore +2 -0
- data/spec/sandbox/sqlite/.monkey_butler.yml +7 -0
- data/spec/sandbox/sqlite/migrations/20140523123443021_create_sandbox.sql +14 -0
- data/spec/sandbox/sqlite/sandbox.sql +0 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/targets/cassandra_target_spec.rb +191 -0
- data/spec/targets/cocoapods_target_spec.rb +197 -0
- data/spec/targets/maven_target_spec.rb +156 -0
- data/spec/targets/sqlite_target_spec.rb +103 -0
- data/spec/util_spec.rb +13 -0
- metadata +260 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8608dfbdf6c5a0ba826db10aab5bcd902cb6a0f5
|
4
|
+
data.tar.gz: 93103df68206b61e6ebb1d4d704ae32355c11965
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40e6e913faded1c3b56690211b91b84b367c7c71172b0e3e7dfcfbb03a89bb2c008cf35401cd0b60a91140c33c3cbb360821e644dec41e6d67198716fbf6000f
|
7
|
+
data.tar.gz: dc075e0fc9b53f2849a674319b62dfa9064b27739561bffb1de7bcbed1b6e85a594400cfca7e0ddc84ad7e9fb3334a277b643abddb6c1ffecd3f698d10bee8bf
|
data/.bundle/config
ADDED
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p481
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
## v1.2.1
|
2
|
+
|
3
|
+
* Fix double dumping of the default keyspace when using multiple Cassandra keyspaces.
|
4
|
+
|
5
|
+
## v1.2.0
|
6
|
+
|
7
|
+
* Introduced `mb drop` for dropping a database.
|
8
|
+
* Introduced `mb config` for working with config variables.
|
9
|
+
|
10
|
+
## v1.1.1
|
11
|
+
|
12
|
+
* Include the names of all keyspaces being dumped during a multi-keyspace dump.
|
13
|
+
|
14
|
+
## v1.1.0
|
15
|
+
|
16
|
+
* Added support for dumping additional keyspaces in Cassandra. Keyspaces are specified via the `cassandra.keyspaces` config setting.
|
17
|
+
|
18
|
+
## v1.0.2
|
19
|
+
|
20
|
+
* Explicitly require database classes in database targets to avoid `NameError` exception.
|
21
|
+
|
22
|
+
## v1.0.1
|
23
|
+
|
24
|
+
* Guard against attempts to execute blank Cassandra queries when applying migrations.
|
25
|
+
|
26
|
+
## v1.0.0
|
27
|
+
|
28
|
+
* Initial public release supporting SQLite and Cassandra.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
monkey_butler (1.2.2)
|
5
|
+
cql-rb (~> 2.0.0)
|
6
|
+
sqlite3 (~> 1.3.9)
|
7
|
+
thor (~> 0.19.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (3.2.18)
|
13
|
+
i18n (~> 0.6, >= 0.6.4)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
byebug (3.1.2)
|
16
|
+
columnize (~> 0.8)
|
17
|
+
debugger-linecache (~> 1.2)
|
18
|
+
celluloid (0.15.2)
|
19
|
+
timers (~> 1.1.0)
|
20
|
+
claide (0.6.1)
|
21
|
+
cocoapods (0.33.1)
|
22
|
+
activesupport (>= 3.2.15, < 4)
|
23
|
+
claide (~> 0.6.1)
|
24
|
+
cocoapods-core (= 0.33.1)
|
25
|
+
cocoapods-downloader (~> 0.6.1)
|
26
|
+
cocoapods-plugins (~> 0.2.0)
|
27
|
+
cocoapods-trunk (~> 0.1.1)
|
28
|
+
cocoapods-try (~> 0.3.0)
|
29
|
+
colored (~> 1.2)
|
30
|
+
escape (~> 0.0.4)
|
31
|
+
json_pure (~> 1.8)
|
32
|
+
nap (~> 0.7)
|
33
|
+
open4 (~> 1.3)
|
34
|
+
xcodeproj (~> 0.17.0)
|
35
|
+
cocoapods-core (0.33.1)
|
36
|
+
activesupport (>= 3.2.15)
|
37
|
+
fuzzy_match (~> 2.0.4)
|
38
|
+
json_pure (~> 1.8)
|
39
|
+
nap (~> 0.5)
|
40
|
+
cocoapods-downloader (0.6.1)
|
41
|
+
cocoapods-plugins (0.2.0)
|
42
|
+
nap
|
43
|
+
cocoapods-trunk (0.1.3)
|
44
|
+
json_pure (~> 1.8)
|
45
|
+
nap (>= 0.6)
|
46
|
+
netrc
|
47
|
+
cocoapods-try (0.3.0)
|
48
|
+
coderay (1.1.0)
|
49
|
+
colored (1.2)
|
50
|
+
columnize (0.8.9)
|
51
|
+
cql-rb (2.0.0)
|
52
|
+
ione (~> 1)
|
53
|
+
debugger-linecache (1.2.0)
|
54
|
+
diff-lcs (1.2.5)
|
55
|
+
docile (1.1.3)
|
56
|
+
escape (0.0.4)
|
57
|
+
ffi (1.9.3)
|
58
|
+
formatador (0.2.5)
|
59
|
+
fuzzy_match (2.0.4)
|
60
|
+
guard (2.6.1)
|
61
|
+
formatador (>= 0.2.4)
|
62
|
+
listen (~> 2.7)
|
63
|
+
lumberjack (~> 1.0)
|
64
|
+
pry (>= 0.9.12)
|
65
|
+
thor (>= 0.18.1)
|
66
|
+
guard-rspec (4.2.10)
|
67
|
+
guard (~> 2.1)
|
68
|
+
rspec (>= 2.14, < 4.0)
|
69
|
+
i18n (0.6.9)
|
70
|
+
ione (1.1.2)
|
71
|
+
json_pure (1.8.1)
|
72
|
+
listen (2.7.7)
|
73
|
+
celluloid (>= 0.15.2)
|
74
|
+
rb-fsevent (>= 0.9.3)
|
75
|
+
rb-inotify (>= 0.9)
|
76
|
+
lumberjack (1.0.6)
|
77
|
+
method_source (0.8.2)
|
78
|
+
multi_json (1.10.1)
|
79
|
+
nap (0.8.0)
|
80
|
+
netrc (0.7.7)
|
81
|
+
open4 (1.3.4)
|
82
|
+
pry (0.10.0)
|
83
|
+
coderay (~> 1.1.0)
|
84
|
+
method_source (~> 0.8.1)
|
85
|
+
slop (~> 3.4)
|
86
|
+
rake (10.3.2)
|
87
|
+
rb-fsevent (0.9.4)
|
88
|
+
rb-inotify (0.9.5)
|
89
|
+
ffi (>= 0.5.0)
|
90
|
+
rspec (2.14.1)
|
91
|
+
rspec-core (~> 2.14.0)
|
92
|
+
rspec-expectations (~> 2.14.0)
|
93
|
+
rspec-mocks (~> 2.14.0)
|
94
|
+
rspec-core (2.14.8)
|
95
|
+
rspec-expectations (2.14.5)
|
96
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
97
|
+
rspec-mocks (2.14.6)
|
98
|
+
simplecov (0.8.2)
|
99
|
+
docile (~> 1.1.0)
|
100
|
+
multi_json
|
101
|
+
simplecov-html (~> 0.8.0)
|
102
|
+
simplecov-html (0.8.0)
|
103
|
+
slop (3.5.0)
|
104
|
+
sqlite3 (1.3.9)
|
105
|
+
thor (0.19.1)
|
106
|
+
timers (1.1.0)
|
107
|
+
xcodeproj (0.17.0)
|
108
|
+
activesupport (~> 3.0)
|
109
|
+
colored (~> 1.2)
|
110
|
+
|
111
|
+
PLATFORMS
|
112
|
+
ruby
|
113
|
+
|
114
|
+
DEPENDENCIES
|
115
|
+
bundler (~> 1.6)
|
116
|
+
byebug (~> 3.1.2)
|
117
|
+
cocoapods (~> 0.33.1)
|
118
|
+
guard-rspec (~> 4.2.9)
|
119
|
+
monkey_butler!
|
120
|
+
rake
|
121
|
+
rspec (~> 2.14.1)
|
122
|
+
simplecov (~> 0.8.2)
|
data/Guardfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/monkey_butler/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2009-2012 The RestKit Project
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
# Monkey Butler
|
2
|
+
[](http://badge.fury.io/rb/monkey_butler)
|
3
|
+
|
4
|
+

|
5
|
+
|
6
|
+
Monkey Butler is a database schema management system written in Ruby. It currently supports SQLite and Cassandra database
|
7
|
+
targets. It was built to solve the schema management challenges on the mobile SDK's and server side services developed for
|
8
|
+
the [Layer](http://layer.com) platform.
|
9
|
+
|
10
|
+
Monkey Butler manages a Git repository containing a database schema and an arbitrary number of migrations. The migrations are
|
11
|
+
authored in SQL format and platform specific renderings of the schema and migrations are created via code generation.
|
12
|
+
The current schema and all associated migrations can then be packaged into a release and shipped as a versioned, installable package.
|
13
|
+
|
14
|
+
## Features
|
15
|
+
|
16
|
+
* Manages a Git repository containing a database schema and migrations
|
17
|
+
* Supports SQLite and Cassandra schemas
|
18
|
+
* Generates platform specific database management and migration utilities
|
19
|
+
* Ensures that the current schema and all migrations are valid SQLite
|
20
|
+
* Packages schema and associated migrations into versioned releases
|
21
|
+
* Publishes releases for dependency management via CocoaPods and Maven
|
22
|
+
|
23
|
+
## Requirements
|
24
|
+
|
25
|
+
Monkey Butler requires a modern Ruby runtime (v1.9.x and up) and the following supporting cast:
|
26
|
+
|
27
|
+
* [thor](http://whatisthor.com/) - Toolkit for building powerful commandline utilities
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Monkey Butler is a commandline utility available via the `mb` binary. There are a number of standard commandline
|
32
|
+
switches available that control the defaults and target behavior of a Monkey Butler invocation. You can obtain help directly from the
|
33
|
+
application by executing `mb help`.
|
34
|
+
|
35
|
+
### Initializing a Project
|
36
|
+
|
37
|
+
Creates a new Monkey Butler schema repository at the path specified. Please refer to the documentation below regarding
|
38
|
+
the repository structure.
|
39
|
+
|
40
|
+
`$ mb init [path/to/project]`
|
41
|
+
|
42
|
+
The default database target is SQLite, but you can specify an alternate database by using the `database` switch:
|
43
|
+
|
44
|
+
`$ mb init --database=cassandra://localhost:9042/keyspace`
|
45
|
+
|
46
|
+
### Loading the Schema
|
47
|
+
|
48
|
+
Loads the current schema defined in `schema.sql` into a local database named `database.sqlite`.
|
49
|
+
|
50
|
+
`$ mb load`
|
51
|
+
|
52
|
+
### Creating a Migration
|
53
|
+
|
54
|
+
Creates a new migration file at `migrations/[TIMESTAMP]_[NAME].sql`. Please refer to the documentation below about timestamp
|
55
|
+
and versioning semantics.
|
56
|
+
|
57
|
+
`$ mb create [name]`
|
58
|
+
|
59
|
+
### Displaying Status
|
60
|
+
|
61
|
+
Displays information about the current schema and any unapplied migrations.
|
62
|
+
|
63
|
+
`$ mb status`
|
64
|
+
|
65
|
+
### Applying Migrations
|
66
|
+
|
67
|
+
Applies all pending to a target database by directly executing the SQL migrations.
|
68
|
+
|
69
|
+
`$ mb migrate [target version]`
|
70
|
+
|
71
|
+
### Generating Implementations
|
72
|
+
|
73
|
+
Generates platform specific implementations into `migrations/[migration].m` and `migrations/[migration].java`.
|
74
|
+
|
75
|
+
`$ mb generate`
|
76
|
+
|
77
|
+
### Validating Schema & Migrations
|
78
|
+
|
79
|
+
Validates that the schema loads and all migrations apply forward from a clean database.
|
80
|
+
|
81
|
+
`$ mb validate`
|
82
|
+
|
83
|
+
### Packaging a Release
|
84
|
+
|
85
|
+
Packages a release of the schema by validating the project, generating all implementations, and creating a tag into the
|
86
|
+
project Git repository.
|
87
|
+
|
88
|
+
`$ mb package [version]`
|
89
|
+
|
90
|
+
### Pushing a Release
|
91
|
+
|
92
|
+
Pushes a release to Git, CocoaPods, and Maven.
|
93
|
+
|
94
|
+
`$ mb push [version]`
|
95
|
+
|
96
|
+
## Design & Implementation Details
|
97
|
+
|
98
|
+
Monkey Butler was designed to deliver the following properties:
|
99
|
+
|
100
|
+
1. Provide a simple mechanism for integrating a unified schema into multiple codebases in parallel.
|
101
|
+
1. Support straightforward bootstrapping of a database with the current schema.
|
102
|
+
2. Support easy migrations from any previous version of the schema up to the latest by applying an ordered sequence of migrations.
|
103
|
+
3. Enable reliable, low friction testing of the migration process.
|
104
|
+
4. Support a heavily branched, multi-developer workflow in which multiple developers are evolving the schema in parallel.
|
105
|
+
|
106
|
+
This portion of the document details how Monkey Butler has been implemented to deliver these properties.
|
107
|
+
|
108
|
+
### Project Layout
|
109
|
+
|
110
|
+
A Monkey Butler project is a simple filesystem layout with version control provided by Git. When a new project is
|
111
|
+
initialized, it has the following structure:
|
112
|
+
|
113
|
+
.
|
114
|
+
├── .gitignore
|
115
|
+
├── .monkey_butler.yml
|
116
|
+
├── [project-name].sql
|
117
|
+
├── [project-name].sqlite
|
118
|
+
└── migrations
|
119
|
+
└── <date-created>-create-[project-name].sql
|
120
|
+
|
121
|
+
Subsequent commands will create files into this filesystem and perform manipulations on the database. The schema can be branched, merged, and
|
122
|
+
released using standard Git techniques.
|
123
|
+
|
124
|
+
### Versioning
|
125
|
+
|
126
|
+
The client schema is internally versioned using timestamps. Timestamps are used instead of monotonically incrementing integers because they better
|
127
|
+
support a branched, multi-developer workflow. The latest version of the overall schema is equal to the timestamp of the most recently applied migration.
|
128
|
+
The current schema version of a given database is derivable by examining the `schema_migrations` table, which maintains a record of all migrations that
|
129
|
+
have been applied to the database since its creation.
|
130
|
+
|
131
|
+
The `schema_migrations` table has the following schema:
|
132
|
+
|
133
|
+
```
|
134
|
+
CREATE TABLE schema_migrations(
|
135
|
+
version INTEGER UNIQUE NOT NULL
|
136
|
+
);
|
137
|
+
|
138
|
+
```
|
139
|
+
|
140
|
+
The `version` column encodes the date a migration was created. The presence of a given migration version in the table indicates that the migration
|
141
|
+
has been applied to the parent database.
|
142
|
+
|
143
|
+
#### Computing Origin and Current Version
|
144
|
+
|
145
|
+
To compute the "origin version" (the version of the schema at the time the database was created), select the minimum value for the `version` column in the `schema_migrations` table:
|
146
|
+
|
147
|
+
`SELECT MIN(version) FROM schema_migrations`
|
148
|
+
|
149
|
+
The current version of the database is computable by selecting the maximum value for the `version` column present in the `schema_migrations` table:
|
150
|
+
|
151
|
+
`SELECT MAX(version) FROM schema_migrations`
|
152
|
+
|
153
|
+
Note that knowing the current version is not sufficient for computing if the database is fully migrated. This is because migrations that were created
|
154
|
+
in the past may not yet have been merged, released and applied yet.
|
155
|
+
|
156
|
+
#### Computing Unapplied Migrations
|
157
|
+
|
158
|
+
In order to compute the set of migrations that have not yet been applied to a given database, one must take the following steps:
|
159
|
+
|
160
|
+
1. Compute the origin version of the database
|
161
|
+
2. Build a collection of the versions of all known migrations in the current build of the code.
|
162
|
+
3. Build a collection of all migration versions that have already been applied to the database (`SELECT version FROM schema_migrations`);
|
163
|
+
4. Remove any migrations from the list with a version less than the origin version of the database.
|
164
|
+
5. Diff the collections of migrations. The set that remains is the set of unapplied migrations.
|
165
|
+
6. Order the set of unapplied migrations into an array of ascending values and apply them in order from oldest to newest.
|
166
|
+
|
167
|
+
### Migrations
|
168
|
+
|
169
|
+
Migrations are authored in pure SQL. A code generation process is used to platform-specific, executable implementation of the migrations in Java and Objective-C
|
170
|
+
from the source SQL files.
|
171
|
+
|
172
|
+
The SQL migration files are named by concatenating a timestamp version with a brief textual description of the database change they introduce to the system.
|
173
|
+
This naming convention is of the form "${VERSION_IDENTIFIER}_${MIGRATION_DESCRIPTION_UNDERSCORED}.sql". The `VERSION_IDENTIFIER` is equal to the
|
174
|
+
following invocation of the `date` utility (on platforms with GNU coreutils): `date +"%Y%m%d%H%M%S%3N"` This date format includes the year, month, day, hour, minute,
|
175
|
+
second and three digits of milliseconds. This ensures that there is very little chance of overlap no matter how many developers are working on the schema,
|
176
|
+
while still supporting very straightforward sorting in the database.
|
177
|
+
|
178
|
+
An example migration file might be called: `201405125248499_add_unqiue_constraint_to_streams.sql`
|
179
|
+
|
180
|
+
The implementation of the generated migration class in Objective-C may look like:
|
181
|
+
|
182
|
+
```objc
|
183
|
+
@interface MBAddUniqueConstraintToStreamsMigration : NSObject <MBMigratable>
|
184
|
+
@end
|
185
|
+
|
186
|
+
@implementation LYR_AddUniqueConstraintToStreamsMigration
|
187
|
+
|
188
|
+
+ (NSString *)version
|
189
|
+
{
|
190
|
+
return @"201405125248499";
|
191
|
+
}
|
192
|
+
|
193
|
+
- (BOOL)migrateDatabase:(FMDatabase *)database error:(out NSError *__autoreleasing *)error
|
194
|
+
{
|
195
|
+
// Apply the migration
|
196
|
+
}
|
197
|
+
|
198
|
+
@end
|
199
|
+
```
|
200
|
+
|
201
|
+
Platform specific migrations can also be generated.
|
202
|
+
|
203
|
+
## Companion Projects
|
204
|
+
|
205
|
+
Monkey Butler itself only generates installable packages containing the schema and migrations. To utilize these schemas in an application you'll
|
206
|
+
need support code. The following companion projects are available for this use:
|
207
|
+
|
208
|
+
* [FMDBMigrationManager](https://github.com/layerhq/FMDBMigrationManager) - An Objective-C SQLite migration manager implementation for use with the [FMDB](https://github.com/ccgus/fmdb) library.
|
209
|
+
* [SQLiteMigrationManager](https://github.com/layerhq/SQLiteMigrationManager) - A Java SQLite migration manager implementation for the Android [SQLiteDatabase](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html) interface.
|
210
|
+
|
211
|
+
## Credits
|
212
|
+
|
213
|
+
Blake Watters
|
214
|
+
|
215
|
+
- http://github.com/blakewatters
|
216
|
+
- http://twitter.com/blakewatters
|
217
|
+
- blakewatters@gmail.com
|
218
|
+
|
219
|
+
## License
|
220
|
+
|
221
|
+
Monkey Butler is available under the Apache 2 License. See the LICENSE file for more info.
|