shearwater 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,17 +9,17 @@ module Shearwater
9
9
  def migrated!(id)
10
10
  execute(
11
11
  "INSERT INTO #{@column_family} (version, migrated_at) VALUES (?, ?)",
12
- id, Time.now
12
+ id.to_i, Time.now
13
13
  )
14
14
  end
15
15
 
16
16
  def rolled_back!(id)
17
- execute("DELETE FROM #{@column_family} WHERE version = ?", id)
17
+ execute("DELETE FROM #{@column_family} WHERE version = ?", id.to_i)
18
18
  end
19
19
 
20
20
  def migrated?(id)
21
21
  !!execute(
22
- "SELECT migrated_at FROM #{@column_family} WHERE version = ?", id
22
+ "SELECT migrated_at FROM #{@column_family} WHERE version = ?", id.to_i
23
23
  ).fetch_row.to_hash['migrated_at']
24
24
  end
25
25
 
@@ -21,6 +21,7 @@ module Shearwater
21
21
  def rollback(step = 1)
22
22
  step.times do
23
23
  id = @backend.last_migration
24
+ break if id.nil?
24
25
  migration = migrations[id]
25
26
  say "Rolling back #{migration.class.name}"
26
27
  migration.down
@@ -1,5 +1,5 @@
1
1
  module Shearwater
2
2
 
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
 
5
5
  end
@@ -32,27 +32,35 @@ describe Shearwater::Migrator do
32
32
  end
33
33
 
34
34
  describe '#rollback' do
35
- before do
36
- 1.upto(3) { |i| backend.migrated!(i) }
37
- end
35
+ context 'with previous migrations' do
36
+ before(:each) do
37
+ 1.upto(3) { |i| backend.migrated!(i) }
38
+ end
38
39
 
39
- it 'should roll back most recent change' do
40
- migrator.rollback
41
- tracker.should have_rolled_back(3)
42
- tracker.should_not have_rolled_back(2)
43
- tracker.should_not have_rolled_back(1)
44
- end
40
+ it 'should roll back most recent change' do
41
+ migrator.rollback
42
+ tracker.should have_rolled_back(3)
43
+ tracker.should_not have_rolled_back(2)
44
+ tracker.should_not have_rolled_back(1)
45
+ end
46
+
47
+ it 'should mark migration as rolled back in backend' do
48
+ migrator.rollback
49
+ backend.migrated?(3).should be_false
50
+ end
45
51
 
46
- it 'should mark migration as rolled back in backend' do
47
- migrator.rollback
48
- backend.migrated?(3).should be_false
52
+ it 'should run multiple migrations if passed' do
53
+ migrator.rollback(2)
54
+ tracker.should have_rolled_back(3)
55
+ tracker.should have_rolled_back(2)
56
+ tracker.should_not have_rolled_back(1)
57
+ end
49
58
  end
50
59
 
51
- it 'should run multiple migrations if passed' do
52
- migrator.rollback(2)
53
- tracker.should have_rolled_back(3)
54
- tracker.should have_rolled_back(2)
55
- tracker.should_not have_rolled_back(1)
60
+ context 'without previous migrations' do
61
+ it 'should silently succeed if no migrations left to rollback' do
62
+ migrator.rollback
63
+ end
56
64
  end
57
65
  end
58
66
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shearwater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mat Brown
9
+ - Andrew De Ponte
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
13
+ date: 2012-11-30 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rspec
@@ -68,25 +69,27 @@ description: ! 'Shearwater is a tiny framework for managing migrations in an eve
68
69
  your migrations. Shearwater doesn''t depend on any ORMs or frameworks.
69
70
 
70
71
  '
71
- email: mat.a.brown@gmail.com
72
+ email:
73
+ - mat.a.brown@gmail.com
74
+ - cyphactor@gmail.com
72
75
  executables: []
73
76
  extensions: []
74
77
  extra_rdoc_files: []
75
78
  files:
76
- - lib/shearwater.rb
77
79
  - lib/shearwater/cassandra_cql_backend.rb
78
- - lib/shearwater/redis_backend.rb
79
80
  - lib/shearwater/in_memory_backend.rb
80
81
  - lib/shearwater/migrator.rb
82
+ - lib/shearwater/redis_backend.rb
81
83
  - lib/shearwater/version.rb
84
+ - lib/shearwater.rb
82
85
  - spec/environment.rb
83
- - spec/examples/spec_helper.rb
84
- - spec/examples/migrator_spec.rb
85
86
  - spec/examples/cassandra_cql_backend_spec.rb
86
- - spec/support/migration_tracker.rb
87
+ - spec/examples/migrator_spec.rb
88
+ - spec/examples/spec_helper.rb
89
+ - spec/migrations/001_migration_1.rb
87
90
  - spec/migrations/002_migration_2.rb
88
91
  - spec/migrations/003_migration_3.rb
89
- - spec/migrations/001_migration_1.rb
92
+ - spec/support/migration_tracker.rb
90
93
  homepage:
91
94
  licenses:
92
95
  - MIT
@@ -113,7 +116,7 @@ signing_key:
113
116
  specification_version: 3
114
117
  summary: Tiny everything-agnostic migrations framework
115
118
  test_files:
116
- - spec/examples/spec_helper.rb
117
- - spec/examples/migrator_spec.rb
118
119
  - spec/examples/cassandra_cql_backend_spec.rb
120
+ - spec/examples/migrator_spec.rb
121
+ - spec/examples/spec_helper.rb
119
122
  has_rdoc: false