switchman 1.8.0 → 1.8.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: e86d6e07988c45f8c70c42c92ece5263797af099
4
- data.tar.gz: 624f54c1a3735b12050b977177076fc3fc870027
3
+ metadata.gz: 50222908649b926ff4aadbe563d555b8e08bb6ef
4
+ data.tar.gz: 1ed9670ef0a8e48243f9089f27c8defe49f95f51
5
5
  SHA512:
6
- metadata.gz: f30d8b5ee490486c13a4f800a09c2bc29ba266e98e839980242562b46f0e0e080e68d7039019d5a69e7944d232829bd592521e86f7206e5bd35cf42cf360a208
7
- data.tar.gz: 9e3b24c5493efce7a36e5da23a0dc471dc878a034125e8304dccb05c7beabef5daa009c87360f5e1c5bc9293f5b3892a5a624a86fffcbdea40fca44bb7878f8c
6
+ metadata.gz: 96128751d37b322f381227b2c4326f683a34f1700853001f3a0071c033f584e204677c1d836c129c86cb856005bb321263e9ad5af67160cc7a551a909d894e59
7
+ data.tar.gz: 3cda176ecdd6c7857b6e8d1bdfef3c43b08123d665fce3c3d35c2a11c007cc706ee47079e2755192d9a21d6112808bc403fe9e87e259c52c24aa4e5b0aefc68d
@@ -198,7 +198,7 @@ module Switchman
198
198
  scopes = Hash[database_servers.map do |server|
199
199
  server_scope = server.shards.merge(scope)
200
200
  if parallel == 1
201
- subscopes = [server_scope]
201
+ subscopes = server_scope
202
202
  else
203
203
  subscopes = []
204
204
  total = server_scope.count
@@ -56,20 +56,40 @@ module Switchman
56
56
  SQL
57
57
  end
58
58
 
59
- def table_exists?(name)
59
+ method_name = ::Rails.version >= '5' ? :data_source_exists? : :table_exists?
60
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
61
+ def #{method_name}(name)
62
+ name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(name.to_s)
63
+ return false unless name.identifier
64
+ if !name.schema && use_qualified_names?
65
+ name.instance_variable_set(:@schema, shard.name)
66
+ end
67
+
68
+ exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0
69
+ SELECT COUNT(*)
70
+ FROM pg_class c
71
+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
72
+ WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
73
+ AND c.relname = '\#{name.identifier}'
74
+ AND n.nspname = \#{name.schema ? "'\#{name.schema}'" : 'ANY (current_schemas(false))'}
75
+ SQL
76
+ end
77
+ RUBY
78
+
79
+ def view_exists?(name)
60
80
  name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(name.to_s)
61
81
  return false unless name.identifier
62
82
  if !name.schema && use_qualified_names?
63
83
  name.instance_variable_set(:@schema, shard.name)
64
84
  end
65
85
 
66
- exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0
67
- SELECT COUNT(*)
68
- FROM pg_class c
69
- LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
70
- WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
71
- AND c.relname = '#{name.identifier}'
72
- AND n.nspname = #{name.schema ? "'#{name.schema}'" : 'ANY (current_schemas(false))'}
86
+ select_values(<<-SQL, 'SCHEMA').any?
87
+ SELECT c.relname
88
+ FROM pg_class c
89
+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
90
+ WHERE c.relkind IN ('v','m') -- (v)iew, (m)aterialized view
91
+ AND c.relname = '#{name.identifier}'
92
+ AND n.nspname = #{name.schema ? "'#{name.schema}'" : 'ANY (current_schemas(false))'}
73
93
  SQL
74
94
  end
75
95
 
@@ -175,7 +195,14 @@ module Switchman
175
195
  options[:on_delete] = extract_foreign_key_action(row['on_delete'])
176
196
  options[:on_update] = extract_foreign_key_action(row['on_update'])
177
197
 
178
- ::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(table_name, row['to_table'], options)
198
+ # strip the schema name from to_table if it matches
199
+ to_table = row['to_table']
200
+ to_table_qualified_name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(to_table)
201
+ if use_qualified_names? && to_table_qualified_name.schema == shard.name
202
+ to_table = to_table_qualified_name.identifier
203
+ end
204
+
205
+ ::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(table_name, to_table, options)
179
206
  end
180
207
  end
181
208
  end
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.8.0"
2
+ VERSION = "1.8.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-08 00:00:00.000000000 Z
13
+ date: 2016-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
254
  version: '0'
255
255
  requirements: []
256
256
  rubyforge_project:
257
- rubygems_version: 2.5.1
257
+ rubygems_version: 2.5.2
258
258
  signing_key:
259
259
  specification_version: 4
260
260
  summary: Rails 4 sharding magic