ar_checked_migration 3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.guardrc +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Appraisals +7 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +79 -0
- data/Rakefile +14 -0
- data/ar_checked_migration.gemspec +35 -0
- data/gemfiles/rails_3.gemfile +7 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/lib/active_record/checked_migration.rb +13 -0
- data/lib/ar_checked_migration/checker.rb +14 -0
- data/lib/ar_checked_migration/railtie.rb +20 -0
- data/lib/ar_checked_migration/runner.rb +26 -0
- data/lib/ar_checked_migration/status.rb +49 -0
- data/lib/ar_checked_migration/templates/active_record/migration/migration.rb +37 -0
- data/lib/ar_checked_migration/templates/active_record/model/migration.rb +18 -0
- data/lib/ar_checked_migration/version.rb +3 -0
- data/lib/ar_checked_migration.rb +10 -0
- data/spec/integration/lib/ar_checked_migration/checker_spec.rb +53 -0
- data/spec/integration/lib/ar_checked_migration/status_spec.rb +43 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/migrations/20130101000001_first.rb +2 -0
- data/spec/support/migrations/20130102000001_second.rb +3 -0
- data/spec/support/migrations/20130103000001_third.rb +3 -0
- data/spec/support/migrations/20130104000001_fourth.rb +3 -0
- data/spec/support/migrations.rb +21 -0
- data/spec/unit/lib/active_record/checked_migration_spec.rb +18 -0
- data/spec/unit/lib/ar_checked_migration/status_spec.rb +21 -0
- metadata +244 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e80d4068a08b95a03e981e6237f018feacc1c46e
|
4
|
+
data.tar.gz: d46f7731357eb9af7c813e6516ed154a2d1861da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b02ee3600885585dd9c1bde2b9ccbd712e3de3bd50e0907bef64e0c927498a8f4081c746f9581358337c58bdacd45a69fec66cbb17fa7e64c260ca331a198ea3
|
7
|
+
data.tar.gz: e801f19de46795cb64edda6e0fb05042fc0b91e0e221082c62eaadcd7ef1c93f123140d17da28147ebbae87f6a26800d5fafede4db61998dfa718cece74faa8e
|
data/.gitignore
ADDED
data/.guardrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Guard.options[:clear] = true
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ar_checked_migration
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p353
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :minitest do
|
5
|
+
watch(%r{^spec/(.*)_spec\.rb})
|
6
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/unit/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/integration/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch(%r{^spec/spec_helper\.rb}) { 'spec' }
|
9
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brad Robertson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# ArCheckedMigration
|
2
|
+
|
3
|
+
[](https://codeclimate.com/repos/5297ae7f89af7e25a70ee800/feed)
|
4
|
+
[](https://travis-ci.org/bradrobertson/ar_checked_migration)
|
5
|
+
|
6
|
+
ArCheckedMigration provides a utility for specifying which migrations to be run are
|
7
|
+
'safe' or not. It is up to you to specify in your migration whether or not it is safe.
|
8
|
+
|
9
|
+
Once each migration has done so, you can use the task below to determine if all
|
10
|
+
migrations to be run are safe, which would mean you wouldn't have to put your
|
11
|
+
application into maintenance mode during a deploy.
|
12
|
+
|
13
|
+
Safe Migrations are generally considered to be:
|
14
|
+
|
15
|
+
- New tables, columns, indexes
|
16
|
+
- Data changes
|
17
|
+
|
18
|
+
Unsafe Migrations include:
|
19
|
+
|
20
|
+
- table or column renames
|
21
|
+
- removing a table or column
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'ar_checked_migration'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install ar_checked_migration
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
To determine if your migrations to run are safe, you can simply run
|
40
|
+
|
41
|
+
````ruby
|
42
|
+
ArCheckedMigration::Runner.safe?
|
43
|
+
````
|
44
|
+
|
45
|
+
Note that if you're NOT using Rails, you'll need to manually specify the migrations
|
46
|
+
directories AND the schema_migrations table name before running the runner.
|
47
|
+
Something like:
|
48
|
+
|
49
|
+
````ruby
|
50
|
+
ArCheckedMigration::Runner.migrations = ActiveRecord::Migrator.migrations(['some', 'paths', 'here'])
|
51
|
+
ArCheckedMigration::Runner.table_name = 'schema_migrations'
|
52
|
+
ArCheckedMigration::Runner.safe?
|
53
|
+
````
|
54
|
+
|
55
|
+
Migrations themselves are a subclass of `ActiveRecord::CheckedMigration` instead of
|
56
|
+
`ActiveRecord::Migration`
|
57
|
+
|
58
|
+
A typical migration will look like
|
59
|
+
|
60
|
+
````ruby
|
61
|
+
class MyMigration < ActiveRecord::CheckedMigration
|
62
|
+
# Set to true or false depending on the type of migration
|
63
|
+
is_safe true
|
64
|
+
|
65
|
+
def change
|
66
|
+
# do some stuff
|
67
|
+
end
|
68
|
+
end
|
69
|
+
````
|
70
|
+
|
71
|
+
If `is_safe` is not set or an `ActiveRecord::Migration` migration is used, it is assumed to be unsafe.
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
require 'appraisal'
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
|
8
|
+
Rake::TestTask.new(:spec) do |t|
|
9
|
+
t.libs << "lib" << "spec"
|
10
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
11
|
+
t.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :spec
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ar_checked_migration/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ar_checked_migration"
|
8
|
+
spec.version = ArCheckedMigration::VERSION
|
9
|
+
spec.authors = ["Brad Robertson"]
|
10
|
+
spec.email = ["bradleyrobertson@gmail.com"]
|
11
|
+
spec.description = %q{Determine whether or not ActiveRecord migrations are
|
12
|
+
considered safe to know if an app
|
13
|
+
needs to go into maintenance on deploy}
|
14
|
+
spec.summary = %q{Check 'safe' and 'unsafe' migrations}
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rails"
|
26
|
+
spec.add_development_dependency "minitest"
|
27
|
+
spec.add_development_dependency "minitest-spec-context"
|
28
|
+
spec.add_development_dependency "minitest-reporters"
|
29
|
+
spec.add_development_dependency "rr"
|
30
|
+
spec.add_development_dependency "guard-minitest"
|
31
|
+
spec.add_development_dependency "appraisal"
|
32
|
+
spec.add_development_dependency "sqlite3"
|
33
|
+
|
34
|
+
spec.add_runtime_dependency "activerecord", ">= 3.2"
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_support/inflector/methods'
|
2
|
+
|
3
|
+
module ArCheckedMigration
|
4
|
+
class Checker < Struct.new(:status)
|
5
|
+
def safe?
|
6
|
+
status.down.all? do |migration|
|
7
|
+
require migration.filename
|
8
|
+
klass = migration.name.constantize
|
9
|
+
|
10
|
+
klass.respond_to?(:is_safe) && klass.is_safe
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ar_checked_migration/runner'
|
2
|
+
|
3
|
+
module ArCheckedMigration
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
initializer 'ar_checked_migration.init' do
|
7
|
+
ActiveSupport.on_load(:active_record) do
|
8
|
+
migrations = ActiveRecord::Migrator.migrations(ActiveRecord::Migrator.migrations_paths)
|
9
|
+
table_name = ActiveRecord::Migrator.schema_migrations_table_name
|
10
|
+
|
11
|
+
ArCheckedMigration::Runner.migrations = migrations
|
12
|
+
ArCheckedMigration::Runner.table_name = table_name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
config.app_generators do |g|
|
17
|
+
g.templates.unshift File.expand_path('../templates', __FILE__)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ar_checked_migration/status'
|
2
|
+
require 'ar_checked_migration/checker'
|
3
|
+
|
4
|
+
module ArCheckedMigration
|
5
|
+
class Runner
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer :migrations, :table_name
|
9
|
+
|
10
|
+
def migrations
|
11
|
+
@migrations || raise("You must give an ActiveRecord::MigrationProxy array")
|
12
|
+
end
|
13
|
+
|
14
|
+
def table_name
|
15
|
+
@table_name || raise("You must specify the schema migrations table_name")
|
16
|
+
end
|
17
|
+
|
18
|
+
def safe?
|
19
|
+
status = Status.new(migrations, table_name)
|
20
|
+
checker = Checker.new(status)
|
21
|
+
|
22
|
+
checker.safe?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ArCheckedMigration
|
2
|
+
class Status < Struct.new(:migrations, :migrations_table)
|
3
|
+
|
4
|
+
def all
|
5
|
+
return all_down unless Migrations.table_exists?(migrations_table)
|
6
|
+
|
7
|
+
@all ||= {down: down_migrations, up: up_migrations}
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
all[:down]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def versions
|
17
|
+
migrations.map(&:version)
|
18
|
+
end
|
19
|
+
|
20
|
+
def all_down
|
21
|
+
{down: migrations, up: []}
|
22
|
+
end
|
23
|
+
|
24
|
+
def up_migrations
|
25
|
+
migrations.select{|m| migrated_versions.include?(m.version) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def down_migrations
|
29
|
+
migrations - up_migrations
|
30
|
+
end
|
31
|
+
|
32
|
+
def migrated_versions
|
33
|
+
@migrated_versions ||= Migrations.up(migrations_table).map(&:to_i)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Migrations
|
38
|
+
def self.table_exists?(table)
|
39
|
+
ActiveRecord::Base.connection.table_exists?(table)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.up(table)
|
43
|
+
ActiveRecord::Base.connection.select_values(<<-SQL
|
44
|
+
SELECT version FROM #{table}
|
45
|
+
SQL
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::CheckedMigration
|
2
|
+
# Change to true if your migration requires no downtime
|
3
|
+
is_safe false
|
4
|
+
|
5
|
+
<%- if migration_action == 'add' -%>
|
6
|
+
def change
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
|
9
|
+
<%- if attribute.has_index? -%>
|
10
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
11
|
+
<%- end -%>
|
12
|
+
<%- end -%>
|
13
|
+
end
|
14
|
+
<%- else -%>
|
15
|
+
def up
|
16
|
+
<% attributes.each do |attribute| -%>
|
17
|
+
<%- if migration_action -%>
|
18
|
+
<%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><%= attribute.inject_options %><% end %>
|
19
|
+
<%- if attribute.has_index? && migration_action == 'add' -%>
|
20
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
21
|
+
<%- end -%>
|
22
|
+
<%- end -%>
|
23
|
+
<%- end -%>
|
24
|
+
end
|
25
|
+
|
26
|
+
def down
|
27
|
+
<% attributes.reverse.each do |attribute| -%>
|
28
|
+
<%- if migration_action -%>
|
29
|
+
<%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><%= attribute.inject_options %><% end %>
|
30
|
+
<%- if attribute.has_index? && migration_action == 'remove' -%>
|
31
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
32
|
+
<%- end -%>
|
33
|
+
<%- end -%>
|
34
|
+
<%- end -%>
|
35
|
+
end
|
36
|
+
<%- end -%>
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::CheckedMigration
|
2
|
+
# Change to false if your migration requires downtime
|
3
|
+
is_safe true
|
4
|
+
|
5
|
+
def change
|
6
|
+
create_table :<%= table_name %> do |t|
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
9
|
+
<% end -%>
|
10
|
+
<% if options[:timestamps] %>
|
11
|
+
t.timestamps
|
12
|
+
<% end -%>
|
13
|
+
end
|
14
|
+
<% attributes_with_index.each do |attribute| -%>
|
15
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
16
|
+
<% end -%>
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'ar_checked_migration/version'
|
2
|
+
require 'ar_checked_migration/status'
|
3
|
+
require 'ar_checked_migration/checker'
|
4
|
+
require 'ar_checked_migration/runner'
|
5
|
+
require 'active_record/checked_migration'
|
6
|
+
require 'ar_checked_migration/railtie' if defined?(Rails)
|
7
|
+
|
8
|
+
module ArCheckedMigration
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ArCheckedMigration::Checker do
|
4
|
+
|
5
|
+
let(:table) { Migrations.table }
|
6
|
+
let(:migrated) { [] }
|
7
|
+
|
8
|
+
let(:status){ ArCheckedMigration::Status.new(Migrations.all, Migrations.table) }
|
9
|
+
let(:checker){ ArCheckedMigration::Checker.new(status) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
ActiveRecord::Base.connection.create_table(table, id: false){|t| t.string('version')}
|
13
|
+
if migrated.length > 0
|
14
|
+
migrated.each do |v|
|
15
|
+
ActiveRecord::Base.connection.execute("INSERT INTO #{table} VALUES (#{v});")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after{ ActiveRecord::Base.connection.drop_table(table) }
|
21
|
+
|
22
|
+
context "non checked migration is down" do
|
23
|
+
let(:migrated){ [] }
|
24
|
+
|
25
|
+
it "is not safe" do
|
26
|
+
checker.safe?.must_equal false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "unsafe checked migration is down" do
|
31
|
+
let(:migrated){ Migrations.timestamps.take(1) }
|
32
|
+
|
33
|
+
it "is not safe" do
|
34
|
+
checker.safe?.must_equal false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "only safe checked migrations are down" do
|
39
|
+
let(:migrated){ Migrations.timestamps.take(2) }
|
40
|
+
|
41
|
+
it "is safe" do
|
42
|
+
checker.safe?.must_equal true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "no migrations to run" do
|
47
|
+
let(:migrated){ Migrations.timestamps }
|
48
|
+
|
49
|
+
it "is safe" do
|
50
|
+
checker.safe?.must_equal true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ArCheckedMigration::Status do
|
4
|
+
let(:migrations_table) { Migrations.table }
|
5
|
+
let(:migrations) { Migrations.all }
|
6
|
+
let(:migrations_timestamps){ Migrations.timestamps }
|
7
|
+
|
8
|
+
let(:status) { ArCheckedMigration::Status.new(migrations, migrations_table) }
|
9
|
+
|
10
|
+
describe '#all' do
|
11
|
+
context "no migrations table exists" do
|
12
|
+
it "considers all migrations down" do
|
13
|
+
status.all.must_equal(down: migrations, up: [])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "migrations table exists" do
|
18
|
+
before{ ActiveRecord::Base.connection.create_table(migrations_table, id: false){|t| t.string('version')} }
|
19
|
+
after{ ActiveRecord::Base.connection.drop_table(migrations_table) }
|
20
|
+
|
21
|
+
it "also considers all things down" do
|
22
|
+
status.all.must_equal(down: migrations, up: [])
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with some migrations up" do
|
26
|
+
let(:up_count){ 2 }
|
27
|
+
let(:migrated){ migrations_timestamps.first(up_count).map{|f| "(#{f})"} }
|
28
|
+
before do
|
29
|
+
migrated.each do |v|
|
30
|
+
ActiveRecord::Base.connection.execute("INSERT INTO #{migrations_table} VALUES (#{v})")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has some up and some down" do
|
35
|
+
status.all.must_equal(
|
36
|
+
up: migrations.first(2),
|
37
|
+
down: migrations.last(2)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest-spec-context'
|
3
|
+
require 'minitest/reporters'
|
4
|
+
require 'rr'
|
5
|
+
|
6
|
+
Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new
|
7
|
+
|
8
|
+
lib = File.expand_path('../lib', File.dirname(__FILE__))
|
9
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
10
|
+
|
11
|
+
require 'active_record'
|
12
|
+
require 'ar_checked_migration'
|
13
|
+
|
14
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
15
|
+
|
16
|
+
SPEC_ROOT = File.dirname(File.expand_path(__FILE__))
|
17
|
+
|
18
|
+
Dir["#{SPEC_ROOT}/support/**/*.rb"].each{|f| require f }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Migrations
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def all
|
5
|
+
ActiveRecord::Migrator.migrations(["#{SPEC_ROOT}/support/migrations"])
|
6
|
+
end
|
7
|
+
|
8
|
+
def timestamps
|
9
|
+
all.map(&:version)
|
10
|
+
end
|
11
|
+
|
12
|
+
def table
|
13
|
+
'schema_migrations'
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def timestamp_regex
|
19
|
+
/(\d{14})_.*\.rb/
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveRecord::CheckedMigration do
|
4
|
+
SomeMigration = Class.new(ActiveRecord::CheckedMigration)
|
5
|
+
|
6
|
+
describe "::is_safe" do
|
7
|
+
it "defaults to false" do
|
8
|
+
SomeMigration.is_safe.must_equal false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "allows setting/getting" do
|
12
|
+
SomeMigration.is_safe(true)
|
13
|
+
SomeMigration.is_safe.must_equal true
|
14
|
+
SomeMigration.is_safe(false)
|
15
|
+
SomeMigration.is_safe.must_equal false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ArCheckedMigration::Status do
|
4
|
+
let(:migrations_table) { Migrations.table }
|
5
|
+
let(:migrations) { Migrations.all }
|
6
|
+
let(:migrations_timestamps) { Migrations.timestamps }
|
7
|
+
let(:up){ migrations.first(2) }
|
8
|
+
|
9
|
+
let(:status) { ArCheckedMigration::Status.new(migrations, migrations_table) }
|
10
|
+
|
11
|
+
describe "#down" do
|
12
|
+
before do
|
13
|
+
stub(ArCheckedMigration::Migrations).table_exists?{ true }
|
14
|
+
stub(ArCheckedMigration::Migrations).up{ up.map(&:version) }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "fetches all migrations that haven't been run" do
|
18
|
+
status.down.must_equal migrations - up
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar_checked_migration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '3.2'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-spec-context
|
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: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: appraisal
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: activerecord
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.2'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.2'
|
167
|
+
description: |-
|
168
|
+
Determine whether or not ActiveRecord migrations are
|
169
|
+
considered safe to know if an app
|
170
|
+
needs to go into maintenance on deploy
|
171
|
+
email:
|
172
|
+
- bradleyrobertson@gmail.com
|
173
|
+
executables: []
|
174
|
+
extensions: []
|
175
|
+
extra_rdoc_files: []
|
176
|
+
files:
|
177
|
+
- .gitignore
|
178
|
+
- .guardrc
|
179
|
+
- .ruby-gemset
|
180
|
+
- .ruby-version
|
181
|
+
- .travis.yml
|
182
|
+
- Appraisals
|
183
|
+
- Gemfile
|
184
|
+
- Guardfile
|
185
|
+
- LICENSE.txt
|
186
|
+
- README.md
|
187
|
+
- Rakefile
|
188
|
+
- ar_checked_migration.gemspec
|
189
|
+
- gemfiles/rails_3.gemfile
|
190
|
+
- gemfiles/rails_4.gemfile
|
191
|
+
- lib/active_record/checked_migration.rb
|
192
|
+
- lib/ar_checked_migration.rb
|
193
|
+
- lib/ar_checked_migration/checker.rb
|
194
|
+
- lib/ar_checked_migration/railtie.rb
|
195
|
+
- lib/ar_checked_migration/runner.rb
|
196
|
+
- lib/ar_checked_migration/status.rb
|
197
|
+
- lib/ar_checked_migration/templates/active_record/migration/migration.rb
|
198
|
+
- lib/ar_checked_migration/templates/active_record/model/migration.rb
|
199
|
+
- lib/ar_checked_migration/version.rb
|
200
|
+
- spec/integration/lib/ar_checked_migration/checker_spec.rb
|
201
|
+
- spec/integration/lib/ar_checked_migration/status_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
- spec/support/migrations.rb
|
204
|
+
- spec/support/migrations/20130101000001_first.rb
|
205
|
+
- spec/support/migrations/20130102000001_second.rb
|
206
|
+
- spec/support/migrations/20130103000001_third.rb
|
207
|
+
- spec/support/migrations/20130104000001_fourth.rb
|
208
|
+
- spec/unit/lib/active_record/checked_migration_spec.rb
|
209
|
+
- spec/unit/lib/ar_checked_migration/status_spec.rb
|
210
|
+
homepage: ''
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
metadata: {}
|
214
|
+
post_install_message:
|
215
|
+
rdoc_options: []
|
216
|
+
require_paths:
|
217
|
+
- lib
|
218
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - '>='
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
requirements: []
|
229
|
+
rubyforge_project:
|
230
|
+
rubygems_version: 2.1.11
|
231
|
+
signing_key:
|
232
|
+
specification_version: 4
|
233
|
+
summary: Check 'safe' and 'unsafe' migrations
|
234
|
+
test_files:
|
235
|
+
- spec/integration/lib/ar_checked_migration/checker_spec.rb
|
236
|
+
- spec/integration/lib/ar_checked_migration/status_spec.rb
|
237
|
+
- spec/spec_helper.rb
|
238
|
+
- spec/support/migrations.rb
|
239
|
+
- spec/support/migrations/20130101000001_first.rb
|
240
|
+
- spec/support/migrations/20130102000001_second.rb
|
241
|
+
- spec/support/migrations/20130103000001_third.rb
|
242
|
+
- spec/support/migrations/20130104000001_fourth.rb
|
243
|
+
- spec/unit/lib/active_record/checked_migration_spec.rb
|
244
|
+
- spec/unit/lib/ar_checked_migration/status_spec.rb
|