exodus 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## v1.1.6
2
+
3
+ * Rerunnable migration is now a class property
4
+
1
5
  ## v1.1.5
2
6
 
3
7
  * Added more logging on custom migrations
@@ -12,7 +12,6 @@ module Exodus
12
12
 
13
13
  key :description, String
14
14
  key :status_complete, Integer, :default => 1
15
- key :rerunnable_safe, Boolean, :default => false # Be careful if the job is rerunnable_safe he will re-run on each db:migrate
16
15
 
17
16
  has_one :status, :class_name => "Exodus::MigrationStatus", :autosave => true
18
17
 
@@ -40,8 +39,8 @@ module Exodus
40
39
  def load_all(migrations)
41
40
  if migrations
42
41
  migrations.each do |migration, args|
43
- if migration && args
44
- formated_migration = format(migration, args)
42
+ if migration
43
+ formated_migration = format(migration, args || {})
45
44
  migration, args = formated_migration
46
45
 
47
46
  unless @migrations.include?(formated_migration)
@@ -58,7 +57,7 @@ module Exodus
58
57
  # Using a list of migrations formats them and removes duplicates
59
58
  # migrations: list of migrations => [[MyMigration, {:my_args => 'some_args'}]]
60
59
  def load_custom(migrations)
61
- migrations = migrations || []
60
+ migrations ||= []
62
61
  migrations.map {|migration_str, args| format(migration_str, args) }.uniq
63
62
  end
64
63
 
@@ -90,6 +89,18 @@ module Exodus
90
89
 
91
90
  super_print(status_info)
92
91
  end
92
+
93
+ def rerunnable_safe=(safe)
94
+ migrations = Migration.instance_variable_get("@migrations")
95
+ deletion = migrations.delete([self])
96
+ Migration.instance_variable_set("@migrations", migrations) if deletion
97
+
98
+ @rerunnable_safe = safe
99
+ end
100
+
101
+ def rerunnable_safe?
102
+ @rerunnable_safe == true
103
+ end
93
104
  end
94
105
 
95
106
  # Makes sure status get instanciated on migration's instanciation
@@ -104,25 +115,31 @@ module Exodus
104
115
  self.status.direction = direction
105
116
 
106
117
  # reset the status if the job is rerunnable and has already be completed
107
- self.status.reset! if self.rerunnable_safe && completed?(direction)
118
+ self.status.reset! if self.class.rerunnable_safe? && completed?(direction)
108
119
  self.status.execution_time = time_it { self.send(direction) }
109
120
  self.status.last_succesful_completion = Time.now
110
121
  end
111
122
 
112
123
  # Sets an error to migration status
113
124
  def failure=(exception)
114
- self.status.error = MigrationError.new(:error_message => exception.message, :error_class => exception.class, :error_backtrace => exception.backtrace)
125
+ self.status.error = MigrationError.new(
126
+ :error_message => exception.message,
127
+ :error_class => exception.class,
128
+ :error_backtrace => exception.backtrace)
115
129
  end
116
130
 
117
131
  # Checks if a migration can be run
118
132
  def is_runnable?(direction)
119
- rerunnable_safe || (direction == UP && status.current_status < status_complete) || (direction == DOWN && status.current_status > 0)
133
+ self.class.rerunnable_safe? ||
134
+ (direction == UP && status.current_status < status_complete) ||
135
+ (direction == DOWN && status.current_status > 0)
120
136
  end
121
137
 
122
138
  # Checks if a migration as been completed
123
139
  def completed?(direction)
124
140
  return false if self.status.execution_time == 0
125
- (direction == UP && self.status.current_status == self.status_complete) || (direction == DOWN && self.status.current_status == 0)
141
+ (direction == UP && self.status.current_status == self.status_complete) ||
142
+ (direction == DOWN && self.status.current_status == 0)
126
143
  end
127
144
 
128
145
  def characteristic
@@ -1,3 +1,3 @@
1
1
  module Exodus
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
@@ -11,7 +11,7 @@ describe Exodus::Migration do
11
11
 
12
12
  it "should have default value for [status_complete, rerunnable_safe]" do
13
13
  subject.status_complete.should == 1
14
- subject.rerunnable_safe.should be_false
14
+ (subject.class.rerunnable_safe?).should be_false
15
15
  end
16
16
  end
17
17
 
@@ -59,9 +59,10 @@ describe Exodus::Migration do
59
59
  end
60
60
 
61
61
  class RerunnableMigrationTest < Exodus::Migration
62
+ self.rerunnable_safe = true
63
+
62
64
  def initialize(args = {})
63
65
  super(args)
64
- self.rerunnable_safe = true
65
66
  end
66
67
 
67
68
  def up
@@ -202,7 +203,7 @@ describe Exodus::Migration do
202
203
  end
203
204
 
204
205
  it "should be runable when if the task is safe" do
205
- subject.rerunnable_safe = true
206
+ subject.class.rerunnable_safe = true
206
207
 
207
208
  subject.is_runnable?('up').should be_true
208
209
  subject.is_runnable?('down').should be_true
@@ -7,7 +7,7 @@ task :require_env do
7
7
  Exodus.load_migrations
8
8
  end
9
9
 
10
- namespace Exodus.configuration.rake_namespace + 'db' do
10
+ namespace Exodus.configuration.rake_namespace.to_s + 'db' do
11
11
  desc "Migrate the database"
12
12
  task :migrate => :require_env do
13
13
  time_it "db:migrate#{" step #{step}" if step}" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exodus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: