farfugl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7948ff9674a86db6179d60a5e625d75e48f0752f
4
+ data.tar.gz: 826a2837c37c8ac4b56cd5132bcf27f664bebcfd
5
+ SHA512:
6
+ metadata.gz: 23db79d7007f5df467087f800e16f8364ce2d7dbb5ba0a08e85618aa92df02007d9b0f3a3ed4aff7fa1cba3af950f21a403f127768a8219fbbbf792c7a912e46
7
+ data.tar.gz: f02c455e9ea25eff38b907cb4827a8b036f562d78337d3a538c293881de213d5b20f8522ca5937649b9304eb3f8ac590bdbf5ef8c27ed218db095eeaeb17a193
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Haukur Páll Hallvarðsson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS
19
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ Farfugl
2
+ =======
3
+
4
+ Migrating an old database with old migrations can be a pain because the
5
+ migrations often rely on code that doesn't exist in the latest version of the
6
+ application. The only solution is to checkout to the commit where the migration
7
+ was introduced, but this can be tedious. **Farfugl** will do this for you, all
8
+ you need to do is run `rake farfugl`.
9
+
10
+ **NOTE**: Farfugl is still under development and is not ready for use.
11
+
12
+ ### Install
13
+
14
+ gem install farfugl
@@ -0,0 +1,5 @@
1
+ module Farfugl
2
+ class Railtie < Rails::Railtie
3
+ require_relative './tasks/farfugl.rb'
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+
3
+ task default: :farfugl
4
+
5
+ desc 'Run migrations one by one, checked out to the correct environment'
6
+ task farfugl: :environment do
7
+ Farfugl.migrate
8
+ end
data/lib/farfugl.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'farfugl/railtie' if defined? Rails
2
+
3
+ module Farfugl
4
+ def self.schema_versions
5
+ schema_table = ActiveRecord::Migrator.schema_migrations_table_name
6
+ query = "SELECT version FROM #{schema_table}"
7
+ versions = ActiveRecord::Base.connection.select_values(query)
8
+ versions.map! { |version| "%.3d" % version }
9
+ end
10
+
11
+ def self.pending_migrations(versions)
12
+ migrations = []
13
+ ActiveRecord::Migrator.migrations_paths.each do |path|
14
+ Dir.foreach(path) do |file|
15
+ if match_data = /^(\d{3,})_(.+)\.rb$/.match(file)
16
+ migrations << "#{path}/#{file}" unless versions.delete(match_data[1])
17
+ end
18
+ end
19
+ end
20
+ migrations
21
+ end
22
+
23
+ def self.hashes(migrations)
24
+ migrations.map { |file| `git log -n 1 -- #{file}`.split[1] }
25
+ end
26
+
27
+ def self.current_branch
28
+ `git rev-parse --abbrev-ref HEAD`
29
+ end
30
+
31
+ def self.untracked_files
32
+ `git status --porcelain 2>/dev/null| grep "^??" | wc -l`
33
+ end
34
+
35
+ def self.checkout(destination)
36
+ `git checkout -f #{destination}`
37
+ end
38
+
39
+ def self.migrate
40
+ original_branch = self.current_branch
41
+ hashes = self.hashes(self.pending_migrations(self.schema_versions))
42
+ hashes.each do |commit_hash|
43
+ self.checkout(commit_hash)
44
+ Rake::Task['db:migrate'].invoke
45
+ end
46
+ self.checkout(original_branch)
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: farfugl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Haukur Páll Hallvarðsson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Old migrations often require code that no longer exists. Farfugl will
14
+ run your migrations one by one, checked out to the correct Git commit to make sure
15
+ that they work.
16
+ email: hph@hph.is
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/farfugl.rb
24
+ - lib/farfugl/railtie.rb
25
+ - lib/farfugl/tasks/farfugl.rb
26
+ homepage: https://github.com/hph/farfugl
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.2.0
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Run migrations one by one with the correct environment
50
+ test_files: []