redshift_simple_migrator 0.1.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01923b9e53ca268191c749379cc7e8ba0f3ba2db
4
- data.tar.gz: 355dc3153e7148fdee4d3e5858ccaae1ab00e131
3
+ metadata.gz: df47cc4f31ba3e1849b1d60811a077d2d50e9c1f
4
+ data.tar.gz: 7f406e403126d9d1232486288e13210467c3b358
5
5
  SHA512:
6
- metadata.gz: 976fa156dd49aa6214ddaa7ee32b27406a7dc5b8699c8c86da9eab78413c2342cf3705acb3317e81a0d84c6c3e6720c0b2cdee96ae089879ac6bbc2f72339bb1
7
- data.tar.gz: dba4b32033ef4f92d6a0f58e1eb3ca18e87b5eb78816842350d89da2ed0dea3e20bd4cae35ad2fe349e0c201ebc67398543b4a8f9ae6834a3b324677cebc5b2d
6
+ metadata.gz: 4e7a213eb0545a4bee8188d8349d87a6092a529f060e03f2678e004e9b04ddd840ceb52a127fc1a8eda41eb79b200e054953b53248b1419762ff3b2c83308bbe
7
+ data.tar.gz: dbb157f09cf92751e68a54f7ce52e3ad65bf03207799d69d7dbc0378b7bfee3f76f37b44fc183cc2266f5eea29b90b4a45b0a4ad8f9f4e7c24210f7bee111ff1
@@ -1,12 +1,18 @@
1
1
  require "redshift_simple_migrator/version"
2
2
 
3
3
  module RedshiftSimpleMigrator
4
- def self.config
5
- RedshiftSimpleMigrator::Configuration.instance
6
- end
4
+ class << self
5
+ def config
6
+ RedshiftSimpleMigrator::Configuration.instance
7
+ end
8
+
9
+ def configure
10
+ yield self.config
11
+ end
7
12
 
8
- def self.configure
9
- yield self.config
13
+ def logger
14
+ config.logger
15
+ end
10
16
  end
11
17
  end
12
18
 
@@ -10,6 +10,8 @@ module RedshiftSimpleMigrator
10
10
  "schema_migrations"
11
11
  end
12
12
 
13
+ config_accessor :logger
14
+
13
15
  config_accessor :migrations_path
14
16
 
15
17
  config_accessor :host, :port, :dbname, :user, :password, :connect_timeout
@@ -13,7 +13,7 @@ module RedshiftSimpleMigrator
13
13
  :exec_params,
14
14
  :escape,
15
15
  :escape_string,
16
- :escape_identifier,
16
+ :quote_ident,
17
17
  :escape_literal,
18
18
  to: :connection
19
19
 
@@ -1,12 +1,54 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/callbacks'
3
+ require 'active_support/core_ext/object'
4
+
1
5
  module RedshiftSimpleMigrator
2
6
  class Migration
7
+ include ActiveSupport::Callbacks
8
+ define_callbacks :up, :down, :execute
9
+
10
+ set_callback :up, :before, :display_migration_up_start
11
+ set_callback :up, :after, :display_migration_up_finish
12
+ set_callback :down, :before, :display_migration_down_start
13
+ set_callback :down, :after, :display_migration_down_finish
14
+
15
+ module RunCallbacksWrapper
16
+ def up
17
+ run_callbacks :up do
18
+ super
19
+ end
20
+ end
21
+
22
+ def down
23
+ run_callbacks :down do
24
+ super
25
+ end
26
+ end
27
+
28
+ def exec(*args)
29
+ log_sql(args[0])
30
+ super
31
+ end
32
+
33
+ def execute(*args)
34
+ log_sql(args[0])
35
+ super
36
+ end
37
+ end
38
+
39
+ def self.inherited(subclass)
40
+ subclass.class_eval do
41
+ prepend RunCallbacksWrapper
42
+ end
43
+ end
44
+
3
45
  attr_reader :connection, :version
4
46
 
5
47
  delegate \
6
48
  :exec,
7
49
  :escape,
8
50
  :escape_string,
9
- :escape_identifier,
51
+ :quote_ident,
10
52
  :escape_literal,
11
53
  to: :connection
12
54
  alias :execute :exec
@@ -23,5 +65,26 @@ module RedshiftSimpleMigrator
23
65
  def down
24
66
  raise NotImplementedError
25
67
  end
68
+
69
+ def display_migration_up_start
70
+ puts "== #{self.class.to_s} up migrating =="
71
+ end
72
+
73
+ def display_migration_up_finish
74
+ puts "== #{self.class.to_s} up migrated =="
75
+ end
76
+
77
+ def display_migration_down_start
78
+ puts "== #{self.class.to_s} down migrating =="
79
+ end
80
+
81
+ def display_migration_down_finish
82
+ puts "== #{self.class.to_s} down migrated =="
83
+ end
84
+
85
+ def log_sql(sql)
86
+ puts "-- Execute --\n#{sql}"
87
+ RedshiftSimpleMigrator.logger.try(:info, "SQL (RedshiftSimpleMigrator) #{sql}")
88
+ end
26
89
  end
27
90
  end
@@ -13,7 +13,7 @@ module RedshiftSimpleMigrator
13
13
  @connection = Connection.new
14
14
  @migrations_path = config.migrations_path
15
15
  @schema_migrations_table_name =
16
- @connection.escape_identifier(config.schema_migrations_table_name)
16
+ @connection.quote_ident(config.schema_migrations_table_name)
17
17
 
18
18
  @current_version_is_loaded = nil
19
19
  @current_migrations = nil
@@ -24,7 +24,7 @@ module RedshiftSimpleMigrator
24
24
 
25
25
  migrations = Dir.entries(migrations_path).map do |name|
26
26
  if match = MIGRATION_FILE_PATTERN.match(name)
27
- load File.expand_path(File.join(migrations_path, name))
27
+ require File.expand_path(File.join(migrations_path, name))
28
28
  migration_class = match[:migration_name].camelcase.constantize
29
29
  migration_class.new(connection, match[:version].to_i)
30
30
  end
@@ -3,6 +3,7 @@ module RedshiftSimpleMigrator
3
3
  initializer "redshift_simple_migrator.initialization" do
4
4
  RedshiftSimpleMigrator.configure do |c|
5
5
  c.migrations_path = Rails.root.join("redshift", "migrate").to_s
6
+ c.logger = Rails.logger
6
7
  end
7
8
  end
8
9
 
@@ -1,3 +1,3 @@
1
1
  module RedshiftSimpleMigrator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redshift_simple_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-16 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg