activerecord-dsql-adapter 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/active_record/connection_adapters/dsql_adapter.rb +35 -7
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b576c75df39b5f6614a13458d0470b4381e4addec43940b53ae76666175c0ce
|
4
|
+
data.tar.gz: 3df4dc2c5b42817bc69fa7c0b2c1cc19dd0c9e063dbff9d88888472e6a759890
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 275a8d7abcbc96fee0c9cba68b34e258b0c804cb5794dc52c339d15ed7357059984730228aa9c547202c7a7f9cb7feb5b6c838a3976fac242e25a71dbae453f5
|
7
|
+
data.tar.gz: 92f3755515e1aa655f043cc76560ae4d82e85f71bd88a772fc79cec1ca5de1e9a7d6aca911a2f380b7972c1254fd541a24ef138184dbd54403a130b889dfc996
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -7,6 +7,14 @@ require "active_record/connection_adapters/postgresql_adapter"
|
|
7
7
|
|
8
8
|
module ActiveRecord
|
9
9
|
module ConnectionAdapters
|
10
|
+
module DSQL
|
11
|
+
class Railtie < ::Rails::Railtie
|
12
|
+
rake_tasks do
|
13
|
+
ActiveRecord::DatabaseTasks.register_task("dsql", "ActiveRecord::Tasks::DSQLDatabaseTasks")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
class DSQLAdapter < PostgreSQLAdapter
|
11
19
|
ADAPTER_NAME = "DSQL"
|
12
20
|
|
@@ -47,12 +55,15 @@ module ActiveRecord
|
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
|
-
# DSQL doesn't support serial or bigserial
|
51
|
-
|
58
|
+
# DSQL doesn't support serial or bigserial, nor sequences, but seems to
|
59
|
+
# endorse using uuid with default random function uuids for primary keys
|
60
|
+
#
|
61
|
+
# https://docs.aws.amazon.com/aurora-dsql/latest/userguide/getting-started.html
|
62
|
+
#
|
52
63
|
def self.native_database_types # :nodoc:
|
53
64
|
@native_database_types ||= begin
|
54
65
|
types = NATIVE_DATABASE_TYPES.dup
|
55
|
-
types[:primary_key] = "
|
66
|
+
types[:primary_key] = "uuid primary key unique default gen_random_uuid()"
|
56
67
|
types[:datetime] = types[datetime_type]
|
57
68
|
types
|
58
69
|
end
|
@@ -116,10 +127,27 @@ module ActiveRecord
|
|
116
127
|
false
|
117
128
|
end
|
118
129
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
130
|
+
# DSQL creates a primary key index which INCLUDES all columns in the
|
131
|
+
# table. We use indnkeyatts to only take notice of key (not INCLUDE-ed)
|
132
|
+
# columns for the primary key.
|
133
|
+
#
|
134
|
+
# https://www.postgresql.org/docs/current/catalog-pg-index.html
|
135
|
+
#
|
136
|
+
def primary_keys(table_name) # :nodoc:
|
137
|
+
query_values(<<~SQL, "SCHEMA")
|
138
|
+
SELECT a.attname
|
139
|
+
FROM (
|
140
|
+
SELECT indrelid, indnkeyatts, indkey, generate_subscripts(indkey, 1) idx
|
141
|
+
FROM pg_index
|
142
|
+
WHERE indrelid = #{quote(quote_table_name(table_name))}::regclass
|
143
|
+
AND indisprimary
|
144
|
+
) i
|
145
|
+
JOIN pg_attribute a
|
146
|
+
ON a.attrelid = i.indrelid
|
147
|
+
AND a.attnum = i.indkey[i.idx]
|
148
|
+
WHERE i.idx < i.indnkeyatts
|
149
|
+
ORDER BY i.idx
|
150
|
+
SQL
|
123
151
|
end
|
124
152
|
end
|
125
153
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|