pg-migrator 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pg-migrator/version.rb +1 -1
- data/lib/pg-migrator.rb +10 -8
- data/pg-migrator.gemspec +3 -3
- data/spec/migrator_spec.rb +3 -1
- metadata +8 -8
data/lib/pg-migrator/version.rb
CHANGED
data/lib/pg-migrator.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
require_relative 'pg-migrator/version'
|
3
3
|
require 'pg'
|
4
|
+
require 'logger'
|
4
5
|
|
5
6
|
module PG
|
6
7
|
class Migrator
|
7
|
-
def initialize(database_url, migrations_dir = './db/migrations')
|
8
|
+
def initialize(database_url, migrations_dir = './db/migrations', logger = Logger.new(STDOUT))
|
8
9
|
@pg = PGconn.connect database_url
|
9
10
|
@pg.exec 'SET client_min_messages = warning'
|
10
11
|
@migrations_dir = migrations_dir
|
11
|
-
|
12
|
-
|
13
|
-
def close
|
14
|
-
@pg.finish
|
12
|
+
@log = logger
|
15
13
|
end
|
16
14
|
|
17
15
|
def reset
|
@@ -35,7 +33,7 @@ module PG
|
|
35
33
|
id = m.sub /.*\/(\d+)_.*/, '\1'
|
36
34
|
name = m.sub /.*\/\d+_([^\.]*).sql$/, '\1'
|
37
35
|
next if applied.any? { |a| a['id'] == id }
|
38
|
-
|
36
|
+
@log.info "Applying #{File.basename m}"
|
39
37
|
conn.exec File.read m
|
40
38
|
conn.exec 'INSERT INTO migration (id, name) VALUES ($1, $2)', [id, name]
|
41
39
|
end
|
@@ -49,13 +47,17 @@ module PG
|
|
49
47
|
name = applied.first['name']
|
50
48
|
down_sql_file = "#{@migrations_dir}/#{id}_#{name}_down.sql"
|
51
49
|
unless File.exists? down_sql_file
|
52
|
-
|
50
|
+
@log.error "No down migration found for #{id} #{name} at #{down_sql_file}"
|
53
51
|
return
|
54
52
|
end
|
55
|
-
|
53
|
+
@log.info "Applying #{File.basename down_sql_file}"
|
56
54
|
conn.exec File.read down_sql_file
|
57
55
|
conn.exec "DELETE FROM migration WHERE id = $1", [id]
|
58
56
|
end
|
59
57
|
end
|
58
|
+
|
59
|
+
def close
|
60
|
+
@pg.finish
|
61
|
+
end
|
60
62
|
end
|
61
63
|
end
|
data/pg-migrator.gemspec
CHANGED
@@ -4,9 +4,9 @@ require File.expand_path('../lib/pg-migrator/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Carl Hörberg"]
|
6
6
|
gem.email = ["carl.hoerberg@gmail.com"]
|
7
|
-
gem.description = %q{
|
8
|
-
gem.summary = %q{Drop raw
|
9
|
-
gem.homepage = ""
|
7
|
+
gem.description = %q{Rake migration tasks which utilities pure SQL files}
|
8
|
+
gem.summary = %q{Drop raw SQL files in db/migrations and add require 'pg-migrator/tasks' to your Rakefile}
|
9
|
+
gem.homepage = "https://github.com/carlhoerberg/pg-migrator"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
data/spec/migrator_spec.rb
CHANGED
@@ -4,7 +4,9 @@ require './lib/pg-migrator'
|
|
4
4
|
describe PG::Migrator do
|
5
5
|
before do
|
6
6
|
@pg = PGconn.connect :dbname => 'pg-migrator'
|
7
|
-
|
7
|
+
logger = Logger.new STDERR
|
8
|
+
logger.level = Logger::FATAL
|
9
|
+
@migrator = PG::Migrator.new({:dbname => 'pg-migrator'}, '/tmp', logger)
|
8
10
|
end
|
9
11
|
|
10
12
|
describe 'reset' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg-migrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-24 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
16
|
-
requirement: &
|
16
|
+
requirement: &70154890788080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70154890788080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: minitest
|
27
|
-
requirement: &
|
27
|
+
requirement: &70154890787660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,8 +32,8 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
description:
|
35
|
+
version_requirements: *70154890787660
|
36
|
+
description: Rake migration tasks which utilities pure SQL files
|
37
37
|
email:
|
38
38
|
- carl.hoerberg@gmail.com
|
39
39
|
executables: []
|
@@ -49,7 +49,7 @@ files:
|
|
49
49
|
- lib/pg-migrator/version.rb
|
50
50
|
- pg-migrator.gemspec
|
51
51
|
- spec/migrator_spec.rb
|
52
|
-
homepage:
|
52
|
+
homepage: https://github.com/carlhoerberg/pg-migrator
|
53
53
|
licenses: []
|
54
54
|
post_install_message:
|
55
55
|
rdoc_options: []
|
@@ -72,7 +72,7 @@ rubyforge_project:
|
|
72
72
|
rubygems_version: 1.8.6
|
73
73
|
signing_key:
|
74
74
|
specification_version: 3
|
75
|
-
summary: Drop raw
|
75
|
+
summary: Drop raw SQL files in db/migrations and add require 'pg-migrator/tasks' to
|
76
76
|
your Rakefile
|
77
77
|
test_files:
|
78
78
|
- spec/migrator_spec.rb
|