-
Notifications
You must be signed in to change notification settings - Fork 0
Add tables/ORM classes for streamflow orders and results #73
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
Open
rod-glover
wants to merge
5
commits into
master
Choose a base branch
from
i72-add-streaflow-orders-results
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9fe2fce
Define streamflow orders and results in ORM
rod-glover 4f850e2
Add __str__ methods; export streamflow classes
rod-glover 6570f3c
Add basic tests of streamflow order-result; fix ORM issues revealed
rod-glover ac42146
Add some test databases to alembic.ini
rod-glover 58e72c9
Add migration
rod-glover File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
alembic/versions/c0810e121564_add_streamflow_order_and_results_tables.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """Add streamflow order and results tables | ||
|
|
||
| Revision ID: c0810e121564 | ||
| Revises: 12f290b63791 | ||
| Create Date: 2018-09-05 11:41:58.245456 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'c0810e121564' | ||
| down_revision = '12f290b63791' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.create_table('streamflow_results', | ||
| sa.Column('streamflow_result_id', sa.Integer(), nullable=False), | ||
| sa.Column('data_file_id', sa.Integer(), nullable=True), | ||
| sa.Column('station_id', sa.Integer(), nullable=True), | ||
| sa.Column('status', sa.Enum('queued', 'processing', 'error', 'cancelled', 'ready', 'removed', name='streamflow_result_statuses'), nullable=False), | ||
| sa.ForeignKeyConstraint(['data_file_id'], ['data_files.data_file_id'], ), | ||
| sa.ForeignKeyConstraint(['station_id'], ['stations.station_id'], ), | ||
| sa.PrimaryKeyConstraint('streamflow_result_id') | ||
| ) | ||
|
|
||
| op.create_table('streamflow_orders', | ||
| sa.Column('streamflow_order_id', sa.Integer(), nullable=False), | ||
| sa.Column('hydromodel_output_id', sa.Integer(), nullable=False), | ||
| sa.Column('streamflow_result_id', sa.Integer(), nullable=False), | ||
| sa.Column('longitude', sa.Float(), nullable=False), | ||
| sa.Column('latitude', sa.Float(), nullable=False), | ||
| sa.Column('notification_method', sa.Enum('none', 'email', name='notification_methods'), nullable=False), | ||
| sa.Column('notification_address', sa.String(length=255), nullable=True), | ||
| sa.Column('status', sa.Enum('accepted', 'fulfilled', 'cancelled', 'error', name='streamflow_order_statuses'), nullable=False), | ||
| sa.ForeignKeyConstraint(['hydromodel_output_id'], ['data_files.data_file_id'], ), | ||
| sa.ForeignKeyConstraint(['streamflow_result_id'], ['streamflow_results.streamflow_result_id'], ), | ||
| sa.PrimaryKeyConstraint('streamflow_order_id') | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_table('streamflow_orders') | ||
| op.drop_table('streamflow_results') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This downgrade does not cleanly remove the upgrade, because it does not delete the
streamflow_order_statusestype. While it's unlikely to be something we need to do, we can't run the upgrade, run the downgrade, and then run the upgrade again without this error message:Is it possible to delete the type? DROP TYPE or something?
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.
https://www.postgresql.org/docs/9.5/static/sql-droptype.html ?
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.
Good catch, @corviday !
Hmm. According to SQLAlchemy docs, "The
table.drop()call will now emit a DROP TYPE for a table-level enumerated type."Several things are possible here:
table.drop()-- hard to imagine that, but...