Skip to content

Change identity columns to use direct SQL query when cross database - #1356

Closed
chrisortman wants to merge 2 commits into
rails-sqlserver:7-2-stablefrom
chrisortman:7-2-stable
Closed

Change identity columns to use direct SQL query when cross database#1356
chrisortman wants to merge 2 commits into
rails-sqlserver:7-2-stablefrom
chrisortman:7-2-stable

Conversation

@chrisortman

Copy link
Copy Markdown

This is related to #1355

When trying to get identity columns, schema_cache is only valid if the database you are inserting into is the database you are connected to.

This change checks the table to see if it is database qualified and if so does a direct query to get identity columns using the system schema of the target database.

When target database is current database I preserved the old behavior so that it does not suddenly introduce an extra query for every insert. This also keeps the active record tests happy.

I did the fix against 7.2 stable because that is what I am currently running my my prod apps. If we can figure out if this is the correct approach I can port it to 8 and main as well.

@aidanharan

aidanharan commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

@chrisortman The test cases are too low level. They don't show the inserting issue you are having or whether the issue has been fixed by your changes. Could you review #1357 and let me know if that recreates the exact error you are encountering?

@chrisortman

Copy link
Copy Markdown
Author

@aidanharan Yes that reproduces the issue

@aidanharan

Copy link
Copy Markdown
Contributor

Closed in favour of #1357

@aidanharan aidanharan closed this Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants