activerecord-dsql-adapter 0.1.2 → 0.1.4
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 +0 -0
- data/lib/active_record/connection_adapters/dsql/railtie.rb +13 -0
- data/lib/active_record/connection_adapters/dsql/schema_dumper.rb +15 -0
- data/lib/active_record/connection_adapters/dsql_adapter.rb +38 -11
- data/lib/active_record/tasks/dsql_database_tasks.rb +30 -0
- data/lib/activerecord-dsql-adapter.rb +23 -1
- data.tar.gz.sig +0 -0
- metadata +4 -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: a2a6400458dc398fea1b2033dd3fe8c8e488808c71f459dfe693cc905b8ceebc
|
4
|
+
data.tar.gz: 50eceb300ff89ca6f93aff37165794a32760a3d242f84be60779d0a8a00d3302
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abcb7ee0f219fbf922ee539b03becb54bdcdb600a0685bde8415c0886319296c90ea8c15d5ee0ccd8428f162c1d1b2bb597d42e4c1e751ab14f8bfd8e91d8987
|
7
|
+
data.tar.gz: 664df396b1edb20293c1a22bec8647a321f0f4224e8e6e352ed78b51568774fee07dcee443b48691d6ce25cf4eef6f694066792db34b8e50b0867ab9cd7c2d91
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module DSQL
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
rake_tasks do
|
8
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task("dsql", "ActiveRecord::Tasks::DSQLDatabaseTasks")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -47,12 +47,15 @@ module ActiveRecord
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
# DSQL doesn't support serial or bigserial
|
51
|
-
|
50
|
+
# DSQL doesn't support serial or bigserial, nor sequences, but seems to
|
51
|
+
# endorse using uuid with default random function uuids for primary keys
|
52
|
+
#
|
53
|
+
# https://docs.aws.amazon.com/aurora-dsql/latest/userguide/getting-started.html
|
54
|
+
#
|
52
55
|
def self.native_database_types # :nodoc:
|
53
56
|
@native_database_types ||= begin
|
54
57
|
types = NATIVE_DATABASE_TYPES.dup
|
55
|
-
types[:primary_key] = "
|
58
|
+
types[:primary_key] = "uuid primary key unique default gen_random_uuid()"
|
56
59
|
types[:datetime] = types[datetime_type]
|
57
60
|
types
|
58
61
|
end
|
@@ -116,16 +119,40 @@ module ActiveRecord
|
|
116
119
|
false
|
117
120
|
end
|
118
121
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
122
|
+
# Ignore DSQL sys schema.
|
123
|
+
#
|
124
|
+
# https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-systems-tables.html
|
125
|
+
#
|
126
|
+
def schema_names
|
127
|
+
super - ["sys"]
|
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
|
123
151
|
end
|
124
|
-
end
|
125
|
-
end
|
126
152
|
|
127
|
-
|
128
|
-
|
153
|
+
def create_schema_dumper(options) # :nodoc:
|
154
|
+
DSQL::SchemaDumper.create(self, options)
|
155
|
+
end
|
129
156
|
end
|
130
157
|
end
|
131
158
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record"
|
4
|
+
require "active_record/tasks/postgresql_database_tasks"
|
5
|
+
|
6
|
+
module ActiveRecord
|
7
|
+
module Tasks
|
8
|
+
class DSQLDatabaseTasks < PostgreSQLDatabaseTasks
|
9
|
+
def initialize(config)
|
10
|
+
config_hash = config.configuration_hash.dup
|
11
|
+
|
12
|
+
config_hash[:sslmode] ||= "require"
|
13
|
+
config_hash[:database] ||= "postgres"
|
14
|
+
config_hash[:username] ||= "admin"
|
15
|
+
|
16
|
+
config = ActiveRecord::DatabaseConfigurations::HashConfig.new(config.env_name, config.name, config_hash)
|
17
|
+
|
18
|
+
super(config)
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(...)
|
22
|
+
fail "DSQL does not support CREATE DATABASE"
|
23
|
+
end
|
24
|
+
|
25
|
+
def drop(...)
|
26
|
+
fail "DSQL does not support DROP DATABASE"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,7 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "active_record"
|
4
4
|
|
5
5
|
ActiveSupport.on_load(:active_record) do
|
6
6
|
ActiveRecord::ConnectionAdapters.register("dsql", "ActiveRecord::ConnectionAdapters::DSQLAdapter", "active_record/connection_adapters/dsql_adapter")
|
7
7
|
end
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
module ConnectionAdapters
|
11
|
+
module DSQL
|
12
|
+
extend ActiveSupport::Autoload
|
13
|
+
|
14
|
+
autoload :SchemaDumper
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ActiveRecord
|
20
|
+
module Tasks
|
21
|
+
extend ActiveSupport::Autoload
|
22
|
+
|
23
|
+
autoload :DSQLDatabaseTasks, "active_record/tasks/dsql_database_tasks"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? Rails
|
28
|
+
require "active_record/connection_adapters/dsql/railtie"
|
29
|
+
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.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Cochran
|
@@ -80,7 +80,10 @@ extensions: []
|
|
80
80
|
extra_rdoc_files: []
|
81
81
|
files:
|
82
82
|
- README.md
|
83
|
+
- lib/active_record/connection_adapters/dsql/railtie.rb
|
84
|
+
- lib/active_record/connection_adapters/dsql/schema_dumper.rb
|
83
85
|
- lib/active_record/connection_adapters/dsql_adapter.rb
|
86
|
+
- lib/active_record/tasks/dsql_database_tasks.rb
|
84
87
|
- lib/activerecord-dsql-adapter.rb
|
85
88
|
homepage: https://github.com/sj26/activerecord-dsql-adapter
|
86
89
|
licenses: []
|
metadata.gz.sig
CHANGED
Binary file
|