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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 521857d7d6e64cb32e944b19916fee20987cede5125fbdee5ee186107551c538
4
- data.tar.gz: d991051dde9b6541635ac6c9663b3086288e9acb657ffce36a567099457e6ed5
3
+ metadata.gz: 4b576c75df39b5f6614a13458d0470b4381e4addec43940b53ae76666175c0ce
4
+ data.tar.gz: 3df4dc2c5b42817bc69fa7c0b2c1cc19dd0c9e063dbff9d88888472e6a759890
5
5
  SHA512:
6
- metadata.gz: 6f9b349d16a2a860e46e89932fd5bef016b78135542addd07395cc08ddbacb209ac98b0eff862289a42f122968b01d2a2a89b5483241fc8384a93d55fd4f569b
7
- data.tar.gz: '089e5e042d90cc75c8298e7a34f89db2c795e3e63d29c606532883268ffef2c61a69e9dd2802f18fcd7c5d2ded73d2c69c3c401163df5eb50f589116020f35a2'
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] = "bigint 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
- class Railtie < ::Rails::Railtie
120
- rake_tasks do
121
- ActiveRecord::DatabaseTasks.register_task("dsql", "ActiveRecord::Tasks::DSQLDatabaseTasks")
122
- end
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
@@ -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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Cochran
metadata.gz.sig CHANGED
Binary file