activerecord-dsql-adapter 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ad2818119d3d7093a3ddd37e8931c729ce600b50ed12e5cf6596f0ffa81672e
4
- data.tar.gz: bc006c7e000efa466b91e64a4aafae12eb4c9fa2094d3d476c6f2b729e0feee9
3
+ metadata.gz: 4b576c75df39b5f6614a13458d0470b4381e4addec43940b53ae76666175c0ce
4
+ data.tar.gz: 3df4dc2c5b42817bc69fa7c0b2c1cc19dd0c9e063dbff9d88888472e6a759890
5
5
  SHA512:
6
- metadata.gz: aabca4cd463236250820fb6676c78b16aa2df30f0dd6fab4ee36bfbf003db58212ad44140177e1a7d0c3ad223a03131de94d754f559dfb6d1801a4dc1ed88d0a
7
- data.tar.gz: 7ee6a43d1f0aa09cfb84006bc10b83277f8e6f64496f9af2a546940e7db57b39b6c39862dd941b5d70b5405700f3f801194a72caef23c233d4f17a65477f3859
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
- ���7����Xݑ(u��N
4
- (��K \-Ժ�8K��
5
- �`΂J���J���\������Y
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] = "bigint 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 "active_record"
4
- require "active_record/connection_adapters"
3
+ require "active_support/lazy_load_hooks"
5
4
 
6
- ActiveRecord::ConnectionAdapters.register("dsql", "ActiveRecord::ConnectionAdapters::DSQLAdapter", "active_record/connection_adapters/dsql_adapter")
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-dsql-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Cochran
metadata.gz.sig CHANGED
Binary file