migrer 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd4914d61f688360460e1803b8fad79fb63df4e8
4
- data.tar.gz: 0849a0784e55947b334fc6e57121e5a24b3c1180
3
+ metadata.gz: 5ab23a51367459bc6a7d74f2ca6fb03f20f9ff9f
4
+ data.tar.gz: c55fc6db8dc641a17dcdad3c7a204e96c1553ac3
5
5
  SHA512:
6
- metadata.gz: 72a3a7c0ff70d504c8f537610587b8aa7087fa74877082e941dadfa01bf7077410f59bf34846cb034ebf87fc82d53c188c8424723605df7f0a6b47c9862c4450
7
- data.tar.gz: 8bfc03576d819677311a2354e6db7fa6f4758017a88fc038cd84fd9b0f216eca06348d08dc9b4ccd2cfc691da4ccf5835d08d40a66c9bcad07d2ca662a9070c6
6
+ metadata.gz: 30e62e52888a1a5b11fa88691e235dfcc1be8b459ac89d919249130e3634ea8f3f35136c41b9fd36938661663b6bada4f05e333aab592af292eb5ef5b8493195
7
+ data.tar.gz: 1e84ea5fa1db4f8f33335a2d657cafac627e39549ecd763bed5588ea896e6b2a7ff0c10b4edf0112f4c77832e057faf05fdb9ea4f574a15ec1e8180bea070901
data/.DS_Store ADDED
Binary file
data/README.md CHANGED
@@ -43,6 +43,20 @@ And install database migrations like so:
43
43
  $ bundle exec rake railties:install:migrations FROM=migrer
44
44
  $ bundle exec rake db:migrate
45
45
 
46
+ ## Configuration
47
+
48
+ Migrer can be configured (e.g. in an initializer) as follows:
49
+
50
+ ```ruby
51
+ Migrer.configure do |config|
52
+ config.paranoid = true
53
+ end
54
+ ```
55
+
56
+ Configuration options:
57
+
58
+ paranoid (default: false) - If set to true, a prompt will be required before running each data migration.
59
+
46
60
  ## Usage
47
61
 
48
62
  ### 1) Create the data migration
@@ -62,7 +76,7 @@ Unless you have the RAILS_ENV environment variable already set, prepend this to
62
76
 
63
77
  RAILS_ENV=<environment>
64
78
 
65
- All the following commands will ask for confirmation before executing.
79
+ NOTE: If the 'paranoid' configuration variable is set to true, or if the commands are run with the ```PARANOID=true``` environment variable, all the following commands will ask for confirmation before executing.
66
80
 
67
81
  **Run all unprocessed data migrations:**
68
82
 
@@ -0,0 +1,7 @@
1
+ class Configuration
2
+ attr_accessor :paranoid
3
+
4
+ def initialize
5
+ @paranoid = false
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Migrer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/migrer.rb CHANGED
@@ -1,9 +1,30 @@
1
1
  require "migrer/version"
2
+ require "migrer/configuration"
2
3
 
3
4
  module Migrer
5
+ class << self
6
+ attr_writer :configuration
7
+ end
8
+
4
9
  def self.table_name_prefix
5
10
  ''
6
11
  end
12
+
13
+ def self.configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def self.reset
18
+ @configuration = Configuration.new
19
+ end
20
+
21
+ def self.configure
22
+ yield(configuration)
23
+ end
24
+
25
+ def self.paranoid?
26
+ ENV['PARANOID'] == 'true' || configuration.paranoid
27
+ end
7
28
  end
8
29
 
9
30
  # Require our engine
@@ -10,16 +10,20 @@ namespace :data do
10
10
  data_migration = data_migrations[version]
11
11
 
12
12
  if data_migration.present?
13
- if data_migration[:processed]
14
- puts "Data migration already processed. Do you want to run it anyway? (responses other than 'yes' will exit)".migrer_yellow
15
- else
16
- puts "Starting data migration #{data_migration[:class_name]}. Do you wish to continue? (responses other than 'yes' will exit)".migrer_yellow
17
- end
18
13
 
19
- prompt = $stdin.gets.chomp
14
+ can_migrate = !Migrer.paranoid?
15
+ if Migrer.paranoid?
16
+ if data_migration[:processed]
17
+ puts "Data migration already processed. Do you want to run it anyway? (responses other than 'yes' will exit)".migrer_yellow
18
+ else
19
+ puts "Starting data migration #{data_migration[:class_name]}. Do you wish to continue? (responses other than 'yes' will exit)".migrer_yellow
20
+ end
21
+ prompt = $stdin.gets.chomp
22
+ can_migrate = prompt == "yes"
23
+ end
20
24
 
21
- if prompt == "yes"
22
- puts "#{data_migration[:class_name]}: migrating"
25
+ if can_migrate
26
+ puts "#{data_migration[:class_name]}".migrer_yellow + ": migrating"
23
27
  t_start = Time.now
24
28
 
25
29
  require "#{Rails.root}/db/data_migrate/#{data_migration[:basefilename]}"
@@ -39,10 +43,16 @@ namespace :data do
39
43
  else
