clear_migrations 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/clear_migrations.gemspec +22 -0
- data/lib/clear_migrations.rb +5 -0
- data/lib/clear_migrations/railtie.rb +18 -0
- data/lib/clear_migrations/tasks.rake +48 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 425c05c6b5268b67261e10f1a6b3c59fef4104da
|
4
|
+
data.tar.gz: 97a1a4a2778aaa4bf4fdb78f6d608b84dac629d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 937f1aec0d1cb2c8b08385135160da7217e8c5bda7250bdf347dce2cf1c3355a13dc0c09a4fd01159b78c9d195c66fc3c360affbae85c0647e7d89ce8fc457d0
|
7
|
+
data.tar.gz: 295ab3a8df42f2e2e1b64f53d0fddea4dbc9705aed8e49fb73242a81998f6ec7447d34de5988258c155a8b88e08476a5e4e902022b13b5d07a870390e6d0add9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Yarin Kessler
|
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,42 @@
|
|
1
|
+
# ClearMigrations
|
2
|
+
|
3
|
+
Clears out old migrations from a Rails project.
|
4
|
+
|
5
|
+
No one wants old and crusty migrations hanging around forever, cramping your project's style. When you're ready to cut the cord, this gem lets you do it cleanly.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile and execute bundle to install:
|
10
|
+
|
11
|
+
gem 'clear_migrations'
|
12
|
+
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
**NOTE:** This gem is meant to be used sparingly- especially on multi-user projects. There's not much that can go wrong when you run it in your local environment, but any collaborators and existing deployments **must have their schemas up to date** before pulling from a repo in which migrations have been cleared, otherwise pending migrations will be cleared from their project before they have a chance to run them...
|
17
|
+
|
18
|
+
clear_migrations attempts to make things as easy as possible, but **clearing migrations should always be approached carefully.**
|
19
|
+
|
20
|
+
Once you're sure everyone is up to date on the latest schema, run the rake task provided:
|
21
|
+
|
22
|
+
rake db:clear_migrations
|
23
|
+
|
24
|
+
This will:
|
25
|
+
|
26
|
+
- Run all pending migrations
|
27
|
+
- Delete all migration files from your project
|
28
|
+
- Create a single new migration file called `XXX_reset.rb` and migrate it
|
29
|
+
|
30
|
+
The `XXX_reset.rb` migration does one of two things:
|
31
|
+
|
32
|
+
- On systems that have previously run migrations, it clears the `schema_migrations` table, automatically becoming the first entry.
|
33
|
+
- On new systems that don't have any `schema_migrations` records, it will raise an error if migrated, prompting the user to use `db:schema:load` instead of `db:migrate`. This is best practice anyway, and ensures that new installs always load up the full db schema without relying on the (now missing) migration trail.
|
34
|
+
|
35
|
+
When others pull the changes, they'll receive a db/migrations directory that's truncated up until the reset migration, and can then migrate or instantiate their db as usual.
|
36
|
+
|
37
|
+
|
38
|
+
## Credits
|
39
|
+
|
40
|
+
Code mostly stolen from [simplificator/flatten_migrations](https://github.com/simplificator/flatten_migrations), though this does things differently.
|
41
|
+
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "clear_migrations"
|
7
|
+
spec.version = "0.0.11"
|
8
|
+
spec.authors = ["Yarin Kessler"]
|
9
|
+
spec.email = ["ykessler@appgrinders.com"]
|
10
|
+
spec.description = %q{Clear out old migrations from a Rails project}
|
11
|
+
spec.summary = %q{Clear out old migrations from a Rails project}
|
12
|
+
spec.homepage = "https://github.com/ykessler/clear-migrations"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
namespace :db do
|
3
|
+
|
4
|
+
desc "Clear out old db migration files"
|
5
|
+
task :clear_migrations do
|
6
|
+
puts "(IMPORTANT: Make sure others run their migrations before they pull the changes you're about to make!)"
|
7
|
+
do_migrations
|
8
|
+
delete_migrations
|
9
|
+
create_reset_migration
|
10
|
+
do_migrations true
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def do_migrations( force = false )
|
16
|
+
puts "Running #{force ? "new" : "pending"} migration#{force ? "" : "s"}..."
|
17
|
+
if force then Rake::Task[ "db:migrate" ].reenable end
|
18
|
+
Rake::Task[ "db:migrate" ].invoke
|
19
|
+
puts "Done"
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_migrations
|
23
|
+
puts "Deleting migration files..."
|
24
|
+
Dir[ File.join Rails.root.to_s, "db", "migrate", "*" ].each{ |f| File.delete f }
|
25
|
+
puts "Done"
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_reset_migration
|
29
|
+
puts "Creating reset migration..."
|
30
|
+
timestamp = Time.now.strftime "%Y%m%d%H%M%S"
|
31
|
+
File.open( File.join( Rails.root.to_s, "db", "migrate", "#{timestamp}_reset.rb" ), 'w' ) do |f|
|
32
|
+
f.puts "# Establishes reset point for migrations cleared out by the clear_migrations gem."
|
33
|
+
f.puts "class Reset < ActiveRecord::Migration"
|
34
|
+
f.puts "\tdef self.up\n"
|
35
|
+
f.puts "\t\tif ActiveRecord::Migrator.get_all_versions.empty?"
|
36
|
+
f.puts "\t\t\traise \"===> USE DB:SCHEMA:LOAD INSTEAD OF DB:MIGRATE \nMigrations for this project have been previously cleared out with the clear_migrations gem. \nTo create this project's database on a new system, please use db:schema:load instead of trying to run all the migrations from scratch.\n\n\""
|
37
|
+
f.puts "\t\telse"
|
38
|
+
f.puts "\t\t\texecute \"TRUNCATE schema_migrations;\""
|
39
|
+
f.puts "\t\tend"
|
40
|
+
f.puts "\tend\n"
|
41
|
+
f.puts "\tdef self.down\n"
|
42
|
+
f.puts "\t\traise ActiveRecord::IrreversibleMigration"
|
43
|
+
f.puts "\tend"
|
44
|
+
f.puts "end\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clear_migrations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yarin Kessler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-30 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
|
+
description: Clear out old migrations from a Rails project
|
42
|
+
email:
|
43
|
+
- ykessler@appgrinders.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- clear_migrations.gemspec
|
54
|
+
- lib/clear_migrations.rb
|
55
|
+
- lib/clear_migrations/railtie.rb
|
56
|
+
- lib/clear_migrations/tasks.rake
|
57
|
+
homepage: https://github.com/ykessler/clear-migrations
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.3
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Clear out old migrations from a Rails project
|
81
|
+
test_files: []
|