global_uid 4.0.0.beta1 → 4.0.0.beta2

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
  SHA256:
3
- metadata.gz: 0a02789fdd302a6dbc207c590c60ce5b5909f8430e3432813af90d0373efd71b
4
- data.tar.gz: 4cf5cd96f7b8855b546a1741c67dac5db6bb9b42cca3105bbe741423a2f2e66e
3
+ metadata.gz: f572a1f8e4c4e113bbe071eedc10d0311a89827adfa318dd577e3ec0b0fc12bd
4
+ data.tar.gz: 5075c514fbbb2f7fef0c38534ae094779d98b536924dcb5e19bb031f9273877e
5
5
  SHA512:
6
- metadata.gz: 9e36b732bbea40d81423498b9ec9365e39688601691524b615a9b1cc0955b5dbcbf7b9788128bcb5673b08ccd37c49b44a7990d8a62f578358cd9ca8116d17fb
7
- data.tar.gz: 73b1d6ff9808d94c14e1618b7da2137e0ad9c2b02442941b788519ebdc77daec7bfc8be67715ec16294062ea8ae334c1b437a198342f096623bd4f124585385c
6
+ metadata.gz: 7e2cdf576215f37dfdf18e132b86d80f088d6c40f7a751bdf0ed95965596389cfc61df046fa1aa0136b7f0f56c091a9cf8d869a3c2f06395bb44a4bf4362d5f1
7
+ data.tar.gz: c8f1c21a6259983780c860298b9ab119aeea9f9d4c5541940a78b5433dab9df6a01b26ca0567fb4b395cf375a84fe027a8c0efaaeb9feb77dc3ca9f63631fe84
@@ -23,6 +23,22 @@ module GlobalUid
23
23
  yield configuration if block_given?
24
24
  end
25
25
 
26
+ def self.disable!
27
+ self.configuration.disabled = true
28
+ end
29
+
30
+ def self.enable!
31
+ self.configuration.disabled = false
32
+ end
33
+
34
+ def self.enabled?
35
+ !self.disabled?
36
+ end
37
+
38
+ def self.disabled?
39
+ self.configuration.disabled
40
+ end
41
+
26
42
  # @private
27
43
  def self.reset_configuration
28
44
  @configuration = nil
@@ -8,7 +8,7 @@ module GlobalUid
8
8
  end
9
9
 
10
10
  def global_uid_before_create
11
- return if GlobalUid.configuration.disabled?
11
+ return if GlobalUid.disabled?
12
12
  return if self.class.global_uid_disabled
13
13
 
14
14
  self.id = self.class.generate_uid
@@ -11,7 +11,6 @@ module GlobalUid
11
11
  attr_accessor :suppress_increment_exceptions
12
12
  attr_accessor :storage_engine
13
13
 
14
- alias_method :disabled?, :disabled
15
14
  alias_method :connection_shuffling?, :connection_shuffling
16
15
  alias_method :suppress_increment_exceptions?, :suppress_increment_exceptions
17
16
 
@@ -3,7 +3,7 @@ module GlobalUid
3
3
  module MigrationExtension
4
4
 
5
5
  def create_table(name, options = {}, &blk)
6
- uid_enabled = !(GlobalUid.configuration.disabled? || options[:use_global_uid] == false)
6
+ uid_enabled = GlobalUid.enabled? && options[:use_global_uid] != false
7
7
 
8
8
  # rules for stripping out auto_increment -- enabled and not a "PK-less" table
9
9
  remove_auto_increment = uid_enabled && !(options[:id] == false)
@@ -20,9 +20,8 @@ module GlobalUid
20
20
  GlobalUid::Base.with_servers do |server|
21
21
  server.create_uid_table!(
22
22
  name: id_table_name,
23
- uid_type: options[:uid_type] || "bigint(21) UNSIGNED",
24
- start_id: options[:start_id] || 1,
25
- storage_engine: GlobalUid.configuration.storage_engine
23
+ uid_type: options[:uid_type],
24
+ start_id: options[:start_id]
26
25
  )
27
26
  end
28
27
  end
@@ -30,7 +29,7 @@ module GlobalUid
30
29
  end
31
30
 
32
31
  def drop_table(name, options = {})
33
- if !GlobalUid.configuration.disabled? && options[:use_global_uid] == true
32
+ if GlobalUid.enabled? && options[:use_global_uid] == true
34
33
  id_table_name = options[:global_uid_table] || GlobalUid::Base.id_table_from_name(name)
35
34
  GlobalUid::Base.with_servers do |server|
36
35
  server.drop_uid_table!(name: id_table_name)
@@ -45,13 +45,16 @@ module GlobalUid
45
45
  @allocator = nil
46
46
  end
47
47
 
48
- def create_uid_table!(name:, uid_type:, start_id:, storage_engine:)
48
+ def create_uid_table!(name:, uid_type: nil, start_id: nil)
49
+ uid_type ||= "bigint(21) UNSIGNED"
50
+ start_id ||= 1
51
+
49
52
  connection.execute("CREATE TABLE IF NOT EXISTS `#{name}` (
50
53
  `id` #{uid_type} NOT NULL AUTO_INCREMENT,
51
54
  `stub` char(1) NOT NULL DEFAULT '',
52
55
  PRIMARY KEY (`id`),
53
56
  UNIQUE KEY `stub` (`stub`)
54
- ) ENGINE=#{storage_engine}")
57
+ ) ENGINE=#{GlobalUid.configuration.storage_engine}")
55
58
 
56
59
  # prime the pump on each server
57
60
  connection.execute("INSERT IGNORE INTO `#{name}` VALUES(#{start_id}, 'a')")
@@ -0,0 +1,44 @@
1
+ module GlobalUid
2
+ module TestSupport
3
+ # Tables should be created through the MigrationExtension but
4
+ # if you want to manually create and drop the '_id' tables,
5
+ # you can do so via this module
6
+ class << self
7
+ def create_uid_tables(tables: [], uid_type: nil, start_id: nil)
8
+ return if GlobalUid.disabled?
9
+
10
+ GlobalUid::Base.with_servers do |server|
11
+ tables.each do |table|
12
+ server.create_uid_table!(
13
+ name: GlobalUid::Base.id_table_from_name(table),
14
+ uid_type: uid_type,
15
+ start_id: start_id
16
+ )
17
+ end
18
+ end
19
+ end
20
+
21
+ def drop_uid_tables(tables: [])
22
+ return if GlobalUid.disabled?
23
+
24
+ GlobalUid::Base.with_servers do |server|
25
+ tables.each do |table|
26
+ server.drop_uid_table!(
27
+ name: GlobalUid::Base.id_table_from_name(table)
28
+ )
29
+ end
30
+ end
31
+ end
32
+
33
+ def recreate_uid_tables(tables: [], uid_type: nil, start_id: nil)
34
+ return if GlobalUid.disabled?
35
+
36
+ drop_uid_tables(tables: tables)
37
+ create_uid_tables(tables: tables, uid_type: nil, start_id: start_id)
38
+
39
+ # Reset the servers, clearing any allocations from memory
40
+ GlobalUid::Base.disconnect!
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global_uid
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta1
4
+ version: 4.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Quorning
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-04-28 00:00:00.000000000 Z
14
+ date: 2020-04-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -220,6 +220,7 @@ files:
220
220
  - lib/global_uid/migration_extension.rb
221
221
  - lib/global_uid/schema_dumper_extension.rb
222
222
  - lib/global_uid/server.rb
223
+ - lib/global_uid/test_support.rb
223
224
  homepage: https://github.com/zendesk/global_uid
224
225
  licenses:
225
226
  - MIT