activerecord-aws_data_service_mysql-adapter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/activerecord-aws_data_service_mysql-adapter.gemspec +41 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb +120 -0
- data/lib/active_record/connection_adapters/aws_data_service_mysql_adapter.rb +73 -0
- data/test.rb +68 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea845acf007f68d7ab23d36b4c8047929b4a1595f40fc4987475cf7abe8eff52
|
4
|
+
data.tar.gz: 8d2c21499204eee1d1df81b629580d3cd72b6572e4440e920cd28ebc651c4739
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: acbf481ab559e9dd3f796e34fe91f654279ab906d06d1b124289fb5e3fe12b6f58315ef14448da896c6f3971f6f81b97fbb87f5c3ef00bc6c57f1ac2aec619f6
|
7
|
+
data.tar.gz: 9e09360e0d50c1edd8b0257ca56d4fc7bb2d91793a5a715874053eb83d2bc8b22ebe73f126e2f3e87c521b0b977a475bd3c61ecbfb11a220ba4bad8bd024cf56
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in activerecord-aws_data_service_mysql-adapter.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'pry-byebug'
|
9
|
+
|
10
|
+
# To find the original behavior
|
11
|
+
gem 'mysql2'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
activerecord-aws_data_service_mysql-adapter (0.1.0)
|
5
|
+
activerecord (>= 6.0.0.rc2)
|
6
|
+
aws-sdk-rdsdataservice (>= 1.10.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (6.0.0.rc2)
|
12
|
+
activesupport (= 6.0.0.rc2)
|
13
|
+
activerecord (6.0.0.rc2)
|
14
|
+
activemodel (= 6.0.0.rc2)
|
15
|
+
activesupport (= 6.0.0.rc2)
|
16
|
+
activesupport (6.0.0.rc2)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
22
|
+
aws-eventstream (1.0.3)
|
23
|
+
aws-partitions (1.192.0)
|
24
|
+
aws-sdk-core (3.61.0)
|
25
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
26
|
+
aws-partitions (~> 1.0)
|
27
|
+
aws-sigv4 (~> 1.1)
|
28
|
+
jmespath (~> 1.0)
|
29
|
+
aws-sdk-rdsdataservice (1.10.0)
|
30
|
+
aws-sdk-core (~> 3, >= 3.58.0)
|
31
|
+
aws-sigv4 (~> 1.1)
|
32
|
+
aws-sigv4 (1.1.0)
|
33
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
34
|
+
byebug (11.0.1)
|
35
|
+
coderay (1.1.2)
|
36
|
+
concurrent-ruby (1.1.5)
|
37
|
+
i18n (1.6.0)
|
38
|
+
concurrent-ruby (~> 1.0)
|
39
|
+
jmespath (1.4.0)
|
40
|
+
method_source (0.9.2)
|
41
|
+
minitest (5.11.3)
|
42
|
+
mysql2 (0.5.2)
|
43
|
+
pry (0.12.2)
|
44
|
+
coderay (~> 1.1.0)
|
45
|
+
method_source (~> 0.9.0)
|
46
|
+
pry-byebug (3.7.0)
|
47
|
+
byebug (~> 11.0)
|
48
|
+
pry (~> 0.10)
|
49
|
+
rake (10.5.0)
|
50
|
+
thread_safe (0.3.6)
|
51
|
+
tzinfo (1.2.5)
|
52
|
+
thread_safe (~> 0.1)
|
53
|
+
zeitwerk (2.1.9)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
activerecord-aws_data_service_mysql-adapter!
|
60
|
+
bundler (~> 1.17)
|
61
|
+
mysql2
|
62
|
+
pry-byebug
|
63
|
+
rake (~> 10.0)
|
64
|
+
|
65
|
+
BUNDLED WITH
|
66
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Fumiaki MATSUSHIMA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Activerecord::AwsDataServiceMysql::Adapter
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'activerecord-aws_data_service_mysql-adapter'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install activerecord-aws_data_service_mysql-adapter
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
AWS_ACCESS_KEY_ID=xxxxx
|
23
|
+
AWS_SECRET_ACCESS_KEY=xxxxx
|
24
|
+
AWS_REGION=xxxxx
|
25
|
+
DATABASE_URL=aws-data-service-mysql:///?secret_arn=arn:aws:secretsmanager:xxxxx:xxxxx:secret:xxxxx&resource_arn=arn:aws:rds:xxxxx:xxxxx:cluster:xxxxx
|
26
|
+
```
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
ActiveRecord::Base.connection.execute('SELECT 1')
|
30
|
+
```
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
45
|
+
|
46
|
+
## Code of Conduct
|
47
|
+
|
48
|
+
Everyone interacting in the Activerecord::AwsDataServiceMysql::Adapter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "activerecord-aws_data_service_mysql-adapter"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["Fumiaki MATSUSHIMA"]
|
9
|
+
spec.email = ["mtsmfm@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{An Aurora Serverless ActiveRecord adapter}
|
12
|
+
spec.description = %q{An Aurora Serverless ActiveRecord adapter}
|
13
|
+
spec.homepage = "https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
"public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.devcontainer)/}) }
|
31
|
+
end
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
spec.add_runtime_dependency "activerecord", [">= 6.0.0.rc2"]
|
37
|
+
spec.add_runtime_dependency "aws-sdk-rdsdataservice", [">= 1.10.0"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "activerecord/aws_data_service_mysql/adapter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'aws-sdk-rdsdataservice'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module AwsDataServiceMysql
|
6
|
+
class Result
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize(result, as:, symbolize_keys:, database_timezone:)
|
10
|
+
@result = result
|
11
|
+
@as = as
|
12
|
+
@symbolize_keys = symbolize_keys
|
13
|
+
@database_timezone = database_timezone
|
14
|
+
end
|
15
|
+
|
16
|
+
def each(as: @as, symbolize_keys: @symbolize_keys)
|
17
|
+
return unless @result.records || @result.generated_fields
|
18
|
+
raise if @result.records && @result.generated_fields
|
19
|
+
|
20
|
+
@result.lazy.flat_map {|page|
|
21
|
+
(page.records || [page.generated_fields]).map {|row|
|
22
|
+
row.map {|c| c.is_null ? nil : c.values.compact.first }
|
23
|
+
}
|
24
|
+
}.each do |row|
|
25
|
+
if as == :array
|
26
|
+
yield row
|
27
|
+
else
|
28
|
+
if symbolize_keys
|
29
|
+
yield fields.map(&:to_sym).zip(row).to_h
|
30
|
+
else
|
31
|
+
yield fields.zip(row).to_h
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def fields
|
38
|
+
@fields ||= @result.column_metadata ? @result.column_metadata.map(&:label) : []
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Connection
|
43
|
+
attr_reader :query_options
|
44
|
+
|
45
|
+
def initialize(secret_arn:, resource_arn:, database:, **config)
|
46
|
+
@client = ::Aws::RDSDataService::Client.new
|
47
|
+
@secret_arn = secret_arn
|
48
|
+
@resource_arn = resource_arn
|
49
|
+
@database = database
|
50
|
+
@query_options = {
|
51
|
+
database_timezone: :local,
|
52
|
+
as: :array, # Mysql2 default is hash
|
53
|
+
symbolize_keys: false
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def query(sql, **query_options)
|
58
|
+
_query(sql, **@query_options.merge(query_options))
|
59
|
+
end
|
60
|
+
|
61
|
+
def ping
|
62
|
+
query('SELECT 1')
|
63
|
+
end
|
64
|
+
|
65
|
+
def close
|
66
|
+
# nop
|
67
|
+
end
|
68
|
+
|
69
|
+
def abandon_results!
|
70
|
+
# nop
|
71
|
+
end
|
72
|
+
|
73
|
+
def affected_rows
|
74
|
+
@last_result.number_of_records_updated
|
75
|
+
end
|
76
|
+
|
77
|
+
def last_id
|
78
|
+
@last_result.generated_fields.first.values.compact.first
|
79
|
+
end
|
80
|
+
|
81
|
+
def server_info
|
82
|
+
{
|
83
|
+
version: query('SHOW VARIABLES LIKE "version";', as: :array).first.last
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def begin_db_transaction
|
88
|
+
@current_transaction = client.begin_transaction(secret_arn: secret_arn, resource_arn: resource_arn, database: database)
|
89
|
+
end
|
90
|
+
|
91
|
+
def commit_db_transaction
|
92
|
+
client.commit_transaction(secret_arn: secret_arn, resource_arn: resource_arn, transaction_id: @current_transaction.transaction_id)
|
93
|
+
@current_transaction = nil
|
94
|
+
end
|
95
|
+
|
96
|
+
def exec_rollback_db_transaction
|
97
|
+
client.rollback_transaction(secret_arn: secret_arn, resource_arn: resource_arn, transaction_id: @current_transaction.transaction_id)
|
98
|
+
@current_transaction = nil
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
attr_reader :client, :secret_arn, :resource_arn, :database
|
104
|
+
|
105
|
+
def _query(sql, **options)
|
106
|
+
@last_result = client.execute_statement(
|
107
|
+
secret_arn: secret_arn, resource_arn: resource_arn, sql: sql, database: database, include_result_metadata: true, transaction_id: @current_transaction&.transaction_id
|
108
|
+
)
|
109
|
+
Result.new(@last_result, **options)
|
110
|
+
rescue Aws::RDSDataService::Errors::BadRequestException => error
|
111
|
+
if error.message.include?("No database selected")
|
112
|
+
raise ActiveRecord::NoDatabaseError
|
113
|
+
else
|
114
|
+
raise
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
2
|
+
require 'active_record/connection_adapters/mysql/database_statements'
|
3
|
+
|
4
|
+
require 'active_record/connection_adapters/aws_data_service_mysql/connection.rb'
|
5
|
+
|
6
|
+
module ActiveRecord
|
7
|
+
module ConnectionHandling
|
8
|
+
def aws_data_service_mysql_connection(config)
|
9
|
+
ConnectionAdapters::AwsDataServiceMysqlAdapter.new(ConnectionAdapters::AwsDataServiceMysql::Connection.new(config), logger, nil, config)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ConnectionAdapters
|
14
|
+
class AwsDataServiceMysqlAdapter < AbstractMysqlAdapter
|
15
|
+
ADAPTER_NAME = 'AwsDataServiceMysql'.freeze
|
16
|
+
|
17
|
+
include MySQL::DatabaseStatements
|
18
|
+
|
19
|
+
def initialize(*)
|
20
|
+
super
|
21
|
+
@prepared_statements = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def each_hash(result)
|
25
|
+
if block_given?
|
26
|
+
result.each(as: :hash, symbolize_keys: true) do |row|
|
27
|
+
yield row
|
28
|
+
end
|
29
|
+
else
|
30
|
+
to_enum(:each_hash, result)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def begin_db_transaction
|
35
|
+
log('BEGIN') do
|
36
|
+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
37
|
+
@connection.begin_db_transaction
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def commit_db_transaction
|
43
|
+
log('COMMIT') do
|
44
|
+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
45
|
+
@connection.commit_db_transaction
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def exec_rollback_db_transaction
|
51
|
+
log('ROLLBACK') do
|
52
|
+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
53
|
+
@connection.exec_rollback_db_transaction
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def error_number(exception)
|
61
|
+
exception.error_number if exception.respond_to?(:error_number)
|
62
|
+
end
|
63
|
+
|
64
|
+
def full_version
|
65
|
+
schema_cache.database_version.full_version_string
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_full_version
|
69
|
+
@connection.server_info[:version]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
$LOAD_PATH << File.join(__dir__, 'lib')
|
9
|
+
|
10
|
+
ActiveRecord::Base.establish_connection
|
11
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
12
|
+
|
13
|
+
# DATABASE_URL=mysql2://mysql/database?pool=1 ruby test.rb
|
14
|
+
|
15
|
+
begin
|
16
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current('default_env')
|
17
|
+
rescue
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveRecord::Base.establish_connection
|
21
|
+
|
22
|
+
ActiveRecord::Schema.define do
|
23
|
+
create_table :posts, force: true do |t|
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table :comments, force: true do |t|
|
27
|
+
t.integer :post_id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Post < ActiveRecord::Base
|
32
|
+
has_many :comments
|
33
|
+
end
|
34
|
+
|
35
|
+
class Comment < ActiveRecord::Base
|
36
|
+
belongs_to :post
|
37
|
+
end
|
38
|
+
|
39
|
+
class BugTest < Minitest::Test
|
40
|
+
def setup
|
41
|
+
Post.destroy_all
|
42
|
+
Comment.destroy_all
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_association_stuff
|
46
|
+
post = Post.create!
|
47
|
+
post.comments << Comment.create!
|
48
|
+
|
49
|
+
assert_equal 1, post.comments.count
|
50
|
+
assert_equal 1, Comment.count
|
51
|
+
assert_equal post.id, Comment.first.post.id
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_transaction
|
55
|
+
assert_equal 0, Post.count
|
56
|
+
|
57
|
+
Post.transaction do
|
58
|
+
Post.create!
|
59
|
+
Post.transaction(requires_new: true) do
|
60
|
+
Post.create!
|
61
|
+
|
62
|
+
raise ActiveRecord::Rollback
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_equal 1, Post.count
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-aws_data_service_mysql-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fumiaki MATSUSHIMA
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0.rc2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0.rc2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-rdsdataservice
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.10.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.10.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: An Aurora Serverless ActiveRecord adapter
|
70
|
+
email:
|
71
|
+
- mtsmfm@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- CHANGELOG.md
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- activerecord-aws_data_service_mysql-adapter.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb
|
88
|
+
- lib/active_record/connection_adapters/aws_data_service_mysql_adapter.rb
|
89
|
+
- test.rb
|
90
|
+
homepage: https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
homepage_uri: https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter
|
95
|
+
source_code_uri: https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter
|
96
|
+
changelog_uri: https://github.com/mtsmfm/activerecord-aws_data_service_mysql-adapter
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubygems_version: 3.0.3
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: An Aurora Serverless ActiveRecord adapter
|
116
|
+
test_files: []
|