farfugl 0.0.1 → 0.0.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -5
  3. data/farfugl.gemspec +12 -0
  4. data/lib/farfugl.rb +18 -7
  5. metadata +5 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7948ff9674a86db6179d60a5e625d75e48f0752f
4
- data.tar.gz: 826a2837c37c8ac4b56cd5132bcf27f664bebcfd
3
+ metadata.gz: d0938ba3fb3e4de254fa4879e7e311c5f082c57b
4
+ data.tar.gz: c97a55c1eeefa4164075e17ec6fec8fb18348859
5
5
  SHA512:
6
- metadata.gz: 23db79d7007f5df467087f800e16f8364ce2d7dbb5ba0a08e85618aa92df02007d9b0f3a3ed4aff7fa1cba3af950f21a403f127768a8219fbbbf792c7a912e46
7
- data.tar.gz: f02c455e9ea25eff38b907cb4827a8b036f562d78337d3a538c293881de213d5b20f8522ca5937649b9304eb3f8ac590bdbf5ef8c27ed218db095eeaeb17a193
6
+ metadata.gz: e688319d4bfb3cbecc6c153b59cf6e17e4b94203e8386c22d555be08b24131c6f7f5ebd98954042655929878bcbd9614641f10b0714c88db24e8e9cb8de3c66b
7
+ data.tar.gz: 18cee260bd2baeacb070073daf42b1d5f3ac77b936df4d2f1e93abdba7f8caf20f829f005c041660a9dc8cced83e2886401ba33e50fc6043b24908a56fd2baf3
data/README.md CHANGED
@@ -1,14 +1,26 @@
1
1
  Farfugl
2
2
  =======
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/farfugl.png)](http://badge.fury.io/rb/farfugl)
5
+
4
6
  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`.
7
+ migrations often depend on code that doesn't exist in the latest version of the
8
+ application. The simplest solution is to checkout to the commit where each
9
+ migration was introduced (or last modified) and run each migration from there,
10
+ but this can be time-consuming and tedious. **Farfugl** automates this process.
9
11
 
10
- **NOTE**: Farfugl is still under development and is not ready for use.
12
+ Please note that **Farfugl** is still under development and is not completely
13
+ stable; always create backups your database before using it.
11
14
 
12
15
  ### Install
13
16
 
17
+ You can install **Farfugl** on your system like any other gem:
18
+
14
19
  gem install farfugl
20
+
21
+ You can also add `gem 'farfugl'` to your Rails application's Gemfile and run
22
+ `bundle`.
23
+
24
+ ### Usage
25
+
26
+ rake farfugl
data/farfugl.gemspec ADDED
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'farfugl'
3
+ s.version = '0.0.2'
4
+ s.date = '2014-01-19'
5
+ s.summary = 'Run old Rails migrations without code dependence problems'
6
+ s.description = 'Run old Rails migrations without code dependence problems'
7
+ s.authors = ['Haukur Páll Hallvarðsson']
8
+ s.email = 'hph@hph.is'
9
+ s.files = `git ls-files`.split
10
+ s.homepage = 'https://github.com/hph/farfugl'
11
+ s.license = 'MIT'
12
+ end
data/lib/farfugl.rb CHANGED
@@ -4,8 +4,8 @@ module Farfugl
4
4
  def self.schema_versions
5
5
  schema_table = ActiveRecord::Migrator.schema_migrations_table_name
6
6
  query = "SELECT version FROM #{schema_table}"
7
- versions = ActiveRecord::Base.connection.select_values(query)
8
- versions.map! { |version| "%.3d" % version }
7
+ ActiveRecord::Base.connection.select_values(query)
8
+ .map { |version| "%.3d" % version }
9
9
  end
10
10
 
11
11
  def self.pending_migrations(versions)
@@ -20,16 +20,24 @@ module Farfugl
20
20
  migrations
21
21
  end
22
22
 
23
+ def self.hash(file)
24
+ `git log -n 1 -- #{file}`.split[1]
25
+ end
26
+
23
27
  def self.hashes(migrations)
24
- migrations.map { |file| `git log -n 1 -- #{file}`.split[1] }
28
+ migrations.map { |file| self.hash(file) }
25
29
  end
26
30
 
27
- def self.current_branch
28
- `git rev-parse --abbrev-ref HEAD`
31
+ def self.stash
32
+ `git stash -u`
29
33
  end
30
34
 
31
- def self.untracked_files
32
- `git status --porcelain 2>/dev/null| grep "^??" | wc -l`
35
+ def self.unstash
36
+ `git stash pop`
37
+ end
38
+
39
+ def self.current_branch
40
+ `git rev-parse --abbrev-ref HEAD`
33
41
  end
34
42
 
35
43
  def self.checkout(destination)
@@ -37,12 +45,15 @@ module Farfugl
37
45
  end
38
46
 
39
47
  def self.migrate
48
+ self.stash
40
49
  original_branch = self.current_branch
41
50
  hashes = self.hashes(self.pending_migrations(self.schema_versions))
42
51
  hashes.each do |commit_hash|
43
52
  self.checkout(commit_hash)
44
53
  Rake::Task['db:migrate'].invoke
54
+ Rake::Task['db:migrate'].reenable
45
55
  end
46
56
  self.checkout(original_branch)
57
+ self.unstash
47
58
  end
48
59
  end
metadata CHANGED
@@ -1,18 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farfugl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haukur Páll Hallvarðsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2014-01-19 00:00:00.000000000 Z
12
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.
13
+ description: Run old Rails migrations without code dependence problems
16
14
  email: hph@hph.is
17
15
  executables: []
18
16
  extensions: []
@@ -20,6 +18,7 @@ extra_rdoc_files: []
20
18
  files:
21
19
  - LICENSE
22
20
  - README.md
21
+ - farfugl.gemspec
23
22
  - lib/farfugl.rb
24
23
  - lib/farfugl/railtie.rb
25
24
  - lib/farfugl/tasks/farfugl.rb
@@ -46,5 +45,5 @@ rubyforge_project:
46
45
  rubygems_version: 2.2.0
47
46
  signing_key:
48
47
  specification_version: 4
49
- summary: Run migrations one by one with the correct environment
48
+ summary: Run old Rails migrations without code dependence problems
50
49
  test_files: []