schema_plus_core 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a77d048b0af1593358c7a3a3a65eb57eddb2e8088fa5ac0d1704a65d0fe90ea
4
- data.tar.gz: 6509557c46101b4fccf4f8cf51100a2c00980a31d4b273523ad3e5be15b470cb
3
+ metadata.gz: c5c91ca6a28894c17bf6b73d7b8c57f03500dd6474194e5df25afe8727a3691c
4
+ data.tar.gz: 32d4f2437d5d3ff1f31f050fb407f26dc80bdaabeb81f8779dfbfd72182de49e
5
5
  SHA512:
6
- metadata.gz: 666b330c46324e8b198b649cffa95fce5cba396ca2897919ed05ee93dcf03e5ea52ed6698a2567dd851a2ce18ca06f4e47c5d7da53429623afe20a513da0f786
7
- data.tar.gz: 38188d56fc44dcd55bb200f732dec9625d6aa0e22dac55a534c5062d127f59224fe93d05b250b2dda161e85ba611067977e73f104230ca112936d7454d6aa37b
6
+ metadata.gz: 2778bbf477a925da8a58dbb577e0a2ac292a919fd3db813f2d404cce2957438f329f7ed2d567fe1f24ebcde15ea5225cafea854b831db4bb23168983b0d165bd
7
+ data.tar.gz: 8571518821c17bf21cbf6ff77c4dec9c4ac29d501323446fd2df30d9453e8918597ca41d2c5aec09aea580feae7ad9ff9a57b7c08c8cc270ec7df73c0d64913f
data/README.md CHANGED
@@ -444,6 +444,7 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
444
444
 
445
445
  ## Release Notes
446
446
 
447
+ * 2.2.3 Fix dumping complex expression based indexes in AR 5.x
447
448
  * 2.2.2 Fixed dumping tables in postgresql in AR 5.2 when the PK is not a bigint.
448
449
  * 2.2.1 Fixed expression index handling in AR5.x.
449
450
  * 2.2.0 Added AR5.2 support. Thanks to [@jeremyyap](https://github.com/jeremyyap)
@@ -44,6 +44,54 @@ module SchemaPlus
44
44
  end
45
45
  end
46
46
 
47
+ TABLE_COLUMN_MATCHES = [
48
+ [ # first match expression index case
49
+ %r{
50
+ ^
51
+ t\.index \s*
52
+ "(?<index_cols>(?:[^"\\]|\\.)*?)" \s*
53
+ , \s*
54
+ name\: \s* [:'"](?<name>[^"\s]+)[,"]? \s*
55
+ ,? \s*
56
+ (?<options>.*)
57
+ $
58
+ }x,
59
+ ->(m) {
60
+ index_cols = m[:index_cols].gsub('\\"', '"')
61
+ SchemaDump::Table::Index.new name: m[:name], columns: index_cols, options: eval("{" + m[:options] + "}")
62
+ }
63
+ ],
64
+ [ # general matching of columns
65
+ %r{
66
+ ^
67
+ t\.(?<type>\S+) \s*
68
+ [:'"](?<name>[^"\s]+)[,"]? \s*
69
+ ,? \s*
70
+ (?<options>.*)
71
+ $
72
+ }x,
73
+ ->(m) {
74
+ SchemaDump::Table::Column.new name: m[:name], type: m[:type], options: eval("{" + m[:options] + "}"), comments: []
75
+ }
76
+ ],
77
+ [ # index definitions with multiple columns
78
+ %r{
79
+ ^
80
+ t\.index \s*
81
+ \[(?<index_cols>.*?)\] \s*
82
+ , \s*
83
+ name\: \s* [:'"](?<name>[^"\s]+)[,"]? \s*
84
+ ,? \s*
85
+ (?<options>.*)
86
+ $
87
+ }x,
88
+ ->(m) {
89
+ index_cols = m[:index_cols].tr(%q{'":}, '').strip.split(/\s*,\s*/)
90
+ SchemaDump::Table::Index.new name: m[:name], columns: index_cols, options: eval("{#{m[:options]}}")
91
+ }
92
+ ]
93
+ ].freeze
94
+
47
95
  def table(table, _)
48
96
  SchemaMonkey::Middleware::Dumper::Table.start(dumper: self, connection: @connection, dump: @dump, table: @dump.tables[table] = SchemaDump::Table.new(name: table)) do |env|
49
97
  stream = StringIO.new
@@ -68,34 +116,13 @@ module SchemaPlus
68
116
  env.table.trailer = m[:trailer].split("\n").map(&:strip).reject{|s| s.blank?}
69
117
  table_objects = m[:columns].strip.split("\n").map { |col|
70
118
  cs = col.strip
71
- m = cs.match %r{
72
- ^
73
- t\.(?<type>\S+) \s*
74
- [:'"](?<name>[^"\s]+)[,"]? \s*
75
- ,? \s*
76
- (?<options>.*)
77
- $
78
- }x
79
- if !m.nil?
80
- SchemaDump::Table::Column.new name: m[:name], type: m[:type], options: eval("{" + m[:options] + "}"), comments: []
81
- else
82
- m = cs.match %r{
83
- ^
84
- t\.index \s*
85
- \[(?<index_cols>.*?)\] \s*
86
- , \s*
87
- name\: \s* [:'"](?<name>[^"\s]+)[,"]? \s*
88
- ,? \s*
89
- (?<options>.*)
90
- $
91
- }x
92
- if m.nil?
93
- nil
94
- else
95
- index_cols = m[:index_cols].tr(%q{'":}, '').strip.split(/\s*,\s*/)
96
- SchemaDump::Table::Index.new name: m[:name], columns: index_cols, options: eval("{#{m[:options]}}")
97
- end
119
+ result = nil
120
+ # find the first regex that matches and grab the column definition
121
+ TABLE_COLUMN_MATCHES.find do |(r, l)|
122
+ m = cs.match r
123
+ result = m.nil? ? nil : l.call(m)
98
124
  end
125
+ result
99
126
  }.reject { |o| o.nil? }
100
127
  env.table.columns = table_objects.select { |o| o.is_a? SchemaDump::Table::Column }
101
128
  env.table.indexes = table_objects.select { |o| o.is_a? SchemaDump::Table::Index }
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module Core
3
- VERSION = "2.2.2"
3
+ VERSION = "2.2.3"
4
4
  end
5
5
  end
@@ -91,6 +91,20 @@ describe SchemaMonkey::Middleware::Dumper do
91
91
 
92
92
  Then { expect(dump).to_not match(/create_table "inttable", id: :serial.*default:/m) }
93
93
  end
94
+
95
+ context 'expression index handling', postgresql: :only do
96
+ before(:each) do
97
+ migration.create_table "expressions" do |t|
98
+ t.string :field
99
+ t.string :column
100
+ t.index 'lower(field), id', name: 'index_expression_field'
101
+ t.index 'lower("column"), id', name: 'index_expression_column'
102
+ end
103
+ end
104
+
105
+ Then { expect(dump).to match(/index "lower.+field.+, id", :name=>"index_expression_field"/) }
106
+ Then { expect(dump).to match(/index "lower.+"column\\".+, id", :name=>"index_expression_column"/) }
107
+ end
94
108
  end
95
109
 
96
110
  context TestDumper::Middleware::Dumper::Table do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-15 00:00:00.000000000 Z
11
+ date: 2018-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord