Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set DB transactions to read-only and provide messaging for non-read operations #21

Merged
merged 2 commits into from
Sep 7, 2017

Conversation

timothysu
Copy link
Contributor

This fixes #18 and also fixes #19 , where transactions are always read-only in sandbox (read-only) mode. Clearer messaging is added when a user tries to make a non-read operation.

screen shot 2017-09-01 at 4 33 03 pm

prime: @cjf2xn

module PostgreSQLAdapter
def begin_db_transaction
super
execute 'SET TRANSACTION READ ONLY'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if someone tries to select for update in this mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PG::ReadOnlySqlTransaction: ERROR: cannot execute SELECT FOR UPDATE in a read-only transaction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that behavior break certain code-paths?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool just wanted to ensure this covers locking in read statements also. I'm not aware of anything that would break.

Do you typically use this locally to manually verify your changes? If you run a couple commands that way and everything behaves properly I think that's enough code-path validation.

Copy link
Contributor Author

@timothysu timothysu Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I manually verify locally for in-house Salsify apps.

I could build out the feature tests here and have fancier rails fixtures, but it'd be extremely difficult to capture all the various use-cases that this should be catching. Would be a nice-to-have though.

Copy link

@cjf2xn cjf2xn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@timothysu timothysu merged commit d3e02f5 into master Sep 7, 2017
@timothysu timothysu deleted the feature/transaction-read-only branch September 8, 2017 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sandbox mode should make it clear that edits don't stick Writes made in sandbox mode take out DB locks
2 participants