activerecord-dsql-adapter 0.1.1 → 0.1.3
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
- checksums.yaml.gz.sig +3 -4
- data/lib/active_record/connection_adapters/dsql_adapter.rb +68 -5
- data/lib/activerecord-dsql-adapter.rb +4 -3
- 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
@@ -1,4 +1,3 @@
|
|
1
|
-
FE��JtM��F���I��e-o��釽�ݺق�e�t��|�G���s�jG�A֭���%���7�eZ_�b����0�t{���iq'3�
|
2
1
|
�4�Ƒ���Ɗq��j���yi"G���}�)���<`��
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
��wf�1E�)A�N���hjFԙA|��Ê&��w�1� � ��頭}�g�7�v����'L�P�%j[�Cw1�������m��ԙ(�J��v��B։*p��乯�
|
3
|
+
�뮼S3
|
4
|
+
i��ކ�XZ
|
@@ -7,20 +7,40 @@ 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
|
|
13
21
|
class << self
|
14
22
|
def new_client(conn_params)
|
15
23
|
conn_params[:sslmode] ||= "require"
|
16
|
-
conn_params[:user] ||= "admin"
|
17
24
|
conn_params[:dbname] ||= "postgres"
|
18
|
-
|
25
|
+
conn_params[:user] ||= "admin"
|
19
26
|
conn_params[:password] ||= generate_password(conn_params)
|
20
27
|
|
21
28
|
super(conn_params)
|
22
29
|
end
|
23
30
|
|
31
|
+
def dbconsole(config, options = {})
|
32
|
+
config_hash = config.configuration_hash.dup
|
33
|
+
|
34
|
+
config_hash[:sslmode] ||= "require"
|
35
|
+
config_hash[:database] ||= "postgres"
|
36
|
+
config_hash[:username] ||= "admin"
|
37
|
+
config_hash[:password] ||= generate_password(config_hash)
|
38
|
+
|
39
|
+
config = ActiveRecord::DatabaseConfigurations::HashConfig.new(config.env_name, config.name, config_hash)
|
40
|
+
|
41
|
+
super(config, options)
|
42
|
+
end
|
43
|
+
|
24
44
|
private
|
25
45
|
|
26
46
|
def generate_password(conn_params)
|
@@ -35,12 +55,15 @@ module ActiveRecord
|
|
35
55
|
end
|
36
56
|
end
|
37
57
|
|
38
|
-
# DSQL doesn't support serial or bigserial
|
39
|
-
|
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
|
+
#
|
40
63
|
def self.native_database_types # :nodoc:
|
41
64
|
@native_database_types ||= begin
|
42
65
|
types = NATIVE_DATABASE_TYPES.dup
|
43
|
-
types[:primary_key] = "
|
66
|
+
types[:primary_key] = "uuid primary key unique default gen_random_uuid()"
|
44
67
|
types[:datetime] = types[datetime_type]
|
45
68
|
types
|
46
69
|
end
|
@@ -93,6 +116,46 @@ module ActiveRecord
|
|
93
116
|
def supports_json?
|
94
117
|
false
|
95
118
|
end
|
119
|
+
|
120
|
+
# DSQL *does* support DDL transactions, but does not support mixing DDL and
|
121
|
+
# DML, so inserting the migration version into the schema_migrations
|
122
|
+
# table fails unless we turn off the DDL transaction.
|
123
|
+
#
|
124
|
+
# PG::FeatureNotSupported: ERROR: ddl and dml are not supported in the same transaction
|
125
|
+
#
|
126
|
+
def supports_ddl_transactions?
|
127
|
+
false
|
128
|
+
end
|
129
|
+
|
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
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
module Tasks
|
156
|
+
class DSQLDatabaseTasks < PostgreSQLDatabaseTasks
|
96
157
|
end
|
97
158
|
end
|
98
159
|
end
|
160
|
+
|
161
|
+
ActiveSupport.run_load_hooks(:active_record_dsql_adapter, ActiveRecord::ConnectionAdapters::DSQLAdapter)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
4
|
-
require "active_record/connection_adapters"
|
3
|
+
require "active_support/lazy_load_hooks"
|
5
4
|
|
6
|
-
|
5
|
+
ActiveSupport.on_load(:active_record) do
|
6
|
+
ActiveRecord::ConnectionAdapters.register("dsql", "ActiveRecord::ConnectionAdapters::DSQLAdapter", "active_record/connection_adapters/dsql_adapter")
|
7
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|