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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f572a1f8e4c4e113bbe071eedc10d0311a89827adfa318dd577e3ec0b0fc12bd
|
4
|
+
data.tar.gz: 5075c514fbbb2f7fef0c38534ae094779d98b536924dcb5e19bb031f9273877e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e2cdf576215f37dfdf18e132b86d80f088d6c40f7a751bdf0ed95965596389cfc61df046fa1aa0136b7f0f56c091a9cf8d869a3c2f06395bb44a4bf4362d5f1
|
7
|
+
data.tar.gz: c8f1c21a6259983780c860298b9ab119aeea9f9d4c5541940a78b5433dab9df6a01b26ca0567fb4b395cf375a84fe027a8c0efaaeb9feb77dc3ca9f63631fe84
|
data/lib/global_uid.rb
CHANGED
@@ -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
|
@@ -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 =
|
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]
|
24
|
-
start_id: options[:start_id]
|
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
|
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)
|
data/lib/global_uid/server.rb
CHANGED
@@ -45,13 +45,16 @@ module GlobalUid
|
|
45
45
|
@allocator = nil
|
46
46
|
end
|
47
47
|
|
48
|
-
def create_uid_table!(name:, uid_type
|
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.
|
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-
|
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
|