ulid-rails 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -13
- data/bin/run_tests +23 -0
- data/bin/wait-for-it.sh +178 -0
- data/docker-compose.yml +44 -0
- data/gemfiles/5.2.gemfile +3 -1
- data/gemfiles/6.0.gemfile +3 -1
- data/lib/ulid/rails/formatter.rb +2 -1
- data/lib/ulid/rails/type.rb +14 -10
- data/lib/ulid/rails/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c37eb5b4b0722d0858a1c08682e89a8285350ab1d151bc90bbb6aaf1c6cff5d
|
4
|
+
data.tar.gz: 9bd6b0bff5eb157b998f04b26b7eb75e3b53d90c4820e2dcbc9ede7c8a1246b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab1f5cf9796884e8845a67bf13a3e6b69f2e3d48c2b21c23ff5d0f1836fdbd6da1850dcb9292be74cad38476f4df3f4cd46306d66d2bdc203c7da50c24861ce2
|
7
|
+
data.tar.gz: f8300abe5bd288884ae1d8a24a12f08e3b6c248c144cc68f564fe567ff7c7fa213ce9a3110a1b5125a9ec9a38220afa139938cb12ce0b779532b613c6390e9a4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
### Migrations
|
24
24
|
|
25
|
-
|
25
|
+
Specify `id: false` to `create_table` and add `id` column as 16-byte binary type.
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
def change
|
@@ -33,16 +33,6 @@ If you use MySQL, specify `id: false` to `create_table` and add `id` column as 1
|
|
33
33
|
end
|
34
34
|
```
|
35
35
|
|
36
|
-
If you use PostgreSQL, just specify `id: :uuid` to `create_table`
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
def change
|
40
|
-
create_table :users, id: :uuid do |t|
|
41
|
-
# ...
|
42
|
-
end
|
43
|
-
end
|
44
|
-
```
|
45
|
-
|
46
36
|
|
47
37
|
### Model Changes
|
48
38
|
|
@@ -103,8 +93,6 @@ class Model < ApplicationRecord
|
|
103
93
|
end
|
104
94
|
```
|
105
95
|
|
106
|
-
## FAQ
|
107
|
-
|
108
96
|
### Foreign Keys
|
109
97
|
|
110
98
|
You need to specicfy `type` option
|
@@ -116,6 +104,16 @@ You need to specicfy `type` option
|
|
116
104
|
end
|
117
105
|
```
|
118
106
|
|
107
|
+
## Development
|
108
|
+
|
109
|
+
### Run tests
|
110
|
+
|
111
|
+
Just run the below command to test with all supported DB engines.
|
112
|
+
|
113
|
+
```
|
114
|
+
$ docker-compose run test
|
115
|
+
```
|
116
|
+
|
119
117
|
## License
|
120
118
|
|
121
119
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/run_tests
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
test_with_db() {
|
4
|
+
echo "Testing with $1"
|
5
|
+
DB=$1 bundle exec rake
|
6
|
+
}
|
7
|
+
|
8
|
+
test_with_db "sqlite3"
|
9
|
+
|
10
|
+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
11
|
+
|
12
|
+
# Most features should work with MySQL 5.6 but I couldn't properly set it up in test.
|
13
|
+
# $DIR/wait-for-it.sh mysql56:3306
|
14
|
+
# test_with_db "mysql56"
|
15
|
+
|
16
|
+
$DIR/wait-for-it.sh mysql57:3306
|
17
|
+
test_with_db "mysql57"
|
18
|
+
|
19
|
+
$DIR/wait-for-it.sh mysql80:3306
|
20
|
+
test_with_db "mysql80"
|
21
|
+
|
22
|
+
$DIR/wait-for-it.sh pg12:5432
|
23
|
+
test_with_db "pg12"
|
data/bin/wait-for-it.sh
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# Use this script to test if a given TCP host/port are available
|
3
|
+
|
4
|
+
WAITFORIT_cmdname=${0##*/}
|
5
|
+
|
6
|
+
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
7
|
+
|
8
|
+
usage()
|
9
|
+
{
|
10
|
+
cat << USAGE >&2
|
11
|
+
Usage:
|
12
|
+
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
13
|
+
-h HOST | --host=HOST Host or IP under test
|
14
|
+
-p PORT | --port=PORT TCP port under test
|
15
|
+
Alternatively, you specify the host and port as host:port
|
16
|
+
-s | --strict Only execute subcommand if the test succeeds
|
17
|
+
-q | --quiet Don't output any status messages
|
18
|
+
-t TIMEOUT | --timeout=TIMEOUT
|
19
|
+
Timeout in seconds, zero for no timeout
|
20
|
+
-- COMMAND ARGS Execute command with args after the test finishes
|
21
|
+
USAGE
|
22
|
+
exit 1
|
23
|
+
}
|
24
|
+
|
25
|
+
wait_for()
|
26
|
+
{
|
27
|
+
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
28
|
+
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
29
|
+
else
|
30
|
+
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
|
31
|
+
fi
|
32
|
+
WAITFORIT_start_ts=$(date +%s)
|
33
|
+
while :
|
34
|
+
do
|
35
|
+
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
|
36
|
+
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
37
|
+
WAITFORIT_result=$?
|
38
|
+
else
|
39
|
+
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
40
|
+
WAITFORIT_result=$?
|
41
|
+
fi
|
42
|
+
if [[ $WAITFORIT_result -eq 0 ]]; then
|
43
|
+
WAITFORIT_end_ts=$(date +%s)
|
44
|
+
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
45
|
+
break
|
46
|
+
fi
|
47
|
+
sleep 1
|
48
|
+
done
|
49
|
+
return $WAITFORIT_result
|
50
|
+
}
|
51
|
+
|
52
|
+
wait_for_wrapper()
|
53
|
+
{
|
54
|
+
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
55
|
+
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
56
|
+
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
57
|
+
else
|
58
|
+
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
59
|
+
fi
|
60
|
+
WAITFORIT_PID=$!
|
61
|
+
trap "kill -INT -$WAITFORIT_PID" INT
|
62
|
+
wait $WAITFORIT_PID
|
63
|
+
WAITFORIT_RESULT=$?
|
64
|
+
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
65
|
+
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
66
|
+
fi
|
67
|
+
return $WAITFORIT_RESULT
|
68
|
+
}
|
69
|
+
|
70
|
+
# process arguments
|
71
|
+
while [[ $# -gt 0 ]]
|
72
|
+
do
|
73
|
+
case "$1" in
|
74
|
+
*:* )
|
75
|
+
WAITFORIT_hostport=(${1//:/ })
|
76
|
+
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
77
|
+
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
78
|
+
shift 1
|
79
|
+
;;
|
80
|
+
--child)
|
81
|
+
WAITFORIT_CHILD=1
|
82
|
+
shift 1
|
83
|
+
;;
|
84
|
+
-q | --quiet)
|
85
|
+
WAITFORIT_QUIET=1
|
86
|
+
shift 1
|
87
|
+
;;
|
88
|
+
-s | --strict)
|
89
|
+
WAITFORIT_STRICT=1
|
90
|
+
shift 1
|
91
|
+
;;
|
92
|
+
-h)
|
93
|
+
WAITFORIT_HOST="$2"
|
94
|
+
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
95
|
+
shift 2
|
96
|
+
;;
|
97
|
+
--host=*)
|
98
|
+
WAITFORIT_HOST="${1#*=}"
|
99
|
+
shift 1
|
100
|
+
;;
|
101
|
+
-p)
|
102
|
+
WAITFORIT_PORT="$2"
|
103
|
+
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
104
|
+
shift 2
|
105
|
+
;;
|
106
|
+
--port=*)
|
107
|
+
WAITFORIT_PORT="${1#*=}"
|
108
|
+
shift 1
|
109
|
+
;;
|
110
|
+
-t)
|
111
|
+
WAITFORIT_TIMEOUT="$2"
|
112
|
+
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
113
|
+
shift 2
|
114
|
+
;;
|
115
|
+
--timeout=*)
|
116
|
+
WAITFORIT_TIMEOUT="${1#*=}"
|
117
|
+
shift 1
|
118
|
+
;;
|
119
|
+
--)
|
120
|
+
shift
|
121
|
+
WAITFORIT_CLI=("$@")
|
122
|
+
break
|
123
|
+
;;
|
124
|
+
--help)
|
125
|
+
usage
|
126
|
+
;;
|
127
|
+
*)
|
128
|
+
echoerr "Unknown argument: $1"
|
129
|
+
usage
|
130
|
+
;;
|
131
|
+
esac
|
132
|
+
done
|
133
|
+
|
134
|
+
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
135
|
+
echoerr "Error: you need to provide a host and port to test."
|
136
|
+
usage
|
137
|
+
fi
|
138
|
+
|
139
|
+
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
140
|
+
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
141
|
+
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
142
|
+
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
143
|
+
|
144
|
+
# check to see if timeout is from busybox?
|
145
|
+
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
146
|
+
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
147
|
+
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
148
|
+
WAITFORIT_ISBUSY=1
|
149
|
+
WAITFORIT_BUSYTIMEFLAG="-t"
|
150
|
+
|
151
|
+
else
|
152
|
+
WAITFORIT_ISBUSY=0
|
153
|
+
WAITFORIT_BUSYTIMEFLAG=""
|
154
|
+
fi
|
155
|
+
|
156
|
+
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
157
|
+
wait_for
|
158
|
+
WAITFORIT_RESULT=$?
|
159
|
+
exit $WAITFORIT_RESULT
|
160
|
+
else
|
161
|
+
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
162
|
+
wait_for_wrapper
|
163
|
+
WAITFORIT_RESULT=$?
|
164
|
+
else
|
165
|
+
wait_for
|
166
|
+
WAITFORIT_RESULT=$?
|
167
|
+
fi
|
168
|
+
fi
|
169
|
+
|
170
|
+
if [[ $WAITFORIT_CLI != "" ]]; then
|
171
|
+
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
172
|
+
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
173
|
+
exit $WAITFORIT_RESULT
|
174
|
+
fi
|
175
|
+
exec "${WAITFORIT_CLI[@]}"
|
176
|
+
else
|
177
|
+
exit $WAITFORIT_RESULT
|
178
|
+
fi
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
version: '3.6'
|
2
|
+
services:
|
3
|
+
test:
|
4
|
+
image: ruby:2.6
|
5
|
+
command: sh -c "rm Gemfile.lock && bundle install && bin/run_tests"
|
6
|
+
depends_on:
|
7
|
+
- mysql56
|
8
|
+
- mysql57
|
9
|
+
- mysql80
|
10
|
+
- pg12
|
11
|
+
working_dir: /app
|
12
|
+
volumes:
|
13
|
+
- bundle:/usr/local/bundle
|
14
|
+
- .:/app
|
15
|
+
|
16
|
+
mysql56:
|
17
|
+
image: mysql:5.6
|
18
|
+
environment:
|
19
|
+
MYSQL_ROOT_PASSWORD: password
|
20
|
+
command: --innodb-large-prefix --innodb-file-format=barracuda
|
21
|
+
healthcheck:
|
22
|
+
test: mysql --password=password -e "show databases;"
|
23
|
+
mysql57:
|
24
|
+
image: mysql:5.7
|
25
|
+
environment:
|
26
|
+
MYSQL_ROOT_PASSWORD: password
|
27
|
+
healthcheck:
|
28
|
+
test: mysql --password=password -e "show databases;"
|
29
|
+
mysql80:
|
30
|
+
image: mysql:8.0
|
31
|
+
command: --default-authentication-plugin=mysql_native_password
|
32
|
+
environment:
|
33
|
+
MYSQL_ROOT_PASSWORD: password
|
34
|
+
healthcheck:
|
35
|
+
test: mysql --password=password -e "show databases;"
|
36
|
+
pg12:
|
37
|
+
image: postgres:12
|
38
|
+
environment:
|
39
|
+
PGDATA: /data
|
40
|
+
POSTGRES_DB: db
|
41
|
+
healthcheck:
|
42
|
+
test: echo "\\l" | psql -U postgre
|
43
|
+
volumes:
|
44
|
+
bundle:
|
data/gemfiles/5.2.gemfile
CHANGED
data/gemfiles/6.0.gemfile
CHANGED
data/lib/ulid/rails/formatter.rb
CHANGED
data/lib/ulid/rails/type.rb
CHANGED
@@ -14,20 +14,24 @@ module ULID
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def cast(value)
|
17
|
-
if value.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
super
|
25
|
-
end
|
17
|
+
return nil if value.nil?
|
18
|
+
|
19
|
+
value = value.to_s if value.is_a?(Data)
|
20
|
+
value = value.unpack("H*")[0] if value.encoding == Encoding::ASCII_8BIT
|
21
|
+
value = value[2..] if value.start_with?("\\x")
|
22
|
+
|
23
|
+
value.length == 32 ? @formatter.format(value) : super
|
26
24
|
end
|
27
25
|
|
28
26
|
def serialize(value)
|
29
27
|
return if value.nil?
|
30
|
-
|
28
|
+
|
29
|
+
case ActiveRecord::Base.connection_config[:adapter]
|
30
|
+
when "mysql2", "sqlite3"
|
31
|
+
Data.new(@formatter.unformat(value))
|
32
|
+
when "postgresql"
|
33
|
+
Data.new([@formatter.unformat(value)].pack("H*"))
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
data/lib/ulid/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ulid-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazunori Kajihiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ulid
|
@@ -137,7 +137,10 @@ files:
|
|
137
137
|
- README.md
|
138
138
|
- Rakefile
|
139
139
|
- bin/console
|
140
|
+
- bin/run_tests
|
140
141
|
- bin/setup
|
142
|
+
- bin/wait-for-it.sh
|
143
|
+
- docker-compose.yml
|
141
144
|
- gemfiles/5.2.gemfile
|
142
145
|
- gemfiles/6.0.gemfile
|
143
146
|
- lib/ulid/rails.rb
|