-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add ability to handle explicit schema name. #70
base: master
Are you sure you want to change the base?
Add ability to handle explicit schema name. #70
Conversation
This PR also takes a crack at fixing Travis-CI configuration to start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR !
eralchemy/sqla.py
Outdated
# as another parameter into this function from metadata_to_intermediary() | ||
left_column = format_name(fk._column_tokens[1]) | ||
if fk._column_tokens[0]: | ||
left_column = "{}.{}".format(format_name(fk._column_tokens[0]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I require a test of this fix preferably in in integration with a real postgresql
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amended existing schema test to assert that column names match full table names.
Hope that is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need automated testing for this feature possibly in integration with a real Postgres.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current test uses the local instance of a postgres database named test
and created inside .travis.yml
. Is that not enough?
Didn't saw it.
Where is the assertion showing the issue #67 is fixed?
Le jeu. 9 janv. 2020 à 18:20, psipika <notifications@github.com> a écrit :
… ***@***.**** commented on this pull request.
------------------------------
In eralchemy/sqla.py
<#70 (comment)>
:
> @@ -13,9 +13,20 @@
def relation_to_intermediary(fk):
"""Transform an SQLAlchemy ForeignKey object to it's intermediary representation. """
+
+ # In the cases where schema name is provided, _column_tokens[1] is
+ # insufficient to correctly identify the relationship. Therefore, assuming
+ # that the schema name is _column_tokens[0], when set seems the least
+ # intrusive approach. The other one would be sending in the schema name
+ # as another parameter into this function from metadata_to_intermediary()
+ left_column = format_name(fk._column_tokens[1])
+ if fk._column_tokens[0]:
+ left_column = "{}.{}".format(format_name(fk._column_tokens[0]),
The current test uses the local instance of a postgres database (named
test and created inside .travis.yml
<https://github.com/Alexis-benoist/eralchemy/blob/master/.travis.yml#L14-L15>.
Is that not enough?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#70?email_source=notifications&email_token=ABB3JJYB6TZOQIOCBEG7XGLQ45MELA5CNFSM4KBXTM62YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCRHHK2Y#discussion_r364864338>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABB3JJ5RFNT2AZQRD3ZH74TQ45MELANCNFSM4KBXTM6Q>
.
|
Here: tables, relationships = database_to_intermediary(db_uri, schema='test')
table_names = [t.name for t in tables]
....
# Assert column names match table names, including schema
assert all(r.right_col in table_names for r in relationships)
assert all(r.left_col in table_names for r in relationships) Basically, the table names returned from the function call are in the form |
@@ -74,6 +75,9 @@ def test_database_to_intermediary_with_schema(): | |||
# Not in because different schema. | |||
assert relation not in relationships | |||
assert exclude_relation not in relationships | |||
# Assert column names match table names, including schema | |||
assert all(r.right_col in table_names for r in relationships) | |||
assert all(r.left_col in table_names for r in relationships) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extract this part to another test and make the assertion show the "{}.{}" formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, separated out and checking explicitly for presence/lack of schema name in the relationship column names. Thanks for taking the time to review my updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we do a set expected_names
like and assert it's equal to the result?
Ping @Alexis-benoist -- is there anything else I can address to move this forward? |
@psipika Thank you for this, I hope it gets merged. Just a heads up that for my case, I needed to change relation_to_intermediary(fk, metadata.schema or table.schema) My base is a DeclarativeMeta, and I defined schemas as the table level, e.g.: class Foo(Base):
__tablename__ = 'foo'
__table_args__ = {"schema": "bar"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay.
@@ -74,6 +75,9 @@ def test_database_to_intermediary_with_schema(): | |||
# Not in because different schema. | |||
assert relation not in relationships | |||
assert exclude_relation not in relationships | |||
# Assert column names match table names, including schema | |||
assert all(r.right_col in table_names for r in relationships) | |||
assert all(r.left_col in table_names for r in relationships) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we do a set expected_names
like and assert it's equal to the result?
assert all(r.right_col in table_names for r in relationships) | ||
assert all(r.left_col in table_names for r in relationships) | ||
|
||
# Assert column names match table names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark as below + code is duplicated.
The same problem exist also when the schema is not defined. |
When invoking
render_er
with a schema name, like:The resulting image is missing the proper relationships. As mentioned in issue #67, the problem is that the
left_col
argument toRelation
is missing the name of the schema. This PR aims to address the problem using the [subjectively] least intrusive means.Closes #67