40
44
  data_migrations.each do |k, v|
41
45
  unless v[:processed]
42
- puts "Starting data migration #{v[:class_name]}. Do you wish to continue? (responses other than 'yes' will exit)".migrer_yellow
43
- prompt = $stdin.gets.chomp
44
- if prompt == "yes"
45
- puts "#{v[:class_name]}: migrating"
46
+ can_migrate = !Migrer.paranoid?
47
+
48
+ if Migrer.paranoid?
49
+ puts "Starting data migration #{v[:class_name]}. Do you wish to continue? (responses other than 'yes' will exit)".migrer_yellow
50
+ prompt = $stdin.gets.chomp
51
+ can_migrate = prompt == "yes"
52
+ end
53
+
54
+ if can_migrate
55
+ puts "#{v[:class_name]}".migrer_yellow + ": migrating"
46
56
  t_start = Time.now
47
57
 
48
58
  require "#{Rails.root}/db/data_migrate/#{v[:basefilename]}"
@@ -70,11 +80,15 @@ namespace :data do
70
80
  if data_migration[:processed]
71
81
  puts "Data migration already processed.".migrer_yellow
72
82
  else
73
- puts "Data migration #{data_migration[:class_name]} will be marked as processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
83
+ can_migrate = !Migrer.paranoid?
74
84
 
75
- prompt = $stdin.gets.chomp
85
+ if Migrer.paranoid?
86
+ puts "Data migration #{data_migration[:class_name]} will be marked as processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
87
+ prompt = $stdin.gets.chomp
88
+ can_migrate = prompt == "yes"
89
+ end
76
90
 
77
- if prompt == "yes"
91
+ if can_migrate
78
92
  Migrer::DataMigrationVersion.create(version: version)
79
93
  puts "#{data_migration[:class_name]}:" + " marked as migrated".migrer_green
80
94
  end
@@ -91,10 +105,15 @@ namespace :data do
91
105
  task mark_all: :environment do
92
106
  unprocessed_data_migrations = Migrer::DataMigrationVersion.all_from_files.select { |k, v| !v[:processed] }
93
107
 
94
- puts "This will mark all data migrations as already processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
108
+ can_migrate = !Migrer.paranoid?
109
+
110
+ if Migrer.paranoid?
111
+ puts "This will mark all data migrations as already processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
112
+ prompt = $stdin.gets.chomp
113
+ can_migrate = prompt == "yes"
114
+ end
95
115
 
96
- prompt = $stdin.gets.chomp
97
- if prompt == "yes"
116
+ if can_migrate
98
117
  unprocessed_data_migrations.each do |k, v|
99
118
  Migrer::DataMigrationVersion.create(version: k)
100
119
  puts "#{v[:class_name]}:" + " marked as migrated".migrer_green
@@ -113,11 +132,15 @@ namespace :data do
113
132
  if !data_migration[:processed]
114
133
  puts "Data migration not yet processed.".migrer_yellow
115
134
  else
116
- puts "Data migration #{data_migration[:class_name]} will be unmarked as processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
135
+ can_migrate = !Migrer.paranoid?
117
136
 
118
- prompt = $stdin.gets.chomp
137
+ if Migrer.paranoid?
138
+ puts "Data migration #{data_migration[:class_name]} will be unmarked as processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
139
+ prompt = $stdin.gets.chomp
140
+ can_migrate = prompt == "yes"
141
+ end
119
142
 
120
- if prompt == "yes"
143
+ if can_migrate
121
144
  Migrer::DataMigrationVersion.find_by_version(version).destroy
122
145
  puts "#{data_migration[:class_name]}:" + " unmarked as migrated".migrer_green
123
146
  end
@@ -132,11 +155,15 @@ namespace :data do
132
155
 
133
156
  desc 'Revert all data migrations to an unprocessed state.'
134
157
  task unmark_all: :environment do
135
- puts "All data migrations will be unmarked as processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
158
+ can_migrate = !Migrer.paranoid?
136
159
 
137
- prompt = $stdin.gets.chomp
160
+ if Migrer.paranoid?
161
+ puts "All data migrations will be unmarked as processed. Continue? (responses other than 'yes' will exit)".migrer_yellow
162
+ prompt = $stdin.gets.chomp
163
+ can_migrate = prompt == "yes"
164
+ end
138
165
 
139
- if prompt == "yes"
166
+ if can_migrate
140
167
  Migrer::DataMigrationVersion.destroy_all
141
168
  puts "Data migration records cleared".migrer_green
142
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migrer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sathya Sekaran
@@ -32,6 +32,7 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
+ - ".DS_Store"
35
36
  - ".gitignore"
36
37
  - Gemfile
37
38
  - LICENSE.txt
@@ -44,6 +45,7 @@ files:
44
45
  - lib/generators/data_migration/templates/data_migration.rb
45
46
  - lib/migrer.rb
46
47
  - lib/migrer/ansi_colors.rb
48
+ - lib/migrer/configuration.rb
47
49
  - lib/migrer/engine.rb
48
50
  - lib/migrer/version.rb
49
51
  - lib/tasks/migrer.rake