activerecord-aurora-serverless-adapter 5.2.2 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -3
  3. data/Gemfile.lock +63 -55
  4. data/README.md +5 -4
  5. data/activerecord-aurora-serverless-adapter.gemspec +2 -5
  6. data/lib/active_record/connection_adapters/aurora_serverless/client.rb +0 -25
  7. data/lib/active_record/connection_adapters/aurora_serverless/mysql2.rb +14 -13
  8. data/lib/active_record/connection_adapters/aurora_serverless/mysql2/client.rb +0 -4
  9. data/lib/active_record/connection_adapters/aurora_serverless/version.rb +1 -1
  10. data/lib/mysql2.rb +1 -0
  11. metadata +5 -43
  12. data/test/aasa_helper.rb +0 -163
  13. data/test/aurora-serverless/bin/aurora-serverless.ts +0 -17
  14. data/test/aurora-serverless/cdk.context.json +0 -3
  15. data/test/aurora-serverless/cdk.json +0 -3
  16. data/test/aurora-serverless/lib/aurora-serverless-stack.ts +0 -194
  17. data/test/aurora-serverless/package-lock.json +0 -6485
  18. data/test/aurora-serverless/package.json +0 -21
  19. data/test/aurora-serverless/tsconfig.json +0 -23
  20. data/test/bin/_deploy-aurora +0 -8
  21. data/test/bin/_wakeup +0 -17
  22. data/test/bin/deploy-aurora +0 -8
  23. data/test/bin/wakeup +0 -8
  24. data/test/cases/aasa/mysql_client_test.rb +0 -59
  25. data/test/cases/aasa/mysql_result_test.rb +0 -63
  26. data/test/cases/aasa/mysql_types_test.rb +0 -135
  27. data/test/cases/coerced_tests.rb +0 -151
  28. data/test/config.yml +0 -20
  29. data/test/support/aasa_coerceable.rb +0 -53
  30. data/test/support/aasa_env.rb +0 -11
  31. data/test/support/aasa_fixtures.rb +0 -9
  32. data/test/support/aasa_minitest.rb +0 -39
  33. data/test/support/aasa_mysqlpatch.rb +0 -8
  34. data/test/support/aasa_paths.rb +0 -47
  35. data/test/support/aasa_rake.rb +0 -102
