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

Handle leading spaces in the SQL #72

Merged
merged 2 commits into from
Feb 7, 2015
Merged

Handle leading spaces in the SQL #72

merged 2 commits into from
Feb 7, 2015

Conversation

kdonovan
Copy link

@kdonovan kdonovan commented Feb 6, 2015

In our project (postgres) the needs_master? method and friends were being passing SQL with leading spaces, which didn't match the regex and so all queries ended up being routed to master.

SQL_SLAVE_MATCHERS = [/^select\s/i].map(&:freeze).freeze
SQL_ALL_MATCHERS = [/^set\s/i].map(&:freeze).freeze
SQL_SKIP_STICKINESS_MATCHERS = [/^show\s([\w]+\s)?(field|table|database|schema|view|index)(es|s)?/i, /^(set|describe|explain|pragma)\s/i].map(&:freeze).freeze
SQL_MASTER_MATCHERS = [/^\s*select.+for update$/i, /select.+lock in share mode$/i].map(&:freeze).freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a second regex here which should have the same matcher.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! One second...

@mnelson
Copy link
Contributor

mnelson commented Feb 6, 2015

I'm pretty sure the failure on travis is due to a new rack version if you want to update the httponly bit as well. Looks good after that.

@kdonovan
Copy link
Author

kdonovan commented Feb 6, 2015

I tweaked the spec file to expect the HttpOnly, but now Travis is giving errors "Gem::InstallError: pg requires Ruby version >= 1.9.3.". I didn't tweak the gemfile at all, so I'm not sure what's going on with that... both that and the spec issue seem outside the scope of the changes I made. :/

@mnelson
Copy link
Contributor

mnelson commented Feb 7, 2015

I'll take a look tomorrow.

mnelson added a commit that referenced this pull request Feb 7, 2015
@mnelson mnelson merged commit 9dda370 into instacart:master Feb 7, 2015
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.

2 participants