farfugl 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -5
- data/farfugl.gemspec +12 -0
- data/lib/farfugl.rb +18 -7
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0938ba3fb3e4de254fa4879e7e311c5f082c57b
|
4
|
+
data.tar.gz: c97a55c1eeefa4164075e17ec6fec8fb18348859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
6
|
-
application. The
|
7
|
-
was introduced
|
8
|
-
|
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
|
-
**
|
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
|
-
|
8
|
-
|
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|
|
28
|
+
migrations.map { |file| self.hash(file) }
|
25
29
|
end
|
26
30
|
|
27
|
-
def self.
|
28
|
-
`git
|
31
|
+
def self.stash
|
32
|
+
`git stash -u`
|
29
33
|
end
|
30
34
|
|
31
|
-
def self.
|
32
|
-
`git
|
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.
|
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-
|
11
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
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
|
48
|
+
summary: Run old Rails migrations without code dependence problems
|
50
49
|
test_files: []
|