uuidable 0.2.7 → 1.0.0
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 +4 -4
- data/.github/workflows/gem-push.yml +25 -0
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -3
- data/Gemfile +2 -0
- data/Gemfile.lock +51 -53
- data/README.md +3 -1
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/lib/uuidable/active_record.rb +22 -5
- data/lib/uuidable/migration.rb +13 -11
- data/lib/uuidable/v1_migration_helpers.rb +143 -0
- data/lib/uuidable/version.rb +3 -1
- data/lib/uuidable.rb +6 -1
- data/uuidable.gemspec +7 -2
- metadata +29 -7
- data/.travis.yml +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f081ae636a60448b89df948da41feb1b11bfdc8a338d79b2c6c407732b2f3f8
|
|
4
|
+
data.tar.gz: 0a878578bbcb7d31c48a8688feeeaef4ac1d5aff333dc7b0b9087f27668d9680
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc2257a1ce64b2e4d3a69b50fd5600b8737c1e9ad733b05cf989ec247115bcd4b002a3a564502e0a69686b37f1421a22972494471aee5d5c91ae2c9fe6b27127
|
|
7
|
+
data.tar.gz: 1c3870cfe1234a8197a8f8d79746b8ba4c2bde15b3d61b83658c52548a2c9a4cd223141a11ac0585cfd8c545aaed7576e266155ecc4158a2d84a8d45e4927e14
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Build + publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: [ v* ]
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
name: Build + Publish
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v1
|
|
12
|
+
|
|
13
|
+
- name: Release Gem
|
|
14
|
+
if: contains(github.ref, 'refs/tags/v')
|
|
15
|
+
uses: cadwallion/publish-rubygems-action@master
|
|
16
|
+
env:
|
|
17
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
|
18
|
+
RELEASE_COMMAND: bundle exec rake release
|
|
19
|
+
# steps:
|
|
20
|
+
# - uses: actions/checkout@v3
|
|
21
|
+
# - name: Set up Ruby
|
|
22
|
+
# uses: ruby/setup-ruby@v1
|
|
23
|
+
# with:
|
|
24
|
+
# ruby-version: .ruby-version
|
|
25
|
+
# bundler-cache: true
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Test
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ '*' ]
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
test:
|
|
19
|
+
runs-on: ${{ matrix.os }}-latest
|
|
20
|
+
strategy:
|
|
21
|
+
matrix:
|
|
22
|
+
os: [ubuntu, macos]
|
|
23
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
|
24
|
+
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v3
|
|
27
|
+
- name: Set up Ruby
|
|
28
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
|
29
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
|
30
|
+
uses: ruby/setup-ruby@v1
|
|
31
|
+
with:
|
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
34
|
+
- name: Run rubocop
|
|
35
|
+
run: bundle exec rubocop
|
|
36
|
+
- name: Run tests
|
|
37
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
uuidable (0.
|
|
4
|
+
uuidable (1.0.0)
|
|
5
5
|
activerecord (>= 4.2, < 7.2)
|
|
6
|
+
mysql-binuuid-rails (>= 1.3, < 2)
|
|
6
7
|
uuidtools (>= 2.1, < 3)
|
|
7
8
|
|
|
8
9
|
GEM
|
|
9
10
|
remote: https://rubygems.org/
|
|
10
11
|
specs:
|
|
11
|
-
activemodel (7.
|
|
12
|
-
activesupport (= 7.
|
|
13
|
-
activerecord (7.
|
|
14
|
-
activemodel (= 7.
|
|
15
|
-
activesupport (= 7.
|
|
16
|
-
|
|
17
|
-
activesupport (7.1.3.4)
|
|
18
|
-
base64
|
|
19
|
-
bigdecimal
|
|
12
|
+
activemodel (7.0.4.1)
|
|
13
|
+
activesupport (= 7.0.4.1)
|
|
14
|
+
activerecord (7.0.4.1)
|
|
15
|
+
activemodel (= 7.0.4.1)
|
|
16
|
+
activesupport (= 7.0.4.1)
|
|
17
|
+
activesupport (7.0.4.1)
|
|
20
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
21
|
-
connection_pool (>= 2.2.5)
|
|
22
|
-
drb
|
|
23
19
|
i18n (>= 1.6, < 2)
|
|
24
20
|
minitest (>= 5.1)
|
|
25
|
-
mutex_m
|
|
26
21
|
tzinfo (~> 2.0)
|
|
27
|
-
addressable (2.
|
|
28
|
-
|
|
22
|
+
addressable (2.8.0)
|
|
23
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
24
|
+
ast (2.4.2)
|
|
29
25
|
backports (3.6.8)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
concurrent-ruby (1.3.4)
|
|
33
|
-
connection_pool (2.4.1)
|
|
34
|
-
diff-lcs (1.2.5)
|
|
35
|
-
drb (2.2.1)
|
|
26
|
+
concurrent-ruby (1.1.10)
|
|
27
|
+
diff-lcs (1.5.0)
|
|
36
28
|
ethon (0.8.1)
|
|
37
29
|
ffi (>= 1.3.0)
|
|
38
30
|
faraday (0.9.2)
|
|
@@ -48,49 +40,55 @@ GEM
|
|
|
48
40
|
net-http-persistent (>= 2.7)
|
|
49
41
|
net-http-pipeline
|
|
50
42
|
highline (1.7.8)
|
|
51
|
-
i18n (1.
|
|
43
|
+
i18n (1.12.0)
|
|
52
44
|
concurrent-ruby (~> 1.0)
|
|
53
45
|
json (2.3.1)
|
|
54
46
|
launchy (2.4.3)
|
|
55
47
|
addressable (~> 2.3)
|
|
56
|
-
minitest (5.
|
|
48
|
+
minitest (5.17.0)
|
|
57
49
|
multi_json (1.11.2)
|
|
58
50
|
multipart-post (2.0.0)
|
|
59
|
-
|
|
51
|
+
mysql-binuuid-rails (1.3.0)
|
|
52
|
+
activerecord (>= 5)
|
|
60
53
|
net-http-persistent (2.9.4)
|
|
61
54
|
net-http-pipeline (1.0.1)
|
|
62
|
-
parallel (1.
|
|
63
|
-
parser (2.
|
|
64
|
-
ast (~> 2.
|
|
65
|
-
|
|
55
|
+
parallel (1.22.1)
|
|
56
|
+
parser (3.1.2.0)
|
|
57
|
+
ast (~> 2.4.1)
|
|
58
|
+
public_suffix (4.0.7)
|
|
66
59
|
pusher-client (0.6.2)
|
|
67
60
|
json
|
|
68
61
|
websocket (~> 1.0)
|
|
69
|
-
rainbow (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
rspec-
|
|
75
|
-
rspec-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
62
|
+
rainbow (3.1.1)
|
|
63
|
+
rake (13.0.6)
|
|
64
|
+
regexp_parser (2.5.0)
|
|
65
|
+
rexml (3.2.5)
|
|
66
|
+
rspec (3.11.0)
|
|
67
|
+
rspec-core (~> 3.11.0)
|
|
68
|
+
rspec-expectations (~> 3.11.0)
|
|
69
|
+
rspec-mocks (~> 3.11.0)
|
|
70
|
+
rspec-core (3.11.0)
|
|
71
|
+
rspec-support (~> 3.11.0)
|
|
72
|
+
rspec-expectations (3.11.0)
|
|
79
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
80
|
-
rspec-support (~> 3.
|
|
81
|
-
rspec-mocks (3.
|
|
74
|
+
rspec-support (~> 3.11.0)
|
|
75
|
+
rspec-mocks (3.11.1)
|
|
82
76
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
-
rspec-support (~> 3.
|
|
84
|
-
rspec-support (3.
|
|
85
|
-
rubocop (
|
|
77
|
+
rspec-support (~> 3.11.0)
|
|
78
|
+
rspec-support (3.11.0)
|
|
79
|
+
rubocop (1.32.0)
|
|
80
|
+
json (~> 2.3)
|
|
86
81
|
parallel (~> 1.10)
|
|
87
|
-
parser (>=
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
parser (>= 3.1.0.0)
|
|
83
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
84
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
85
|
+
rexml (>= 3.2.5, < 4.0)
|
|
86
|
+
rubocop-ast (>= 1.19.1, < 2.0)
|
|
90
87
|
ruby-progressbar (~> 1.7)
|
|
91
|
-
unicode-display_width (
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
89
|
+
rubocop-ast (1.19.1)
|
|
90
|
+
parser (>= 3.1.1.0)
|
|
91
|
+
ruby-progressbar (1.11.0)
|
|
94
92
|
travis (1.8.2)
|
|
95
93
|
backports
|
|
96
94
|
faraday (~> 0.9)
|
|
@@ -102,9 +100,9 @@ GEM
|
|
|
102
100
|
typhoeus (~> 0.6, >= 0.6.8)
|
|
103
101
|
typhoeus (0.8.0)
|
|
104
102
|
ethon (>= 0.8.0)
|
|
105
|
-
tzinfo (2.0.
|
|
103
|
+
tzinfo (2.0.5)
|
|
106
104
|
concurrent-ruby (~> 1.0)
|
|
107
|
-
unicode-display_width (
|
|
105
|
+
unicode-display_width (2.2.0)
|
|
108
106
|
uuidtools (2.2.0)
|
|
109
107
|
websocket (1.2.2)
|
|
110
108
|
|
|
@@ -112,7 +110,7 @@ PLATFORMS
|
|
|
112
110
|
ruby
|
|
113
111
|
|
|
114
112
|
DEPENDENCIES
|
|
115
|
-
bundler (~>
|
|
113
|
+
bundler (~> 2.4)
|
|
116
114
|
rake (~> 13.0)
|
|
117
115
|
rspec (~> 3.0)
|
|
118
116
|
rubocop
|
|
@@ -120,4 +118,4 @@ DEPENDENCIES
|
|
|
120
118
|
uuidable!
|
|
121
119
|
|
|
122
120
|
BUNDLED WITH
|
|
123
|
-
|
|
121
|
+
2.4.22
|
data/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
# Uuidable
|
|
1
|
+
# Uuidable
|
|
2
|
+
|
|
3
|
+
[](https://github.com/flant/uuidable/actions/workflows/ruby.yml) [](https://badge.fury.io/rb/uuidable)
|
|
2
4
|
|
|
3
5
|
With this gem you can use UUID instead of id in routes. But id is still primary key.
|
|
4
6
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Uuidable
|
|
2
4
|
# ActiveRecord mixin
|
|
3
5
|
module ActiveRecord
|
|
@@ -7,7 +9,7 @@ module Uuidable
|
|
|
7
9
|
|
|
8
10
|
module Finder
|
|
9
11
|
def find(*args)
|
|
10
|
-
if args.first
|
|
12
|
+
if args.first.is_a?(String) && args.first&.match(UUIDTools::UUID_REGEXP)
|
|
11
13
|
find_by_uuid!(*args)
|
|
12
14
|
else
|
|
13
15
|
super
|
|
@@ -19,8 +21,23 @@ module Uuidable
|
|
|
19
21
|
module ClassMethods
|
|
20
22
|
include Finder
|
|
21
23
|
|
|
22
|
-
def uuidable(as_param: true)
|
|
23
|
-
|
|
24
|
+
def uuidable(as_param: true) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
25
|
+
# Configure all uuid columns for MySQL. Database may not be connected (i.e. on assets precompile), so we must supress errors.
|
|
26
|
+
conn_config = respond_to?(:connection_db_config) ? connection_db_config.configuration_hash : connection_config
|
|
27
|
+
if conn_config[:adapter].include?('mysql')
|
|
28
|
+
begin
|
|
29
|
+
columns.select { |c| c.type == :binary && c.limit == 16 && c.name.include?('uuid') }.each do |column|
|
|
30
|
+
attribute column.name.to_sym, MySQLBinUUID::Type.new
|
|
31
|
+
end
|
|
32
|
+
rescue ::ActiveRecord::ConnectionNotEstablished, Mysql2::Error::ConnectionError, ::ActiveRecord::NoDatabaseError # rubocop:disable Lint/SuppressedException
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
after_initialize do
|
|
37
|
+
self.uuid = Uuidable.generate_uuid if attributes.keys.include?('uuid') && uuid.blank?
|
|
38
|
+
self.uuid__old = uuid if respond_to?(:uuid__old)
|
|
39
|
+
end
|
|
40
|
+
|
|
24
41
|
validates :uuid, presence: true, uniqueness: true, if: :uuid_changed?
|
|
25
42
|
|
|
26
43
|
if as_param
|
|
@@ -44,6 +61,6 @@ module Uuidable
|
|
|
44
61
|
end
|
|
45
62
|
|
|
46
63
|
ActiveSupport.on_load(:active_record) do
|
|
47
|
-
ActiveRecord::Base.
|
|
48
|
-
ActiveRecord::Relation.
|
|
64
|
+
ActiveRecord::Base.include Uuidable::ActiveRecord
|
|
65
|
+
ActiveRecord::Relation.prepend Uuidable::ActiveRecord::Finder
|
|
49
66
|
end
|
data/lib/uuidable/migration.rb
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Uuidable
|
|
2
4
|
COLUMN_NAME = :uuid
|
|
3
5
|
COLUMN_TYPE = :binary
|
|
4
|
-
COLUMN_OPTIONS = { limit:
|
|
6
|
+
COLUMN_OPTIONS = { limit: 16, null: false }.freeze
|
|
5
7
|
INDEX_OPTIONS = { unique: true }.freeze
|
|
6
8
|
|
|
7
9
|
# Module adds method to table definition
|
|
8
10
|
module TableDefinition
|
|
9
|
-
def uuid(
|
|
11
|
+
def uuid(column_name = COLUMN_NAME, **opts)
|
|
10
12
|
index_opts = opts.delete(:index)
|
|
11
13
|
index_opts = {} if index_opts.nil?
|
|
12
14
|
|
|
13
|
-
column_name
|
|
15
|
+
column_name ||= opts.delete(:column_name)
|
|
14
16
|
|
|
15
|
-
column column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts)
|
|
16
|
-
index column_name, INDEX_OPTIONS.merge(index_opts) if index_opts
|
|
17
|
+
column column_name, COLUMN_TYPE, **COLUMN_OPTIONS.merge(opts)
|
|
18
|
+
index column_name, **INDEX_OPTIONS.merge(index_opts) if index_opts
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
# Module adds method to alter table migration
|
|
21
23
|
module Migration
|
|
22
|
-
def add_uuid_column(table_name,
|
|
24
|
+
def add_uuid_column(table_name, column_name = COLUMN_NAME, **opts)
|
|
23
25
|
index_opts = opts.delete(:index)
|
|
24
26
|
index_opts = {} if index_opts == true
|
|
25
27
|
|
|
26
|
-
column_name
|
|
28
|
+
column_name ||= opts.delete(:column_name)
|
|
27
29
|
|
|
28
|
-
add_column table_name, column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts)
|
|
30
|
+
add_column table_name, column_name, COLUMN_TYPE, **COLUMN_OPTIONS.merge(opts)
|
|
29
31
|
|
|
30
32
|
add_uuid_index(table_name, index_opts.merge(column_name: column_name)) if index_opts
|
|
31
33
|
end
|
|
@@ -33,13 +35,13 @@ module Uuidable
|
|
|
33
35
|
def add_uuid_index(table_name, opts = {})
|
|
34
36
|
column_name = opts.delete(:column_name) || COLUMN_NAME
|
|
35
37
|
|
|
36
|
-
add_index table_name, column_name, INDEX_OPTIONS.merge(opts)
|
|
38
|
+
add_index table_name, column_name, **INDEX_OPTIONS.merge(opts)
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
if defined? ActiveRecord::ConnectionAdapters::TableDefinition
|
|
42
|
-
ActiveRecord::ConnectionAdapters::TableDefinition.
|
|
44
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.include Uuidable::TableDefinition
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
ActiveRecord::Migration.
|
|
47
|
+
ActiveRecord::Migration.include Uuidable::Migration if defined? ActiveRecord::Migration
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable all
|
|
4
|
+
module Uuidable
|
|
5
|
+
module V1MigrationHelpers
|
|
6
|
+
NEW_POSTFIX = '__new'
|
|
7
|
+
OLD_POSTFIX = '__old'
|
|
8
|
+
|
|
9
|
+
# Will create uuid columns with new type, move data from pre-v1 column and then move pre-v1 to *__old.
|
|
10
|
+
# WARNING: will only work on MySQL 8+.
|
|
11
|
+
def uuidable_migrate_uuid_columns_to_v1(table_name, columns_options = {}, **opts)
|
|
12
|
+
columns_options.stringify_keys!
|
|
13
|
+
uuid_columns = connection.columns(table_name).select do |column|
|
|
14
|
+
(columns_options.blank? || columns_options.key?(column.name)) &&
|
|
15
|
+
valid_column_for_migration?(column, **opts)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
return if uuid_columns.blank?
|
|
19
|
+
|
|
20
|
+
indexes = indexes_with_columns(table_name, uuid_columns)
|
|
21
|
+
|
|
22
|
+
change_table table_name, bulk: true do |t|
|
|
23
|
+
uuid_columns.each do |column|
|
|
24
|
+
options = columns_options[column.name] || { null: column.null }
|
|
25
|
+
t.column :"#{column.name}#{NEW_POSTFIX}", :binary, **COLUMN_OPTIONS.merge(options).merge(after: column.name)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
update = uuid_columns.map do |column, _opts|
|
|
30
|
+
<<~SQL
|
|
31
|
+
`#{table_name}`.`#{column.name}#{NEW_POSTFIX}` = IF(
|
|
32
|
+
IS_UUID(`#{table_name}`.`#{column.name}`),
|
|
33
|
+
UUID_TO_BIN(`#{table_name}`.`#{column.name}`),
|
|
34
|
+
`#{table_name}`.`#{column.name}`
|
|
35
|
+
)
|
|
36
|
+
SQL
|
|
37
|
+
end.join(', ')
|
|
38
|
+
|
|
39
|
+
execute "UPDATE `#{table_name}` SET #{update}"
|
|
40
|
+
|
|
41
|
+
change_table table_name, bulk: true do |t|
|
|
42
|
+
uuid_columns.each do |column|
|
|
43
|
+
t.rename column.name, :"#{column.name}#{OLD_POSTFIX}"
|
|
44
|
+
t.rename :"#{column.name}#{NEW_POSTFIX}", column.name
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
indexes.each do |ind|
|
|
48
|
+
t.remove_index name: ind.name
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# recreate indexes with new column
|
|
53
|
+
change_table table_name, bulk: true do |t|
|
|
54
|
+
indexes.each do |ind|
|
|
55
|
+
t.index ind.columns, name: ind.name, unique: ind.unique
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# WARNING: will only work until *__old columns is not deleted!
|
|
61
|
+
def uuidable_rollback_uuid_columns_from_v1(table_name, *columns)
|
|
62
|
+
columns.map!(&:to_s)
|
|
63
|
+
indexes = indexes(table_name)
|
|
64
|
+
|
|
65
|
+
uuid_columns = connection.columns(table_name).select do |column|
|
|
66
|
+
(columns.blank? || columns.include?(column.name)) &&
|
|
67
|
+
valid_column_for_migration?(column, limit: 16)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return if uuid_columns.blank?
|
|
71
|
+
|
|
72
|
+
indexes = indexes_with_columns(table_name, uuid_columns)
|
|
73
|
+
|
|
74
|
+
change_table table_name, bulk: true do |t|
|
|
75
|
+
uuid_columns.each do |column|
|
|
76
|
+
t.rename column.name, :"#{column.name}#{NEW_POSTFIX}"
|
|
77
|
+
t.rename :"#{column.name}#{OLD_POSTFIX}", column.name
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
indexes.each do |ind|
|
|
81
|
+
t.remove_index name: ind.name
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
change_table table_name, bulk: true do |t|
|
|
86
|
+
uuid_columns.each do |column|
|
|
87
|
+
t.remove :"#{column.name}#{NEW_POSTFIX}"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
indexes.each do |ind|
|
|
91
|
+
t.index name: ind.name, unique: ind.unique
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def uuidable_migrate_all_pre_v1_uuid_columns!
|
|
97
|
+
tables.each do |table_name|
|
|
98
|
+
uuidable_migrate_uuid_columns_to_v1 table_name
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def uuidable_rollback_all_pre_v1_uuid_columns!
|
|
103
|
+
tables.each do |table_name|
|
|
104
|
+
uuidable_rollback_uuid_columns_from_v1 table_name
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# WARNING: this is irreversible migration! It will drop all *uuid__old columns and their indexes in all tables!
|
|
109
|
+
def uuidable_drop_all_pre_v1_uuid_columns!
|
|
110
|
+
tables.each do |table_name|
|
|
111
|
+
indexes = indexes(table_name)
|
|
112
|
+
change_table table_name, bulk: true do |t|
|
|
113
|
+
connection.columns(table_name).each do |column|
|
|
114
|
+
next unless column.name.include?(OLD_POSTFIX)
|
|
115
|
+
|
|
116
|
+
indexes.each do |ind|
|
|
117
|
+
next unless ind.columns.include?(column.name)
|
|
118
|
+
|
|
119
|
+
t.remove_index name: ind.name
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
t.remove column.name
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def valid_column_for_migration?(column, limit: 36, skip_type_check: false)
|
|
129
|
+
column.name.include?('uuid') &&
|
|
130
|
+
!column.name.include?(NEW_POSTFIX) &&
|
|
131
|
+
!column.name.include?(OLD_POSTFIX) &&
|
|
132
|
+
(skip_type_check || (
|
|
133
|
+
column.type == :binary &&
|
|
134
|
+
column.limit == limit
|
|
135
|
+
))
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def indexes_with_columns(table_name, columns)
|
|
139
|
+
indexes(table_name).select { |ind| (ind.columns & columns.map(&:name)).any? }
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
# rubocop:enable all
|
data/lib/uuidable/version.rb
CHANGED
data/lib/uuidable.rb
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'uuidable/version'
|
|
2
|
-
require '
|
|
4
|
+
require 'active_model'
|
|
3
5
|
require 'uuidtools'
|
|
4
6
|
|
|
7
|
+
require 'mysql-binuuid-rails'
|
|
8
|
+
|
|
5
9
|
# Main module
|
|
6
10
|
module Uuidable
|
|
7
11
|
module_function
|
|
@@ -12,4 +16,5 @@ module Uuidable
|
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
require 'uuidable/migration'
|
|
19
|
+
require 'uuidable/v1_migration_helpers'
|
|
15
20
|
require 'uuidable/active_record'
|
data/uuidable.gemspec
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
5
|
require 'uuidable/version'
|
|
4
6
|
|
|
@@ -18,11 +20,14 @@ Gem::Specification.new do |spec|
|
|
|
18
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
19
21
|
spec.require_paths = ['lib']
|
|
20
22
|
|
|
21
|
-
spec.
|
|
23
|
+
spec.required_ruby_version = '>= 2.7'
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.4'
|
|
22
26
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
23
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
24
28
|
spec.add_development_dependency 'travis', '~> 1.8', '>= 1.8.2'
|
|
25
29
|
|
|
26
30
|
spec.add_dependency 'activerecord', '>= 4.2', '< 7.2'
|
|
31
|
+
spec.add_dependency 'mysql-binuuid-rails', '>= 1.3', '< 2'
|
|
27
32
|
spec.add_dependency 'uuidtools', '>= 2.1', '< 3'
|
|
28
33
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uuidable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergey Gnuskov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '2.4'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '2.4'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -92,6 +92,26 @@ dependencies:
|
|
|
92
92
|
- - "<"
|
|
93
93
|
- !ruby/object:Gem::Version
|
|
94
94
|
version: '7.2'
|
|
95
|
+
- !ruby/object:Gem::Dependency
|
|
96
|
+
name: mysql-binuuid-rails
|
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '1.3'
|
|
102
|
+
- - "<"
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '2'
|
|
105
|
+
type: :runtime
|
|
106
|
+
prerelease: false
|
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '1.3'
|
|
112
|
+
- - "<"
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '2'
|
|
95
115
|
- !ruby/object:Gem::Dependency
|
|
96
116
|
name: uuidtools
|
|
97
117
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -119,11 +139,12 @@ executables: []
|
|
|
119
139
|
extensions: []
|
|
120
140
|
extra_rdoc_files: []
|
|
121
141
|
files:
|
|
142
|
+
- ".github/workflows/gem-push.yml"
|
|
143
|
+
- ".github/workflows/ruby.yml"
|
|
122
144
|
- ".gitignore"
|
|
123
145
|
- ".overcommit.yml"
|
|
124
146
|
- ".rspec"
|
|
125
147
|
- ".rubocop.yml"
|
|
126
|
-
- ".travis.yml"
|
|
127
148
|
- Gemfile
|
|
128
149
|
- Gemfile.lock
|
|
129
150
|
- LICENSE.txt
|
|
@@ -134,6 +155,7 @@ files:
|
|
|
134
155
|
- lib/uuidable.rb
|
|
135
156
|
- lib/uuidable/active_record.rb
|
|
136
157
|
- lib/uuidable/migration.rb
|
|
158
|
+
- lib/uuidable/v1_migration_helpers.rb
|
|
137
159
|
- lib/uuidable/version.rb
|
|
138
160
|
- uuidable.gemspec
|
|
139
161
|
homepage: https://github.com/flant/uuidable
|
|
@@ -148,14 +170,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
148
170
|
requirements:
|
|
149
171
|
- - ">="
|
|
150
172
|
- !ruby/object:Gem::Version
|
|
151
|
-
version: '
|
|
173
|
+
version: '2.7'
|
|
152
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
175
|
requirements:
|
|
154
176
|
- - ">="
|
|
155
177
|
- !ruby/object:Gem::Version
|
|
156
178
|
version: '0'
|
|
157
179
|
requirements: []
|
|
158
|
-
rubygems_version: 3.
|
|
180
|
+
rubygems_version: 3.5.3
|
|
159
181
|
signing_key:
|
|
160
182
|
specification_version: 4
|
|
161
183
|
summary: Helps using uuid everywhere in routes instead of id for ActiveRecord models.
|
data/.travis.yml
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
rvm:
|
|
3
|
-
- 2.5.1
|
|
4
|
-
before_install: gem install bundler -v 1.17.3
|
|
5
|
-
script:
|
|
6
|
-
- bundle exec rubocop
|
|
7
|
-
- bundle exec rspec
|
|
8
|
-
deploy:
|
|
9
|
-
provider: rubygems
|
|
10
|
-
api_key:
|
|
11
|
-
secure: UrlqP2DVITJ7IfNWyJAL1981jzQlrRaBoOINDvaea1fSf54U0Bf4zvhiad/5ZMml8dv07sLnp4+gDyZW2jnxae+44A4BxxOYD8UGmEztSjFfQrR6Mbe7vapTatJ4r86c5kv/ea/seUQyy4JgR7cy6MlsFj6HJIw01IiIz3XDMF0hL0C2PXwtCnWgamgnDE6Eqrj/DJ2qhJf/8ELl53N/4fPfnFZKNXzUHhqJqNFgXmoQ092dhkkjmwSZqg0KyANLC1zMW0fqBGpX29/b2QCw0AQDWDlRstA6y2MaVnCGmAE37xZBbO7w03g1Neyjovoz2SklR3z16zmFMx/b6MGDTmnFtMFD6rNn0Paac5zO8U9UmrL4kCUicF9muekneh26Ba9IBIUc/BjujK+yzRHVX3ycdhKz263P1m5PrmJk4VO6OZxSN7rjHPHoz5dy864h1kfhQUQ7o/RxpN5N5i9/fUHH88dYq8mELRQtZGJl3DqJrv6S2NN67/3VLsbPD2LoO01YMKhJmu6MKQzcjGYaA/wjdPWHVsoORvWEY0oWEMrI8qIOCDQH9D1JPyhBUF35jgKI4AcgLNkboByKXdyZD+qklsy8pCl4BtQHtpowZ5/UOp1wi9K5RkU9AwD4RqNz5czliTyjOn5kICdgrdBk6LmU280sdynSlyxOK6AA1g4=
|
|
12
|
-
gem: uuidable
|
|
13
|
-
on:
|
|
14
|
-
tags: true
|
|
15
|
-
repo: flant/uuidable
|