activerecord-dsql-adapter 0.1.2 → 0.1.4

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: a2a6400458dc398fea1b2033dd3fe8c8e488808c71f459dfe693cc905b8ceebc
4
+ data.tar.gz: 50eceb300ff89ca6f93aff37165794a32760a3d242f84be60779d0a8a00d3302
5
5
  SHA512:
6
- metadata.gz: 6f9b349d16a2a860e46e89932fd5bef016b78135542addd07395cc08ddbacb209ac98b0eff862289a42f122968b01d2a2a89b5483241fc8384a93d55fd4f569b
7
- data.tar.gz: '089e5e042d90cc75c8298e7a34f89db2c795e3e63d29c606532883268ffef2c61a69e9dd2802f18fcd7c5d2ded73d2c69c3c401163df5eb50f589116020f35a2'
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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module DSQL
6
+ class SchemaDumper < PostgreSQL::SchemaDumper # :nodoc:
7
+ private
8
+
9
+ def extensions(stream)
10
+ # Ignore extensions
11
+ end
12
+ end
13
+ end
14
+ end
15
+ 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] = "bigint 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
- class Railtie < ::Rails::Railtie
120
- rake_tasks do
121
- ActiveRecord::DatabaseTasks.register_task("dsql", "ActiveRecord::Tasks::DSQLDatabaseTasks")
122
- end
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
- module Tasks
128
- class DSQLDatabaseTasks < PostgreSQLDatabaseTasks
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 "active_support/lazy_load_hooks"
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.2
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