Skip to content

Conversation

@substars
Copy link
Contributor

We're using oracle-enhanced with schema: parameter set, so current_schema is different than the current user, which causes PL/SQL not to find available packages. current_schema should (?) be the same as session_user unless explicitly set otherwise, in which case we should use that.

I'm happy to write a specific test for this, but it'll make setup more complex since we'll need to create another user, do some grants, etc. Thoughts?

@jgebal
Copy link
Contributor

jgebal commented Jan 15, 2016

I used alter session set current_schema a lot at my previous project as we were using multi-schema deployments on single dev instance to avoid stepping on each other's toes when developing. So each developer/feature had his schema to play with.
Seems like a good idea to vs able to mimic this in ruby-postal.

@jgebal
Copy link
Contributor

jgebal commented Jan 15, 2016

From what I remember. We were using
schema: schema_name in the database.html so all tests could run in a specified context per connection.

@jgebal
Copy link
Contributor

jgebal commented Jan 15, 2016

This change looks good.
We could add setter method for schema name too.

@javornikolov
Copy link
Collaborator

Looks good to me. It may happen that in some contexts the session user would be needed, while in others - current schema.

I'm happy to write a specific test for this, but it'll make setup more complex since we'll need to create another user, do some grants, etc. Thoughts?

It's good to have tests. I think we already have 2 test schema hr and arunit - would these be enough? It's not a huge problem to setup more users if needed.

@substars
Copy link
Contributor Author

You're right, no reason not to write tests. Done!

Copy link
Collaborator

Choose a reason for hiding this comment

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

That got me thinking about an edge case - what if we connect through proxy user? (I'm not sure whether the other tests would be compatible with such scenario either).

Copy link
Collaborator

Choose a reason for hiding this comment

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

That got me thinking about an edge case - what if we connect through proxy user? (I'm not sure whether the other tests would be compatible with such scenario either).

Looks like the other tests already expect the username used to connect to match session user:
schema_spec.rb#L37.

So I think it's OK to rely on this assumption for now. We may think of how to address proxy user connections some other time in future.

@substars
Copy link
Contributor Author

Thanks for your feedback @javornikolo, I updated tests to be more descriptive (hopefully!).

Regarding proxy users and a setter for schema_name: the specs frequently reset connections just for the side effect of clearing cached metadata, which was confusing to me. oracle-enhanced sets current_schema right away on new connections so it is a relatively simple use case, but edge cases like those might also be easier to implement if the PLSQL::Schema API was more transparent about what it is caching (and how and when to reset it).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if would be better to have after(:all) close to the relevant before block (it feels a bit easier to see what we need to tear down).

@javornikolov
Copy link
Collaborator

Good spot about the caching... It may be cleaner to add a schema_name setter which takes care about purging the cached stuff. And still - looks like we're still in trouble when current_schema is changed by a database call, resetting the cache via connection= seems quite odd. I think we should add a public method for purging the cache; and maybe ability to turn on/off the caching.

@substars
Copy link
Contributor Author

I agree that that's the way to go, but I think it's a separate issue and deserves its own PR. This is a surgical fix to get the gem working like I'd expect with oracle-enhanced 1.6, messing with caching is more tricky.

Re: the after block, you're right that this project usually has after adjacent to before so I changed mine to match. :octocat:

@javornikolov
Copy link
Collaborator

Cool, it looks good enough to me now :-) I agree - the other intricacies can be handled in separate PR.
So I'm merging this PR :shipit:

@substars, thank you very much for this contribution!

javornikolov added a commit that referenced this pull request Jan 19, 2016
use current_schema in PLSQL::Schema#schema_name
@javornikolov javornikolov merged commit 8c4ff29 into rsim:master Jan 19, 2016
@javornikolov javornikolov modified the milestone: 0.6.0 Mar 13, 2016
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.

3 participants