@@ -1,21 +0,0 @@
1
- {
2
- "name": "aasa-aurora-serverless",
3
- "version": "0.1.0",
4
- "bin": {
5
- "aurora-serverless": "bin/aurora-serverless.js"
6
- },
7
- "devDependencies": {
8
- "@aws-cdk/assert": "^1.19.0",
9
- "@types/node": "10.17.5",
10
- "aws-cdk": "^1.19.0",
11
- "ts-node": "^8.1.0",
12
- "typescript": "~3.7.2"
13
- },
14
- "dependencies": {
15
- "@aws-cdk/aws-ec2": "^1.19.0",
16
- "@aws-cdk/aws-rds": "^1.19.0",
17
- "@aws-cdk/aws-secretsmanager": "^1.19.0",
18
- "@aws-cdk/core": "^1.19.0",
19
- "source-map-support": "^0.5.16"
20
- }
21
- }
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target":"ES2018",
4
- "module": "commonjs",
5
- "lib": ["es2018"],
6
- "declaration": true,
7
- "strict": true,
8
- "noImplicitAny": true,
9
- "strictNullChecks": true,
10
- "noImplicitThis": true,
11
- "alwaysStrict": true,
12
- "noUnusedLocals": false,
13
- "noUnusedParameters": false,
14
- "noImplicitReturns": true,
15
- "noFallthroughCasesInSwitch": false,
16
- "inlineSourceMap": true,
17
- "inlineSources": true,
18
- "experimentalDecorators": true,
19
- "strictPropertyInitialization":false,
20
- "typeRoots": ["./node_modules/@types"]
21
- },
22
- "exclude": ["cdk.out"]
23
- }
@@ -1,8 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- pushd test/aurora-serverless
5
-
6
- npm install
7
- tsc
8
- cdk deploy --require-approval never "*"
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env bash
2
- set +e
3
-
4
- export AWS_PROFILE=${AWS_PROFILE:=default}
5
- export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1}
6
-
7
- aws rds-data execute-statement \
8
- --database "activerecord_unittest" \
9
- --secret-arn "${AASA_SECRET_ARN}" \
10
- --resource-arn "${AASA_RESOURCE_ARN}" \
11
- --sql "SELECT 1"
12
-
13
- aws rds-data execute-statement \
14
- --database "activerecord_unittest2" \
15
- --secret-arn "${AASA_SECRET_ARN2}" \
16
- --resource-arn "${AASA_RESOURCE_ARN2}" \
17
- --sql "SELECT 1"
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- docker-compose \
5
- --project-name aasa \
6
- run \
7
- cdk \
8
- ./test/bin/_deploy-aurora
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- docker-compose \
5
- --project-name aasa \
6
- run \
7
- cdk \
8
- ./test/bin/_wakeup
@@ -1,59 +0,0 @@
1
- require 'aasa_helper'
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module AuroraServerless
6
- class ClientTest < TestCase
7
-
8
- it '#server_info' do
9
- expect(client.server_info).must_equal({
10
- version: '5.6.10'
11
- })
12
- end
13
-
14
- it '#escape' do
15
- expect(client.escape("\\ \001 ' \n \\n \"")).
16
- must_equal("\\\\ \u0001 \\' \\n \\\\n \\\"")
17
- expect(client.escape("abc'def\"ghi\0jkl%mno")).
18
- must_equal("abc\\'def\\\"ghi\\0jkl%mno")
19
- end
20
-
21
- it '#ping' do
22
- expect(client.ping).must_equal true
23
- end
24
-
25
- it 'transactions' do
26
- begin
27
- execute "DELETE FROM aurora_test"
28
- client.begin_db_transaction
29
- execute "INSERT INTO aurora_test (int_test) VALUES (1)"
30
- expect(execute("SELECT int_test FROM aurora_test").to_a).must_equal [[1]]
31
- ensure
32
- client.exec_rollback_db_transaction
33
- expect(execute("SELECT int_test FROM aurora_test").to_a).must_equal []
34
- end
35
- end
36
-
37
- it '#affected_rows' do
38
- execute "DELETE FROM aurora_test"
39
- execute "INSERT INTO aurora_test (int_test) VALUES (1)"
40
- expect(client.affected_rows).must_equal 1
41
- execute "SELECT * FROM aurora_test"
42
- expect(client.affected_rows).must_equal 0
43
- execute "INSERT INTO aurora_test (int_test) VALUES (1)"
44
- execute "INSERT INTO aurora_test (int_test) VALUES (1)"
45
- execute "DELETE FROM aurora_test"
46
- expect(client.affected_rows).must_equal 3
47
- end
48
-
49
- it '#last_id' do
50
- execute "INSERT INTO aurora_test (int_test) VALUES (1)"
51
- expect(client.last_id).must_equal 2
52
- execute "INSERT INTO aurora_test (int_test) VALUES (1)"
53
- expect(client.last_id).must_equal 3
54
- end
55
-
56
- end
57
- end
58
- end
59
- end
@@ -1,63 +0,0 @@
1
- require 'aasa_helper'
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module AuroraServerless
6
- class ResultTest < TestCase
7
-
8
- it '#each' do
9
- execute "DELETE FROM aurora_test"
10
- execute "INSERT INTO aurora_test (int_test, bit_test) VALUES (1, 1)"
11
- execute "INSERT INTO aurora_test (int_test, bit_test) VALUES (2, 0)"
12
- execute "INSERT INTO aurora_test (int_test, bit_test) VALUES (3, 1)"
13
- # Default as: :array.
14
- result = execute "SELECT int_test, bit_test FROM aurora_test"
15
- expect(result.each.length).must_equal 3
16
- result.each do |row|
17
- expect(row).must_be_instance_of Array
18
- end
19
- expect(result.each[0]).must_equal [1, true]
20
- expect(result.each[1]).must_equal [2, false]
21
- expect(result.each[2]).must_equal [3, true]
22
- # Using as: :hash option for columns. Also uses :symbolize_keys too.
23
- result = execute "SELECT int_test, bit_test FROM aurora_test"
24
- kwargs = { as: :hash, symbolize_keys: true }
25
- result.each(**kwargs) do |row|
26
- expect(row).must_be_instance_of Hash
27
- end
28
- expect(result.each(**kwargs)[0]).must_equal({int_test: 1, bit_test: true})
29
- expect(result.each(**kwargs)[1]).must_equal({int_test: 2, bit_test: false})
30
- expect(result.each(**kwargs)[2]).must_equal({int_test: 3, bit_test: true})
31
- end
32
-
33
- it '#fields and #to_a to work' do
34
- result = execute('SELECT 1 as one')
35
- assert_equal ['one'], result.fields
36
- assert_equal [[1]], result.to_a
37
- end
38
-
39
- it 'multiple values' do
40
- execute "DELETE FROM aurora_test"
41
- execute "INSERT INTO aurora_test (int_test, big_int_test) VALUES (1, 11)"
42
- execute "INSERT INTO aurora_test (int_test, big_int_test) VALUES (2, 22)"
43
- execute "INSERT INTO aurora_test (int_test, big_int_test) VALUES (3, 33)"
44
- result = execute('
45
- SELECT int_test, big_int_test
46
- FROM aurora_test
47
- WHERE int_test IS NOT NULL
48
- OR big_int_test IS NOT NULL
49
- ')
50
- assert_equal ['int_test', 'big_int_test'], result.fields
51
- assert_equal [[1, 11], [2, 22], [3, 33]], result.to_a
52
- end
53
-
54
- it 'no results' do
55
- result = execute('SELECT null_test FROM aurora_test WHERE 1 = 2')
56
- assert_equal ['null_test'], result.fields
57
- assert_equal [], result.to_a
58
- end
59
-
60
- end
61
- end
62
- end
63
- end
@@ -1,135 +0,0 @@
1
- require 'aasa_helper'
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module AuroraServerless
6
- class TypesTest < TestCase
7
-
8
- it 'null_test' do
9
- expect(value('null_test')).must_be_nil
10
- end
11
-
12
- it 'bit_test' do
13
- expect(value('bit_test')).must_equal true
14
- end
15
-
16
- it 'tiny_int_test' do
17
- expect(value('tiny_int_test')).must_equal 5
18
- end
19
-
20
- it 'small_int_test' do
21
- expect(value('small_int_test')).must_equal 32766
22
- end
23
-
24
- it 'medium_int_test' do
25
- expect(value('medium_int_test')).must_equal 8388606
26
- end
27
-
28
- it 'int_test' do
29
- expect(value('int_test')).must_equal 2147483646
30
- end
31
-
32
- it 'big_int_test' do
33
- expect(value('big_int_test')).must_equal 9223372036854775806
34
- end
35
-
36
- it 'float_test' do
37
- expect(value('float_test')).must_equal 156.684
38
- end
39
-
40
- it 'float_zero_test' do
41
- expect(value('float_zero_test')).must_equal 0.0
42
- end
43
-
44
- it 'double_test' do
45
- expect(value('double_test')).must_equal 606682.888
46
- end
47
-
48
- it 'decimal_test' do
49
- expect(value('decimal_test')).must_equal BigDecimal.new('676254.545')
50
- end
51
-
52
- it 'date_test' do
53
- expect(value('date_test')).must_be_instance_of Date
54
- expect(value('date_test').strftime("%Y-%m-%d")).must_equal '2010-04-04'
55
- end
56
-
57
- it 'date_time_test' do
58
- expect(value('date_time_test')).must_be_instance_of String
59
- expect(value('date_time_test')).must_equal '2010-04-04 11:44:00'
60
- end
61
-
62
- it 'timestamp_test' do
63
- expect(value('timestamp_test')).must_be_instance_of String
64
- expect(value('timestamp_test')).must_equal '2010-04-04 11:44:00'
65
- end
66
-
67
- it 'time_test' do
68
- expect(value('time_test')).must_be_instance_of String
69
- expect(value('time_test')).must_equal '11:44:00'
70
- end
71
-
72
- it 'year_test' do
73
- expect(value('year_test')).must_equal 2019
74
- end
75
-
76
- it 'char_test' do
77
- expect(value('char_test')).must_equal 'abcdefg'
78
- end
79
-
80
- it 'varchar_test' do
81
- expect(value('varchar_test')).must_equal 'abcdefg'
82
- end
83
-
84
- it 'binary_test' do
85
- expect(value('binary_test')).must_equal "abcdefg#{"\000" * 3}"
86
- expect(value('binary_test').encoding).must_equal Encoding::ASCII_8BIT
87
- end
88
-
89
- it 'varbinary_test' do
90
- expect(value('varbinary_test')).must_equal "abcdefg"
91
- expect(value('varbinary_test').encoding).must_equal Encoding::ASCII_8BIT
92
- end
93
-
94
- it 'tiny_blob_test' do
95
- expect(value('tiny_blob_test')).must_equal "abcdefg"
96
- expect(value('tiny_blob_test').encoding).must_equal Encoding::ASCII_8BIT
97
- end
98
-
99
- it 'tiny_text_test' do
100
- expect(value('tiny_text_test')).must_equal "abcdefg"
101
- end
102
-
103
- it 'blob_test' do
104
- expect(value('blob_test')).must_equal "abcdefg"
105
- expect(value('blob_test').encoding).must_equal Encoding::ASCII_8BIT
106
- end
107
-
108
- it 'text_test' do
109
- expect(value('text_test')).must_equal "abcdefg"
110
- end
111
-
112
- it 'medium_blob_test' do
113
- expect(value('medium_blob_test')).must_equal "abcdefg"
114
- expect(value('medium_blob_test').encoding).must_equal Encoding::ASCII_8BIT
115
- end
116
-
117
- it 'long_blob_test' do
118
- expect(value('long_blob_test')).must_equal "abcdefg"
119
- expect(value('long_blob_test').encoding).must_equal Encoding::ASCII_8BIT
120
- end
121
-
122
- it 'long_text_test' do
123
- expect(value('long_text_test')).must_equal "abcdefg"
124
- end
125
-
126
- private
127
-
128
- def value(column)
129
- @value ||= execute("SELECT #{column} FROM aurora_test LIMIT 1").to_a.first.first
130
- end
131
-
132
- end
133
- end
134
- end
135
- end
@@ -1,151 +0,0 @@
1
- require 'aasa_helper'
2
-
3
- class BasicsTest < ActiveRecord::TestCase
4
- # This segfault my local ruby.
5
- coerce_tests! :test_marshalling_with_associations,
6
- :test_marshal_between_processes
7
-
8
- # We are like PG and avoid this test.
9
- coerce_tests! :test_respect_internal_encoding
10
- end
11
-
12
- class TimePrecisionTest < ActiveRecord::TestCase
13
- coerce_tests! :test_formatting_time_according_to_precision
14
- # Value `999000` in test, core is `999900`, too much for aurora serverless.
15
- def test_formatting_time_according_to_precision_coerced
16
- skip unless @connection # Avoids arunit2 suite run errors.
17
- @connection.create_table(:foos, force: true) do |t|
18
- t.time :start, precision: 0
19
- t.time :finish, precision: 4
20
- end
21
- time = ::Time.utc(2000, 1, 1, 12, 30, 0, 999999)
22
- Foo.create!(start: time, finish: time)
23
- assert foo = Foo.find_by(start: time)
24
- assert_equal 1, Foo.where(finish: time).count
25
- assert_equal time.to_s, foo.start.to_s
26
- assert_equal time.to_s, foo.finish.to_s
27
- assert_equal 000000, foo.start.usec
28
- assert_equal 999000, foo.finish.usec
29
- end
30
-
31
- # Value `123000000` in test, core is `123456000`, too much for aurora serverless.
32
- coerce_tests! :test_time_precision_is_truncated_on_assignment
33
- def test_time_precision_is_truncated_on_assignment_coerced
34
- skip unless @connection # Avoids arunit2 suite run errors.
35
- @connection.create_table(:foos, force: true)
36
- @connection.add_column :foos, :start, :time, precision: 0
37
- @connection.add_column :foos, :finish, :time, precision: 6
38
- time = ::Time.now.change(nsec: 123456789)
39
- foo = Foo.new(start: time, finish: time)
40
- assert_equal 0, foo.start.nsec
41
- assert_equal 123456000, foo.finish.nsec
42
- foo.save!
43
- foo.reload
44
- assert_equal 0, foo.start.nsec
45
- assert_equal 123000000, foo.finish.nsec
46
- end
47
- end
48
-
49
- class TransactionTest < ActiveRecord::TestCase
50
- # These use `assert_sql` for transactions. No can do since we make a SDK call.
51
- coerce_tests! :test_accessing_raw_connection_disables_lazy_transactions,
52
- :test_accessing_raw_connection_materializes_transaction,
53
- :test_unprepared_statement_materializes_transaction,
54
- :test_transactions_can_be_manually_materialized
55
- end
56
-
57
- # TOOD: This inherits (and runs) the `TransactionTest` case file. However,
58
- # there is a slight chance one fails due to a foreign key constraints issue.
59
- # If you want to play, comment this out and.
60
- #
61
- # TESTOPTS="-n='/ConcurrentTransactionTest/'" ONLY_ACTIVERECORD=1 bundle exec rake
62
- #
63
- class ConcurrentTransactionTest < TransactionTest
64
- coerce_all_tests!
65
- end
66
-
67
- class LogSubscriberTest < ActiveRecord::TestCase
68
- # False positive due to Rails bundle.
69
- coerce_tests! :test_vebose_query_logs
70
- end
71
-
72
- module ActiveRecord
73
- class AdapterTest < ActiveRecord::TestCase
74
- # Cross DB selects are simply not going to work.
75
- coerce_tests! :test_not_specifying_database_name_for_cross_database_selects
76
- end
77
- end
78
-
79
- class FixturesTest < ActiveRecord::TestCase
80
- # We do not support batch statements.
81
- coerce_tests! :test_bulk_insert_multiple_table_with_a_multi_statement_query,
82
- :test_insert_fixtures_set_raises_an_error_when_max_allowed_packet_is_smaller_than_fixtures_set_size,
83
- :test_bulk_insert_with_multi_statements_enabled,
84
- :test_insert_fixtures_set_concat_total_sql_into_a_single_packet_smaller_than_max_allowed_packet
85
- end
86
-
87
- module ActiveRecord
88
- module ConnectionAdapters
89
- class SchemaCacheTest < ActiveRecord::TestCase
90
- private
91
- # These tests can not find the `schema_dump_path` because of our test
92
- # setup and we can help fix that using test/config.rb constants.
93
- def schema_dump_path
94
- File.join ASSETS_ROOT, "schema_dump_5_1.yml"
95
- end
96
- end
97
- end
98
- end
99
-
100
- class AttributeMethodsTest < ActiveRecord::TestCase
101
- # Our before type cast is actually a boolean.
102
- coerce_tests! :test_read_attributes_before_type_cast_on_a_boolean
103
- end
104
-
105
- module ActiveRecord
106
- class MysqlDBCreateWithInvalidPermissionsTest < ActiveRecord::TestCase
107
- # This adapter can not create DBs.
108
- coerce_tests! :test_raises_error
109
- end
110
- end
111
-
112
- module ActiveRecord
113
- module ConnectionAdapters
114
- class ConnectionHandlersMultiDbTest < ActiveRecord::TestCase
115
- # This tries to load PG for some reason.
116
- coerce_tests! :test_switching_connections_with_database_url
117
-
118
- # No sqlite3 tests.
119
- coerce_tests! :test_multiple_connection_handlers_works_in_a_threaded_environment,
120
- :test_time_precision_is_truncated_on_assignment_coerced,
121
- :test_formatting_time_according_to_precision_coerced
122
- end
123
- end
124
- end
125
-
126
- module ActiveRecord
127
- module ConnectionAdapters
128
- class ConnectionHandlerTest < ActiveRecord::TestCase
129
- # No sqlite3 tests.
130
- coerce_tests! :test_establish_connection_using_2_level_config_defaults_to_default_env_primary_db,
131
- :test_establish_connection_using_3_level_config_defaults_to_default_env_primary_db
132
- end
133
- end
134
- end
135
-
136
- # ----------------
137
- # RAILS 5-2-stable
138
- # ----------------
139
-
140
- module ActiveRecord
141
- class AdapterTest < ActiveRecord::TestCase
142
- coerce_tests! :test_log_invalid_encoding,
143
- :test_create_record_with_pk_as_zero
144
- end
145
- end
146
-
147
- module ActiveRecord
148
- class DatabaseTasksUtilsTask < ActiveRecord::TestCase
149
- coerce_all_tests!
150
- end
151
- end