migration_bundler 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.bundle/config +2 -0
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +49 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +122 -0
- data/Guardfile +8 -0
- data/LICENSE +202 -0
- data/README.md +219 -0
- data/Rakefile +16 -0
- data/bin/mb +6 -0
- data/lib/migration_bundler/actions.rb +38 -0
- data/lib/migration_bundler/cli.rb +355 -0
- data/lib/migration_bundler/databases/abstract_database.rb +54 -0
- data/lib/migration_bundler/databases/cassandra_database.rb +88 -0
- data/lib/migration_bundler/databases/sqlite_database.rb +116 -0
- data/lib/migration_bundler/migrations.rb +52 -0
- data/lib/migration_bundler/project.rb +90 -0
- data/lib/migration_bundler/targets/base.rb +85 -0
- data/lib/migration_bundler/targets/cassandra/cassandra_target.rb +73 -0
- data/lib/migration_bundler/targets/cassandra/create_schema_migrations.cql.erb +16 -0
- data/lib/migration_bundler/targets/cassandra/migration.cql.erb +0 -0
- data/lib/migration_bundler/targets/cocoapods/cocoapods_target.rb +43 -0
- data/lib/migration_bundler/targets/cocoapods/podspec.erb +12 -0
- data/lib/migration_bundler/targets/maven/maven_target.rb +62 -0
- data/lib/migration_bundler/targets/maven/project/.gitignore +6 -0
- data/lib/migration_bundler/targets/maven/project/MonkeyButler.iml +19 -0
- data/lib/migration_bundler/targets/maven/project/build.gradle +54 -0
- data/lib/migration_bundler/targets/sqlite/create_migration_bundler_tables.sql.erb +15 -0
- data/lib/migration_bundler/targets/sqlite/migration.sql.erb +11 -0
- data/lib/migration_bundler/targets/sqlite/sqlite_target.rb +92 -0
- data/lib/migration_bundler/templates/Gemfile.erb +4 -0
- data/lib/migration_bundler/templates/gitignore.erb +1 -0
- data/lib/migration_bundler/util.rb +71 -0
- data/lib/migration_bundler/version.rb +3 -0
- data/lib/migration_bundler.rb +1 -0
- data/migration_bundler.gemspec +33 -0
- data/spec/cli_spec.rb +700 -0
- data/spec/databases/cassandra_database_spec.rb +260 -0
- data/spec/databases/sqlite_database_spec.rb +198 -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/.migration_bundler.yml +9 -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/.migration_bundler.yml +9 -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: 436ba30d0763b80697d248108f716c97cc03c15d
|
4
|
+
data.tar.gz: d0d9e4137171423a8e3a216352b81c47f046ada3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be3ce97159429c2f69e91ccef63593f461416dd3e6a011efdba77c895b56546dfda8fa4695edb58b5e0d1587a975836734063cc5f8de511c4a66f8e5a7ce60c8
|
7
|
+
data.tar.gz: 887a650861bd675b88f74537c72984ef251115b8cf8d4241e8691c0ca0739f6ee6799f906dc289dcd79d48211bc5d5d8a252da00feb26c266d10948a48d8e565
|
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,49 @@
|
|
1
|
+
## v1.3.0
|
2
|
+
|
3
|
+
* Added support for dumping arbitrary sets of tables.
|
4
|
+
* Renamed project to Migration Bundler.
|
5
|
+
|
6
|
+
## v1.2.5
|
7
|
+
|
8
|
+
* Fix bug in Maven push when publishing point releases.
|
9
|
+
|
10
|
+
## v1.2.4
|
11
|
+
|
12
|
+
* Fix bug in Maven generate when creating point releases.
|
13
|
+
|
14
|
+
## v1.2.3
|
15
|
+
|
16
|
+
* Force generate CocoaPods specs by default.
|
17
|
+
|
18
|
+
## v1.2.2
|
19
|
+
|
20
|
+
* Fix accidental prepending of `create_` to new migraiton names.
|
21
|
+
|
22
|
+
## v1.2.1
|
23
|
+
|
24
|
+
* Fix double dumping of the default keyspace when using multiple Cassandra keyspaces.
|
25
|
+
|
26
|
+
## v1.2.0
|
27
|
+
|
28
|
+
* Introduced `mb drop` for dropping a database.
|
29
|
+
* Introduced `mb config` for working with config variables.
|
30
|
+
|
31
|
+
## v1.1.1
|
32
|
+
|
33
|
+
* Include the names of all keyspaces being dumped during a multi-keyspace dump.
|
34
|
+
|
35
|
+
## v1.1.0
|
36
|
+
|
37
|
+
* Added support for dumping additional keyspaces in Cassandra. Keyspaces are specified via the `cassandra.keyspaces` config setting.
|
38
|
+
|
39
|
+
## v1.0.2
|
40
|
+
|
41
|
+
* Explicitly require database classes in database targets to avoid `NameError` exception.
|
42
|
+
|
43
|
+
## v1.0.1
|
44
|
+
|
45
|
+
* Guard against attempts to execute blank Cassandra queries when applying migrations.
|
46
|
+
|
47
|
+
## v1.0.0
|
48
|
+
|
49
|
+
* 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
|
+
migration_bundler (1.3.0)
|
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
|
+
migration_bundler!
|
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/migration_bundler/(.+)\.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,219 @@
|
|
1
|
+
# Migration Bundler
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/migration_bundler.svg)](http://badge.fury.io/rb/migration_bundler)
|
3
|
+
|
4
|
+
Migration Bundler is a database schema management system written in Ruby. It currently supports SQLite and Cassandra database
|
5
|
+
targets. It was built to solve the schema management challenges on the mobile SDK's and server side services developed for
|
6
|
+
the [Layer](http://layer.com) platform.
|
7
|
+
|
8
|
+
Migration Bundler manages a Git repository containing a database schema and an arbitrary number of migrations. The migrations are
|
9
|
+
authored in SQL format and platform specific renderings of the schema and migrations are created via code generation.
|
10
|
+
The current schema and all associated migrations can then be packaged into a release and shipped as a versioned, installable package.
|
11
|
+
|
12
|
+
## Features
|
13
|
+
|
14
|
+
* Manages a Git repository containing a database schema and migrations
|
15
|
+
* Supports SQLite and Cassandra schemas
|
16
|
+
* Generates platform specific database management and migration utilities
|
17
|
+
* Ensures that the current schema and all migrations are valid SQLite
|
18
|
+
* Packages schema and associated migrations into versioned releases
|
19
|
+
* Publishes releases for dependency management via CocoaPods and Maven
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
Migration Bundler requires a modern Ruby runtime (v1.9.x and up) and the following supporting cast:
|
24
|
+
|
25
|
+
* [thor](http://whatisthor.com/) - Toolkit for building powerful commandline utilities
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Migration Bundler is a commandline utility available via the `mb` binary. There are a number of standard commandline
|
30
|
+
switches available that control the defaults and target behavior of a Migration Bundler invocation. You can obtain help directly from the
|
31
|
+
application by executing `mb help`.
|
32
|
+
|
33
|
+
### Initializing a Project
|
34
|
+
|
35
|
+
Creates a new Migration Bundler schema repository at the path specified. Please refer to the documentation below regarding
|
36
|
+
the repository structure.
|
37
|
+
|
38
|
+
`$ mb init [path/to/project]`
|
39
|
+
|
40
|
+
The default database target is SQLite, but you can specify an alternate database by using the `database` switch:
|
41
|
+
|
42
|
+
`$ mb init --database=cassandra://localhost:9042/keyspace`
|
43
|
+
|
44
|
+
### Loading the Schema
|
45
|
+
|
46
|
+
Loads the current schema defined in `schema.sql` into a local database named `database.sqlite`.
|
47
|
+
|
48
|
+
`$ mb load`
|
49
|
+
|
50
|
+
### Creating a Migration
|
51
|
+
|
52
|
+
Creates a new migration file at `migrations/[TIMESTAMP]_[NAME].sql`. Please refer to the documentation below about timestamp
|
53
|
+
and versioning semantics.
|
54
|
+
|
55
|
+
`$ mb create [name]`
|
56
|
+
|
57
|
+
### Displaying Status
|
58
|
+
|
59
|
+
Displays information about the current schema and any unapplied migrations.
|
60
|
+
|
61
|
+
`$ mb status`
|
62
|
+
|
63
|
+
### Applying Migrations
|
64
|
+
|
65
|
+
Applies all pending to a target database by directly executing the SQL migrations.
|
66
|
+
|
67
|
+
`$ mb migrate [target version]`
|
68
|
+
|
69
|
+
### Generating Implementations
|
70
|
+
|
71
|
+
Generates platform specific implementations into `migrations/[migration].m` and `migrations/[migration].java`.
|
72
|
+
|
73
|
+
`$ mb generate`
|
74
|
+
|
75
|
+
### Validating Schema & Migrations
|
76
|
+
|
77
|
+
Validates that the schema loads and all migrations apply forward from a clean database.
|
78
|
+
|
79
|
+
`$ mb validate`
|
80
|
+
|
81
|
+
### Packaging a Release
|
82
|
+
|
83
|
+
Packages a release of the schema by validating the project, generating all implementations, and creating a tag into the
|
84
|
+
project Git repository.
|
85
|
+
|
86
|
+
`$ mb package [version]`
|
87
|
+
|
88
|
+
### Pushing a Release
|
89
|
+
|
90
|
+
Pushes a release to Git, CocoaPods, and Maven.
|
91
|
+
|
92
|
+
`$ mb push [version]`
|
93
|
+
|
94
|
+
## Design & Implementation Details
|
95
|
+
|
96
|
+
Migration Bundler was designed to deliver the following properties:
|
97
|
+
|
98
|
+
1. Provide a simple mechanism for integrating a unified schema into multiple codebases in parallel.
|
99
|
+
1. Support straightforward bootstrapping of a database with the current schema.
|
100
|
+
2. Support easy migrations from any previous version of the schema up to the latest by applying an ordered sequence of migrations.
|
101
|
+
3. Enable reliable, low friction testing of the migration process.
|
102
|
+
4. Support a heavily branched, multi-developer workflow in which multiple developers are evolving the schema in parallel.
|
103
|
+
|
104
|
+
This portion of the document details how Migration Bundler has been implemented to deliver these properties.
|
105
|
+
|
106
|
+
### Project Layout
|
107
|
+
|
108
|
+
A Migration Bundler project is a simple filesystem layout with version control provided by Git. When a new project is
|
109
|
+
initialized, it has the following structure:
|
110
|
+
|
111
|
+
.
|
112
|
+
├── .gitignore
|
113
|
+
├── .migration_bundler.yml
|
114
|
+
├── [project-name].sql
|
115
|
+
├── [project-name].sqlite
|
116
|
+
└── migrations
|
117
|
+
└── <date-created>-create-[project-name].sql
|
118
|
+
|
119
|
+
Subsequent commands will create files into this filesystem and perform manipulations on the database. The schema can be branched, merged, and
|
120
|
+
released using standard Git techniques.
|
121
|
+
|
122
|
+
### Versioning
|
123
|
+
|
124
|
+
The client schema is internally versioned using timestamps. Timestamps are used instead of monotonically incrementing integers because they better
|
125
|
+
support a branched, multi-developer workflow. The latest version of the overall schema is equal to the timestamp of the most recently applied migration.
|
126
|
+
The current schema version of a given database is derivable by examining the `schema_migrations` table, which maintains a record of all migrations that
|
127
|
+
have been applied to the database since its creation.
|
128
|
+
|
129
|
+
The `schema_migrations` table has the following schema:
|
130
|
+
|
131
|
+
```
|
132
|
+
CREATE TABLE schema_migrations(
|
133
|
+
version INTEGER UNIQUE NOT NULL
|
134
|
+
);
|
135
|
+
|
136
|
+
```
|
137
|
+
|
138
|
+
The `version` column encodes the date a migration was created. The presence of a given migration version in the table indicates that the migration
|
139
|
+
has been applied to the parent database.
|
140
|
+
|
141
|
+
#### Computing Origin and Current Version
|
142
|
+
|
143
|
+
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:
|
144
|
+
|
145
|
+
`SELECT MIN(version) FROM schema_migrations`
|
146
|
+
|
147
|
+
The current version of the database is computable by selecting the maximum value for the `version` column present in the `schema_migrations` table:
|
148
|
+
|
149
|
+
`SELECT MAX(version) FROM schema_migrations`
|
150
|
+
|
151
|
+
Note that knowing the current version is not sufficient for computing if the database is fully migrated. This is because migrations that were created
|
152
|
+
in the past may not yet have been merged, released and applied yet.
|
153
|
+
|
154
|
+
#### Computing Unapplied Migrations
|
155
|
+
|
156
|
+
In order to compute the set of migrations that have not yet been applied to a given database, one must take the following steps:
|
157
|
+
|
158
|
+
1. Compute the origin version of the database
|
159
|
+
2. Build a collection of the versions of all known migrations in the current build of the code.
|
160
|
+
3. Build a collection of all migration versions that have already been applied to the database (`SELECT version FROM schema_migrations`);
|
161
|
+
4. Remove any migrations from the list with a version less than the origin version of the database.
|
162
|
+
5. Diff the collections of migrations. The set that remains is the set of unapplied migrations.
|
163
|
+
6. Order the set of unapplied migrations into an array of ascending values and apply them in order from oldest to newest.
|
164
|
+
|
165
|
+
### Migrations
|
166
|
+
|
167
|
+
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
|
168
|
+
from the source SQL files.
|
169
|
+
|
170
|
+
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.
|
171
|
+
This naming convention is of the form "${VERSION_IDENTIFIER}_${MIGRATION_DESCRIPTION_UNDERSCORED}.sql". The `VERSION_IDENTIFIER` is equal to the
|
172
|
+
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,
|
173
|
+
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,
|
174
|
+
while still supporting very straightforward sorting in the database.
|
175
|
+
|
176
|
+
An example migration file might be called: `201405125248499_add_unqiue_constraint_to_streams.sql`
|
177
|
+
|
178
|
+
The implementation of the generated migration class in Objective-C may look like:
|
179
|
+
|
180
|
+
```objc
|
181
|
+
@interface MBAddUniqueConstraintToStreamsMigration : NSObject <MBMigratable>
|
182
|
+
@end
|
183
|
+
|
184
|
+
@implementation LYR_AddUniqueConstraintToStreamsMigration
|
185
|
+
|
186
|
+
+ (NSString *)version
|
187
|
+
{
|
188
|
+
return @"201405125248499";
|
189
|
+
}
|
190
|
+
|
191
|
+
- (BOOL)migrateDatabase:(FMDatabase *)database error:(out NSError *__autoreleasing *)error
|
192
|
+
{
|
193
|
+
// Apply the migration
|
194
|
+
}
|
195
|
+
|
196
|
+
@end
|
197
|
+
```
|
198
|
+
|
199
|
+
Platform specific migrations can also be generated.
|
200
|
+
|
201
|
+
## Companion Projects
|
202
|
+
|
203
|
+
Migration Bundler itself only generates installable packages containing the schema and migrations. To utilize these schemas in an application you'll
|
204
|
+
need support code. The following companion projects are available for this use:
|
205
|
+
|
206
|
+
* [FMDBMigrationManager](https://github.com/layerhq/FMDBMigrationManager) - An Objective-C SQLite migration manager implementation for use with the [FMDB](https://github.com/ccgus/fmdb) library.
|
207
|
+
* [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.
|
208
|
+
|
209
|
+
## Credits
|
210
|
+
|
211
|
+
Blake Watters
|
212
|
+
|
213
|
+
- http://github.com/blakewatters
|
214
|
+
- http://twitter.com/blakewatters
|
215
|
+
- blakewatters@gmail.com
|
216
|
+
|
217
|
+
## License
|
218
|
+
|
219
|
+
Migration Bundler is available under the Apache 2 License. See the LICENSE file for more info.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
desc 'Builds and installs the migration_bundler Gem'
|
8
|
+
task :install do
|
9
|
+
lib = File.expand_path('../lib', __FILE__)
|
10
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
11
|
+
require 'migration_bundler/version'
|
12
|
+
|
13
|
+
system("gem build migration_bundler.gemspec && gem install migration_bundler-#{MigrationBundler::VERSION}.gem")
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :spec
|