Skip to content

fix: allow functions to be default values#252

Merged
olavloite merged 8 commits intogoogleapis:mainfrom
nownabe:default-value-func
Jun 1, 2023
Merged

fix: allow functions to be default values#252
olavloite merged 8 commits intogoogleapis:mainfrom
nownabe:default-value-func

Conversation

@nownabe
Copy link
Contributor

@nownabe nownabe commented May 16, 2023

Fix #247

@nownabe nownabe requested review from a team and olavloite as code owners May 16, 2023 02:20
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. label May 16, 2023
@nownabe nownabe force-pushed the default-value-func branch from cb59754 to 875fc04 Compare May 16, 2023 04:00
@nownabe
Copy link
Contributor Author

nownabe commented May 16, 2023

On GitHub Actions, the right parenthesis of CURRENT_TIMESTAMP() dissapears... πŸ€”

# GitHub Action
#<Google::Cloud::Spanner::Data ((COLUMN_NAME)"col_timestamp", (SPANNER_TYPE)"TIMESTAMP", (IS_NULLABLE)"YES", (GENERATION_EXPRESSION)nil, (COLUMN_DEFAULT)"CURRENT_TIMESTAMP(", (ORDINAL_POSITION)2)>

# Local
#<Google::Cloud::Spanner::Data ((COLUMN_NAME)"col_timestamp", (SPANNER_TYPE)"TIMESTAMP", (IS_NULLABLE)"YES", (GENERATION_EXPRESSION)nil, (COLUMN_DEFAULT)"CURRENT_TIMESTAMP()", (ORDINAL_POSITION)2)>

Because newer Spanner emulators have a bug aroud information schema.
They cannot return correct values for COLUMN_DEFAULT.

spanner> SELECT COLUMN_NAME, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME="dynamic_items";
+---------------+--------------------+
| COLUMN_NAME   | COLUMN_DEFAULT     |
+---------------+--------------------+
| id            | NULL               |
| col_timestamp | CURRENT_TIMESTAMP( |
+---------------+--------------------+
2 rows in set (2.079298ms)
@nownabe nownabe force-pushed the default-value-func branch from 024e00c to 37bbdeb Compare May 16, 2023 08:59
@nownabe
Copy link
Contributor Author

nownabe commented May 16, 2023

On GitHub Actions, the right parenthesis of CURRENT_TIMESTAMP() dissapears...

It was a bug of emulator v1.5.1 and newer.

@nownabe
Copy link
Contributor Author

nownabe commented May 17, 2023

@olavloite
Copy link
Collaborator

@nownabe Thanks for this change. LGTM. I've reverted the tests to using the latest version of the emulator, as it appears that the bug that you discovered has been fixed.

@olavloite
Copy link
Collaborator

The current build error appears to be caused by ActiveRecord 7.0.5, which contains a change in index_exists?: https://github.com/rails/rails/blob/v7.0.5/activerecord/CHANGELOG.md

@olavloite olavloite merged commit f651bbf into googleapis:main Jun 1, 2023
@nownabe nownabe deleted the default-value-func branch June 1, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/ruby-spanner-activerecord API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to create a record which has CURRENT_TIMESTAMP() as a default value in its schema

2 participants