activerecord-spanner-adapter 2.0.0 → 2.1.0
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
- data/.kokoro/release.cfg +2 -2
- data/.kokoro/release.sh +1 -2
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +10 -0
- data/README.md +25 -23
- data/acceptance/cases/models/default_value_test.rb +2 -2
- data/acceptance/cases/tasks/database_tasks_test.rb +71 -74
- data/acceptance/cases/transactions/read_write_transactions_test.rb +10 -4
- data/acceptance/test_helper.rb +21 -8
- data/activerecord-spanner-adapter.gemspec +1 -1
- data/examples/snippets/Rakefile +1 -0
- data/examples/snippets/auto-generated-primary-key/README.md +140 -0
- data/examples/snippets/auto-generated-primary-key/Rakefile +13 -0
- data/examples/snippets/auto-generated-primary-key/application.rb +86 -0
- data/examples/snippets/auto-generated-primary-key/config/database.yml +10 -0
- data/examples/snippets/auto-generated-primary-key/db/migrate/01_create_tables.rb +29 -0
- data/examples/snippets/auto-generated-primary-key/db/seeds.rb +31 -0
- data/examples/snippets/auto-generated-primary-key/models/album.rb +11 -0
- data/examples/snippets/auto-generated-primary-key/models/singer.rb +11 -0
- data/lib/active_record/connection_adapters/spanner/column.rb +4 -0
- data/lib/active_record/connection_adapters/spanner/schema_creation.rb +13 -2
- data/lib/active_record/connection_adapters/spanner/schema_statements.rb +5 -5
- data/lib/active_record/connection_adapters/spanner/type_metadata.rb +7 -3
- data/lib/active_record/connection_adapters/spanner_adapter.rb +22 -0
- data/lib/activerecord_spanner_adapter/base.rb +49 -16
- data/lib/activerecord_spanner_adapter/information_schema.rb +4 -2
- data/lib/activerecord_spanner_adapter/table/column.rb +4 -1
- data/lib/activerecord_spanner_adapter/version.rb +1 -1
- metadata +13 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 539c47de17139481981cfaaaf2b65d43d8f0b27642ad68663658123d0053a8fb
|
4
|
+
data.tar.gz: c4eb45d075689d08da773ebc11bd1e24df9c6cb7b6ab79a2a352c5c4f4442fbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d32fa8e2aeeb7785a35f4d11c2dd1ae2db7298d030b6d0da3f08ef5acb2c19833f4f80bc4b5e4b3b174ff9a34121fe97f50ddae902a3af1505eacec311b790
|
7
|
+
data.tar.gz: 1ec5e7a0370d3bbcc3dd8b0c2b7412f81a57f03703784a0b20476d20d9016d409efcd4f3dc8ecd234e64d1cbedcfe804497fd6b65fd277d7feca014393627edf
|
data/.kokoro/release.cfg
CHANGED
@@ -13,7 +13,7 @@ build_file: "ruby-spanner-activerecord/.kokoro/trampoline_v2.sh"
|
|
13
13
|
# Configure the docker image for kokoro-trampoline.
|
14
14
|
env_vars: {
|
15
15
|
key: "TRAMPOLINE_IMAGE"
|
16
|
-
value: "us-central1-docker.pkg.dev/cloud-sdk-release-custom-pool/release-images/ruby-
|
16
|
+
value: "us-central1-docker.pkg.dev/cloud-sdk-release-custom-pool/release-images/ruby-release"
|
17
17
|
}
|
18
18
|
|
19
19
|
env_vars: {
|
@@ -28,7 +28,7 @@ env_vars: {
|
|
28
28
|
|
29
29
|
env_vars: {
|
30
30
|
key: "SECRET_MANAGER_KEYS"
|
31
|
-
value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem
|
31
|
+
value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem"
|
32
32
|
}
|
33
33
|
|
34
34
|
# Pick up Rubygems key from internal keystore
|
data/.kokoro/release.sh
CHANGED
@@ -7,5 +7,4 @@ set -eo pipefail
|
|
7
7
|
export GEM_HOME=$HOME/.gem
|
8
8
|
export PATH=$GEM_HOME/bin:$PATH
|
9
9
|
|
10
|
-
|
11
|
-
toys release perform -v --reporter-org=googleapis --enable-docs --force-republish --enable-docs --enable-rad < /dev/null
|
10
|
+
toys release perform -v --reporter-org=googleapis --force-republish --enable-rad < /dev/null
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 2.1.0 (2025-03-17)
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* support IDENTITY columns for auto-generated primary keys ([#352](https://github.com/googleapis/ruby-spanner-activerecord/issues/352))
|
8
|
+
#### Documentation
|
9
|
+
|
10
|
+
* add a test to verify that FOR UPDATE can be used ([#348](https://github.com/googleapis/ruby-spanner-activerecord/issues/348))
|
11
|
+
* update README with the correct supported versions ([#349](https://github.com/googleapis/ruby-spanner-activerecord/issues/349))
|
12
|
+
|
3
13
|
### 2.0.0 (2025-01-23)
|
4
14
|
|
5
15
|
### ⚠ BREAKING CHANGES
|
data/README.md
CHANGED
@@ -4,16 +4,17 @@
|
|
4
4
|
|
5
5
|

|
6
6
|
|
7
|
-
__This adapter only supports GoogleSQL-dialect
|
7
|
+
__This adapter only supports GoogleSQL-dialect Spanner databases. PostgreSQL-dialect
|
8
8
|
databases are not supported. You can use the standard PostgreSQL ActiveRecord adapter in
|
9
9
|
[combination with PGAdapter](https://github.com/GoogleCloudPlatform/pgadapter/blob/-/samples/ruby/activerecord)
|
10
|
-
for
|
10
|
+
for Spanner PostgreSQL-dialect databases.__
|
11
11
|
|
12
|
-
This project provides a
|
12
|
+
This project provides a Spanner adapter for ActiveRecord. It supports the following versions:
|
13
13
|
|
14
|
-
- ActiveRecord
|
15
|
-
- ActiveRecord
|
16
|
-
- ActiveRecord 7.
|
14
|
+
- ActiveRecord 7.0.x with Ruby 3.1 and higher.
|
15
|
+
- ActiveRecord 7.1.x with Ruby 3.1 and higher.
|
16
|
+
- ActiveRecord 7.2.x with Ruby 3.1 and higher.
|
17
|
+
- ActiveRecord 8.0.x with Ruby 3.2 and higher.
|
17
18
|
|
18
19
|
Known limitations are listed in the [Limitations](#limitations) section.
|
19
20
|
Please report any problems that you might encounter by [creating a new issue](https://github.com/googleapis/ruby-spanner-activerecord/issues/new).
|
@@ -41,7 +42,7 @@ And then execute:
|
|
41
42
|
### Migrations
|
42
43
|
__Use DDL batching when executing migrations for the best possible performance.__
|
43
44
|
|
44
|
-
Executing multiple schema changes on
|
45
|
+
Executing multiple schema changes on Spanner can take a long time. It is therefore
|
45
46
|
strongly recommended that you limit the number of schema change operations. You can do
|
46
47
|
this by using DDL batching in your migrations. See [the migrations examples](examples/snippets/migrations)
|
47
48
|
for how to do this.
|
@@ -62,8 +63,8 @@ development:
|
|
62
63
|
To get started with Rails, read the tutorial under {file:examples/rails/README.md examples/rails/README.md}.
|
63
64
|
|
64
65
|
You can also find a list of short self-contained code examples that show how
|
65
|
-
to use ActiveRecord with
|
66
|
-
database, as all samples will automatically start a
|
66
|
+
to use ActiveRecord with Spanner under the directory [examples/snippets](examples/snippets). Each example is directly runnable without the need to setup a Spanner
|
67
|
+
database, as all samples will automatically start a Spanner emulator in a Docker container and execute the sample
|
67
68
|
code against that emulator. All samples can be executed by navigating to the sample directory on your local machine and
|
68
69
|
then executing the command `bundle exec rake run`. Example:
|
69
70
|
|
@@ -76,29 +77,30 @@ __NOTE__: You do need to have [Docker](https://docs.docker.com/get-docker/) inst
|
|
76
77
|
|
77
78
|
Some noteworthy examples in the snippets directory:
|
78
79
|
- [quickstart](examples/snippets/quickstart): A simple application that shows how to create and query a simple database containing two tables.
|
79
|
-
- [migrations](examples/snippets/migrations): Shows a best-practice for executing migrations on
|
80
|
+
- [migrations](examples/snippets/migrations): Shows a best-practice for executing migrations on Spanner.
|
81
|
+
- [auto-generated-primary-key](examples/snippets/auto-generated-primary-key): Shows how to use IDENTITY columns for primary keys.
|
80
82
|
- [bit-reversed-sequences](examples/snippets/bit-reversed-sequence): Shows how to use bit-reversed sequences for primary keys.
|
81
|
-
- [read-write-transactions](examples/snippets/read-write-transactions): Shows how to execute transactions on
|
82
|
-
- [read-only-transactions](examples/snippets/read-only-transactions): Shows how to execute read-only transactions on
|
83
|
+
- [read-write-transactions](examples/snippets/read-write-transactions): Shows how to execute transactions on Spanner.
|
84
|
+
- [read-only-transactions](examples/snippets/read-only-transactions): Shows how to execute read-only transactions on Spanner.
|
83
85
|
- [bulk-insert](examples/snippets/bulk-insert): Shows the best way to insert a large number of new records.
|
84
86
|
- [mutations](examples/snippets/mutations): Shows how you can use [mutations instead of DML](https://cloud.google.com/spanner/docs/dml-versus-mutations)
|
85
|
-
for inserting, updating and deleting data in a
|
87
|
+
for inserting, updating and deleting data in a Spanner database. Mutations can have a significant performance
|
86
88
|
advantage compared to DML statements, but do not allow read-your-writes semantics during a transaction.
|
87
89
|
- [array-data-type](examples/snippets/array-data-type): Shows how to work with `ARRAY` data types.
|
88
90
|
- [interleaved-tables](examples/snippets/interleaved-tables-before-7.1): Shows how to work with [Interleaved Tables](https://cloud.google.com/spanner/docs/schema-and-data-model#create-interleaved-tables).
|
89
91
|
|
90
92
|
## Limitations
|
91
93
|
|
92
|
-
| Limitation
|
93
|
-
|
94
|
-
| Interleaved tables require composite primary keys
|
95
|
-
| Lack of sequential IDs
|
96
|
-
| Table without Primary Key
|
97
|
-
| Table names CANNOT have spaces within them whether back-ticked or not
|
98
|
-
| Table names CANNOT have punctuation marks and MUST contain valid UTF-8
|
99
|
-
| Index with fields length [add_index](https://apidock.com/rails/v5.2.3/ActiveRecord/ConnectionAdapters/SchemaStatements/add_index)
|
100
|
-
| Only GoogleSQL-dialect databases
|
101
|
-
| `rails dbconsole` is not supported.
|
94
|
+
| Limitation | Comment | Resolution |
|
95
|
+
|------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
|
96
|
+
| Interleaved tables require composite primary keys | Spanner requires composite primary keys for interleaved tables. See {file:examples/snippets/interleaved-tables/README.md this example} for an example on how to use interleaved tables with ActiveRecord | Use composite primary keys. |
|
97
|
+
| Lack of sequential IDs | Spanner uses either bit-reversed IDENTITY columns or sequences to generated primary keys to avoid [hotspotting](https://cloud.google.com/spanner/docs/schema-design#uuid_primary_key) so you SHOULD NOT rely on IDs being sorted | Use either IDENTITY columns or bit-reversed sequences to automatically generate primary keys. |
|
98
|
+
| Table without Primary Key | Spanner support does not support tables without a primary key. | Always define a primary key for your table. |
|
99
|
+
| Table names CANNOT have spaces within them whether back-ticked or not | Spanner DOES NOT support tables with spaces in them for example `Entity ID` | Ensure that your table names don't contain spaces. |
|
100
|
+
| Table names CANNOT have punctuation marks and MUST contain valid UTF-8 | Spanner DOES NOT support punctuation marks e.g. periods ".", question marks "?" in table names | Ensure that your table names don't contain punctuation marks. |
|
101
|
+
| Index with fields length [add_index](https://apidock.com/rails/v5.2.3/ActiveRecord/ConnectionAdapters/SchemaStatements/add_index) | Spanner does not support index with fields length | Ensure that your database definition does not include index definitions with field lengths. |
|
102
|
+
| Only GoogleSQL-dialect databases | Spanner supports both GoogleSQL- and PostgreSQL-dialect databases. This adapter only supports GoogleSQL-dialect databases. You can use the [PostgreSQL ActiveRecord provider in combination with PGAdapter](https://github.com/GoogleCloudPlatform/pgadapter/tree/postgresql-dialect/samples/ruby/activerecord) for Spanner PostgreSQL databases. | |
|
103
|
+
| `rails dbconsole` is not supported. | The `rails dbconsole` is not supported for Spanner databases. | |
|
102
104
|
|
103
105
|
|
104
106
|
## Contributing
|
@@ -31,7 +31,7 @@ module Models
|
|
31
31
|
t.column :col_timestamp, :datetime, default: default.col_timestamp
|
32
32
|
end
|
33
33
|
|
34
|
-
item = LiteralValue.new
|
34
|
+
item = LiteralValue.new id: connection.next_sequence_value(nil)
|
35
35
|
default.each_pair { |col, expected| assert_equal(expected, item[col]) }
|
36
36
|
item.save!
|
37
37
|
default.each_pair { |col, expected| assert_equal(expected, item[col]) }
|
@@ -45,7 +45,7 @@ module Models
|
|
45
45
|
t.column :col_timestamp, :datetime, default: -> { "CURRENT_TIMESTAMP()" }
|
46
46
|
end
|
47
47
|
|
48
|
-
item = ExpressionValue.create!
|
48
|
+
item = ExpressionValue.create! id: connection.next_sequence_value(nil)
|
49
49
|
item.reload
|
50
50
|
assert_equal(BigDecimal("1.23"), item.col_numeric)
|
51
51
|
assert(item.col_timestamp)
|