migration_bundler 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +2 -0
  3. data/.gitignore +3 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +49 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +122 -0
  8. data/Guardfile +8 -0
  9. data/LICENSE +202 -0
  10. data/README.md +219 -0
  11. data/Rakefile +16 -0
  12. data/bin/mb +6 -0
  13. data/lib/migration_bundler/actions.rb +38 -0
  14. data/lib/migration_bundler/cli.rb +355 -0
  15. data/lib/migration_bundler/databases/abstract_database.rb +54 -0
  16. data/lib/migration_bundler/databases/cassandra_database.rb +88 -0
  17. data/lib/migration_bundler/databases/sqlite_database.rb +116 -0
  18. data/lib/migration_bundler/migrations.rb +52 -0
  19. data/lib/migration_bundler/project.rb +90 -0
  20. data/lib/migration_bundler/targets/base.rb +85 -0
  21. data/lib/migration_bundler/targets/cassandra/cassandra_target.rb +73 -0
  22. data/lib/migration_bundler/targets/cassandra/create_schema_migrations.cql.erb +16 -0
  23. data/lib/migration_bundler/targets/cassandra/migration.cql.erb +0 -0
  24. data/lib/migration_bundler/targets/cocoapods/cocoapods_target.rb +43 -0
  25. data/lib/migration_bundler/targets/cocoapods/podspec.erb +12 -0
  26. data/lib/migration_bundler/targets/maven/maven_target.rb +62 -0
  27. data/lib/migration_bundler/targets/maven/project/.gitignore +6 -0
  28. data/lib/migration_bundler/targets/maven/project/MonkeyButler.iml +19 -0
  29. data/lib/migration_bundler/targets/maven/project/build.gradle +54 -0
  30. data/lib/migration_bundler/targets/sqlite/create_migration_bundler_tables.sql.erb +15 -0
  31. data/lib/migration_bundler/targets/sqlite/migration.sql.erb +11 -0
  32. data/lib/migration_bundler/targets/sqlite/sqlite_target.rb +92 -0
  33. data/lib/migration_bundler/templates/Gemfile.erb +4 -0
  34. data/lib/migration_bundler/templates/gitignore.erb +1 -0
  35. data/lib/migration_bundler/util.rb +71 -0
  36. data/lib/migration_bundler/version.rb +3 -0
  37. data/lib/migration_bundler.rb +1 -0
  38. data/migration_bundler.gemspec +33 -0
  39. data/spec/cli_spec.rb +700 -0
  40. data/spec/databases/cassandra_database_spec.rb +260 -0
  41. data/spec/databases/sqlite_database_spec.rb +198 -0
  42. data/spec/migrations_spec.rb +4 -0
  43. data/spec/project_spec.rb +128 -0
  44. data/spec/sandbox/cassandra/.gitignore +2 -0
  45. data/spec/sandbox/cassandra/.migration_bundler.yml +9 -0
  46. data/spec/sandbox/cassandra/migrations/20140523123443021_create_sandbox.cql.sql +14 -0
  47. data/spec/sandbox/cassandra/sandbox.cql +0 -0
  48. data/spec/sandbox/sqlite/.gitignore +2 -0
  49. data/spec/sandbox/sqlite/.migration_bundler.yml +9 -0
  50. data/spec/sandbox/sqlite/migrations/20140523123443021_create_sandbox.sql +14 -0
  51. data/spec/sandbox/sqlite/sandbox.sql +0 -0
  52. data/spec/spec_helper.rb +103 -0
  53. data/spec/targets/cassandra_target_spec.rb +191 -0
  54. data/spec/targets/cocoapods_target_spec.rb +197 -0
  55. data/spec/targets/maven_target_spec.rb +156 -0
  56. data/spec/targets/sqlite_target_spec.rb +103 -0
  57. data/spec/util_spec.rb +13 -0
  58. metadata +260 -0
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+ require 'migration_bundler/targets/sqlite/sqlite_target'
3
+ require 'migration_bundler/databases/sqlite_database'
4
+
5
+ describe MigrationBundler::Targets::SqliteTarget do
6
+ let(:thor_class) { MigrationBundler::CLI }
7
+ let!(:project_root) { clone_temp_sandbox }
8
+ let(:project) { MigrationBundler::Project.load(project_root) }
9
+ let(:schema_path) { File.join(project_root, project.schema_path) }
10
+ let(:db_path) { File.join(project_root, 'sandbox.sqlite') }
11
+
12
+ describe "#new" do
13
+ it "generates a new migration with the given name" do
14
+ invoke!(%w{new add_column_to_table})
15
+ migration = Dir.entries(File.join(project_root, 'migrations')).detect { |f| f =~ /add_column_to_table\.sql/ }
16
+ migration.should_not be_nil
17
+ end
18
+ end
19
+
20
+ describe '#dump' do
21
+ before(:each) do
22
+ db = MigrationBundler::Databases::SqliteDatabase.new(URI(db_path))
23
+ db.drop
24
+ db.execute_migration MigrationBundler::Util.strip_leading_whitespace(
25
+ <<-SQL
26
+ #{MigrationBundler::Databases::SqliteDatabase.create_schema_migrations_sql}
27
+ CREATE TABLE table1(version INTEGER UNIQUE NOT NULL, name STRING NOT NULL);
28
+ CREATE TABLE table2(version INTEGER UNIQUE NOT NULL, name STRING NOT NULL);
29
+ CREATE INDEX name1 ON table1(name);
30
+ CREATE VIEW full_name AS SELECT table1.name || table2.name AS full_name FROM table1, table2;
31
+ CREATE TRIGGER kill_overlapping_names AFTER DELETE ON table1
32
+ BEGIN
33
+ DELETE FROM table2 WHERE name = OLD.name;
34
+ END;
35
+ INSERT INTO schema_migrations(version) VALUES (201405233443021)
36
+ SQL
37
+ )
38
+ end
39
+
40
+ let(:dumped_schema) { File.read(schema_path) }
41
+
42
+ it "dumps tables" do
43
+ output = invoke!(%w{dump})
44
+ dumped_schema.should =~ /CREATE TABLE schema_migrations/
45
+ output[:stdout].should =~ /wrote table: schema_migrations/
46
+ dumped_schema.should =~ /CREATE TABLE table1\(version INTEGER UNIQUE NOT NULL, name STRING NOT NULL\);/
47
+ output[:stdout].should =~ /wrote table: table1/
48
+ dumped_schema.should =~ /CREATE TABLE table2\(version INTEGER UNIQUE NOT NULL, name STRING NOT NULL\);/
49
+ output[:stdout].should =~ /wrote table: table2/
50
+ end
51
+
52
+ it "dumps indexes" do
53
+ output = invoke!(%w{dump})
54
+ dumped_schema.should =~ /CREATE INDEX name1 ON table1\(name\);/
55
+ output[:stdout].should =~ /wrote index: name1/
56
+ end
57
+
58
+ it "dumps triggers" do
59
+ output = invoke!(%w{dump})
60
+ dumped_schema.should =~ /CREATE TRIGGER kill_overlapping_names AFTER DELETE ON table1/
61
+ output[:stdout].should =~ /wrote trigger: kill_overlapping_names/
62
+ end
63
+
64
+ it "dumps views" do
65
+ output = invoke!(%w{dump})
66
+ dumped_schema.should =~ /CREATE VIEW full_name AS SELECT table1.name || table2.name AS full_name FROM table1, table2;/
67
+ output[:stdout].should =~ /wrote view: full_name/
68
+ end
69
+
70
+ it "dumps rows from schema_migrations" do
71
+ output = invoke!(%w{dump})
72
+ dumped_schema.should =~ /INSERT INTO schema_migrations \(version\) VALUES \(201405233443021\);/
73
+ output[:stdout].should =~ /wrote 1 rows./
74
+ end
75
+
76
+ it "informs the user of completion" do
77
+ output = invoke!(%w{dump})
78
+ output[:stdout].should =~ /Dump complete. Schema written to sandbox\.sql/
79
+ end
80
+
81
+ context "when given a database parameter" do
82
+ it "dumps the specified database" do
83
+ output = invoke!(%W{dump -d #{db_path}})
84
+ output[:stdout].should =~ /Dumping schema from database '#{db_path}'/
85
+ end
86
+
87
+ context "that does not exist" do
88
+ it "fails with error" do
89
+ output = invoke!(%w{dump -d /tmp/invalid_path})
90
+ output[:stderr].should =~ /Cannot dump database: no file at path '\/tmp\/invalid_path'/
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "#drop" do
97
+ it "truncates the database file" do
98
+ File.open(db_path, 'w+') { |f| f << "test" }
99
+ output = invoke!(%w{drop})
100
+ File.size(db_path).should == 0
101
+ end
102
+ end
103
+ end
data/spec/util_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MigrationBundler::Util do
4
+ describe '#migrations_by_version' do
5
+ it "returns a Hash keyed by version" do
6
+ paths = %w{migrations/20140523123443021_create_sandbox.sql migrations/20140523123845031_add_comments_table.sql}
7
+ hash = MigrationBundler::Util.migrations_by_version(paths)
8
+ hash.size.should == 2
9
+ hash[20140523123443021].should == 'migrations/20140523123443021_create_sandbox.sql'
10
+ hash[20140523123845031].should == 'migrations/20140523123845031_add_comments_table.sql'
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,260 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: migration_bundler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Blake Watters
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: cql-rb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.14.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 4.2.9
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 4.2.9
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.8.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 0.8.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 3.1.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 3.1.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: cocoapods
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 0.33.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 0.33.1
153
+ description: Migration Bundler is a complete database schema management system providing
154
+ migrations, dump/load, and packaging of schema artifacts.
155
+ email: blake@layer.com
156
+ executables:
157
+ - mb
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - .bundle/config
162
+ - .gitignore
163
+ - .ruby-version
164
+ - CHANGELOG.md
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - Guardfile
168
+ - LICENSE
169
+ - README.md
170
+ - Rakefile
171
+ - bin/mb
172
+ - lib/migration_bundler.rb
173
+ - lib/migration_bundler/actions.rb
174
+ - lib/migration_bundler/cli.rb
175
+ - lib/migration_bundler/databases/abstract_database.rb
176
+ - lib/migration_bundler/databases/cassandra_database.rb
177
+ - lib/migration_bundler/databases/sqlite_database.rb
178
+ - lib/migration_bundler/migrations.rb
179
+ - lib/migration_bundler/project.rb
180
+ - lib/migration_bundler/targets/base.rb
181
+ - lib/migration_bundler/targets/cassandra/cassandra_target.rb
182
+ - lib/migration_bundler/targets/cassandra/create_schema_migrations.cql.erb
183
+ - lib/migration_bundler/targets/cassandra/migration.cql.erb
184
+ - lib/migration_bundler/targets/cocoapods/cocoapods_target.rb
185
+ - lib/migration_bundler/targets/cocoapods/podspec.erb
186
+ - lib/migration_bundler/targets/maven/maven_target.rb
187
+ - lib/migration_bundler/targets/maven/project/.gitignore
188
+ - lib/migration_bundler/targets/maven/project/MonkeyButler.iml
189
+ - lib/migration_bundler/targets/maven/project/build.gradle
190
+ - lib/migration_bundler/targets/sqlite/create_migration_bundler_tables.sql.erb
191
+ - lib/migration_bundler/targets/sqlite/migration.sql.erb
192
+ - lib/migration_bundler/targets/sqlite/sqlite_target.rb
193
+ - lib/migration_bundler/templates/Gemfile.erb
194
+ - lib/migration_bundler/templates/gitignore.erb
195
+ - lib/migration_bundler/util.rb
196
+ - lib/migration_bundler/version.rb
197
+ - migration_bundler.gemspec
198
+ - spec/cli_spec.rb
199
+ - spec/databases/cassandra_database_spec.rb
200
+ - spec/databases/sqlite_database_spec.rb
201
+ - spec/migrations_spec.rb
202
+ - spec/project_spec.rb
203
+ - spec/sandbox/cassandra/.gitignore
204
+ - spec/sandbox/cassandra/.migration_bundler.yml
205
+ - spec/sandbox/cassandra/migrations/20140523123443021_create_sandbox.cql.sql
206
+ - spec/sandbox/cassandra/sandbox.cql
207
+ - spec/sandbox/sqlite/.gitignore
208
+ - spec/sandbox/sqlite/.migration_bundler.yml
209
+ - spec/sandbox/sqlite/migrations/20140523123443021_create_sandbox.sql
210
+ - spec/sandbox/sqlite/sandbox.sql
211
+ - spec/spec_helper.rb
212
+ - spec/targets/cassandra_target_spec.rb
213
+ - spec/targets/cocoapods_target_spec.rb
214
+ - spec/targets/maven_target_spec.rb
215
+ - spec/targets/sqlite_target_spec.rb
216
+ - spec/util_spec.rb
217
+ homepage: http://github.com/layerhq/migration_bundler
218
+ licenses:
219
+ - Apache 2
220
+ metadata: {}
221
+ post_install_message:
222
+ rdoc_options: []
223
+ require_paths:
224
+ - lib
225
+ required_ruby_version: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ required_rubygems_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - '>='
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ requirements: []
236
+ rubyforge_project:
237
+ rubygems_version: 2.0.14
238
+ signing_key:
239
+ specification_version: 4
240
+ summary: A flexible database schema management system.
241
+ test_files:
242
+ - spec/cli_spec.rb
243
+ - spec/databases/cassandra_database_spec.rb
244
+ - spec/databases/sqlite_database_spec.rb
245
+ - spec/migrations_spec.rb
246
+ - spec/project_spec.rb
247
+ - spec/sandbox/cassandra/.gitignore
248
+ - spec/sandbox/cassandra/.migration_bundler.yml
249
+ - spec/sandbox/cassandra/migrations/20140523123443021_create_sandbox.cql.sql
250
+ - spec/sandbox/cassandra/sandbox.cql
251
+ - spec/sandbox/sqlite/.gitignore
252
+ - spec/sandbox/sqlite/.migration_bundler.yml
253
+ - spec/sandbox/sqlite/migrations/20140523123443021_create_sandbox.sql
254
+ - spec/sandbox/sqlite/sandbox.sql
255
+ - spec/spec_helper.rb
256
+ - spec/targets/cassandra_target_spec.rb
257
+ - spec/targets/cocoapods_target_spec.rb
258
+ - spec/targets/maven_target_spec.rb
259
+ - spec/targets/sqlite_target_spec.rb
260
+ - spec/util_spec.rb