iry 0.6.0 → 0.7.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/VERSION +1 -1
- data/db/schema.pgsql +17 -4
- data/lib/iry/constraint/check.rb +7 -1
- data/lib/iry/constraint/foreign_key.rb +11 -1
- data/lib/iry/constraint/unique.rb +21 -1
- data/lib/iry.rb +1 -0
- data/package-lock.json +2 -2
- data/package.json +1 -1
- data/rbi/iry.rbi +2 -0
- data/sig/iry.rbs +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ba546c69426b3b1d4c530d79ed5cfed56b5f3ea5dfe629a37b5061a90213b33
|
4
|
+
data.tar.gz: 65aa3e75c36b7fae90d81e20126c0bc134ff16ee7ddc009349754cd17cc14c29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef79029f7a9f7a51dbb20964ad407ea146417a10de1c7c4d9149a9d83acece6e9db2abe2f3ca6779c684e31554bea9e22e6496579b5cc16eaf53ec787d6b4d17
|
7
|
+
data.tar.gz: a7daca1aca5c175224affa28884e83c19fcdfd4b01369c8b28f6cea2cfd5cea476fca77d433eb84fa53518a3812c03bc12448617bbd2a104b49dcaec1757cf44
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/db/schema.pgsql
CHANGED
@@ -3,14 +3,27 @@ create extension if not exists "btree_gist";
|
|
3
3
|
|
4
4
|
create table if not exists users (
|
5
5
|
id uuid primary key default gen_random_uuid(),
|
6
|
-
unique_text text
|
6
|
+
unique_text text not null default gen_random_uuid()::text,
|
7
7
|
exclude_text text not null default gen_random_uuid()::text,
|
8
|
-
user_id uuid
|
9
|
-
untracked_text text
|
8
|
+
user_id uuid,
|
9
|
+
untracked_text text not null default gen_random_uuid()::text,
|
10
10
|
free_text text not null default '',
|
11
|
-
friend_user_id uuid
|
11
|
+
friend_user_id uuid,
|
12
12
|
created_at timestamp(6) not null,
|
13
13
|
updated_at timestamp(6) not null,
|
14
14
|
-- acts similar to unique constraint
|
15
15
|
exclude using gist (exclude_text with =)
|
16
16
|
);
|
17
|
+
|
18
|
+
create unique index if not exists
|
19
|
+
index_users_on_unique_text on users(unique_text);
|
20
|
+
create unique index if not exists
|
21
|
+
index_users_on_untracked_text on users(untracked_text);
|
22
|
+
alter table users
|
23
|
+
add constraint chk_rails_15df0d7772 check (unique_text != 'invalid');
|
24
|
+
alter table users
|
25
|
+
add constraint fk_rails_6d0b8b3c2f
|
26
|
+
foreign key (user_id) references users(id);
|
27
|
+
alter table users
|
28
|
+
add constraint fk_rails_d3f200176b
|
29
|
+
foreign key (friend_user_id) references users(id);
|
data/lib/iry/constraint/check.rb
CHANGED
@@ -6,7 +6,13 @@ module Iry
|
|
6
6
|
# @param table_name [String]
|
7
7
|
# @return [String]
|
8
8
|
def self.infer_name(key, table_name)
|
9
|
-
|
9
|
+
# PostgreSQL convention:
|
10
|
+
# "#{table_name}_#{key}_check"
|
11
|
+
# Rails convention
|
12
|
+
id = "#{table_name}_#{key}_chk"
|
13
|
+
hashed_id = OpenSSL::Digest::SHA256.hexdigest(id)[0..9]
|
14
|
+
|
15
|
+
"chk_rails_#{hashed_id}"
|
10
16
|
end
|
11
17
|
|
12
18
|
# @return [Symbol]
|
@@ -6,7 +6,17 @@ module Iry
|
|
6
6
|
# @param table_name [String]
|
7
7
|
# @return [String]
|
8
8
|
def self.infer_name(keys, table_name)
|
9
|
-
|
9
|
+
if keys.size > 1
|
10
|
+
# PostgreSQL convention:
|
11
|
+
return "#{table_name}_#{keys.join("_")}_fkey"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Rails convention:
|
15
|
+
column = keys.first
|
16
|
+
id = "#{table_name}_#{column}_fk"
|
17
|
+
hashed_id = OpenSSL::Digest::SHA256.hexdigest(id)[0..9]
|
18
|
+
|
19
|
+
"fk_rails_#{hashed_id}"
|
10
20
|
end
|
11
21
|
|
12
22
|
# @return [<Symbol>]
|
@@ -1,12 +1,32 @@
|
|
1
1
|
module Iry
|
2
2
|
module Constraint
|
3
3
|
class Unique
|
4
|
+
MAX_INFER_NAME_BYTE_SIZE = 62
|
5
|
+
|
4
6
|
# Infers the unique constraint name based on keys and table name
|
5
7
|
# @param keys [<Symbol>]
|
6
8
|
# @param table_name [String]
|
7
9
|
# @return [String]
|
8
10
|
def self.infer_name(keys, table_name)
|
9
|
-
|
11
|
+
# PostgreSQL convention:
|
12
|
+
# "#{table_name}_#{keys.join("_")}_key"
|
13
|
+
|
14
|
+
# Rails convention:
|
15
|
+
# index_trip_hikers_on_trip_id_and_hiker_card_id
|
16
|
+
# index_TABLENAME_on_COLUMN1_and_COLUMN2
|
17
|
+
name = "index_#{table_name}_on_#{keys.join("_and_")}"
|
18
|
+
if name.bytesize <= MAX_INFER_NAME_BYTE_SIZE
|
19
|
+
return name
|
20
|
+
end
|
21
|
+
|
22
|
+
digest = OpenSSL::Digest::SHA256.hexdigest(name)[0..9]
|
23
|
+
hashed_id = "_#{digest}"
|
24
|
+
name = "idx_on_#{keys.join("_")}"
|
25
|
+
|
26
|
+
short_limit = max_index_name_size - hashed_identifier.bytesize
|
27
|
+
short_name = name.mb_chars.limit(short_limit).to_s
|
28
|
+
|
29
|
+
"#{short_name}#{hashed_identifier}"
|
10
30
|
end
|
11
31
|
|
12
32
|
# @return [<Symbol>]
|
data/lib/iry.rb
CHANGED
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "iry",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.7.0",
|
4
4
|
"lockfileVersion": 3,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "iry",
|
9
|
-
"version": "0.
|
9
|
+
"version": "0.7.0",
|
10
10
|
"license": "MIT",
|
11
11
|
"devDependencies": {
|
12
12
|
"conventional-changelog-cli": ">= 3.0.0",
|
data/package.json
CHANGED
data/rbi/iry.rbi
CHANGED
data/sig/iry.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Belladonna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|