-
Notifications
You must be signed in to change notification settings - Fork 1
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
Ignorable tables #141
Ignorable tables #141
Conversation
* Add option in the config to ignore some table entirely * Start checking in the functional tests that the produced ORM is as expected. This allows testing the above feature. * For this purpose, completely rework example_orm.py so that it is now the valid output of make-tables on src.dump. * Make make-tables run black on the outputted code. WIP because this commit does not pass mypy.
The tests pass for me locally. @Iain-S was this the same issue you already fixed in some other PR? |
Some tables can't be dropped from the ORM file, namely ones to which there is a foreign key referenc. We still want to be able to ignore those tables when creating generators, deleting and creating data, etc.
I ran into an issue where I some tables kept getting included in |
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.
All looks good to me. I've pushed a couple of minor changes straight to this branch.
metadata.reflect( | ||
engine, | ||
# The type-ignore is due to an erroneous type annotation in SQLAlchemy. | ||
only=reflect_if, # type: ignore | ||
) | ||
|
||
for table_name in metadata.tables.keys(): | ||
table_config = tables_config.get(table_name, {}) | ||
ignore = table_config.get("ignore", False) | ||
if ignore: | ||
logging.warning( | ||
"Table %s is supposed to be ignored but there is a foreign key " | ||
"reference to it. " | ||
"You may need to create this table manually at the dst schema before " | ||
"running create-tables.", | ||
table_name, | ||
) |
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.
Is it the case that, even after refect()
, metadata may still contain some of the ignored
tables (if they are referenced by a foreign key) so we need to check and warn?
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.
Yep, exactly that
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 was originally hoping that I wouldn't need to have the ignore
option anywhere else other than here: You leave it out of the orm.py, and it's automatically not involved in ssg.py or anywhere else. But because of this thing, if there are FK references to the ignored table it'll still be in the orm.py and then you have to check for it in all the other stages, like create-tables and make-generators.
Add option to ignore tables. In so doing, also rework example_orm.py.
Closes #139