-
Notifications
You must be signed in to change notification settings - Fork 22
docs: DB migration docs #222
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
203 changes: 203 additions & 0 deletions
203
alembic/versions/2022_10_13_0054-71b291295ae1_update_schema_types.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,203 @@ | ||
| """Update schema types | ||
|
|
||
| Revision ID: 71b291295ae1 | ||
| Revises: 37cd6f86330a | ||
| Create Date: 2022-10-13 00:54:24.422858+00:00 | ||
|
|
||
| """ | ||
| # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import, no-name-in-module | ||
|
|
||
| import sqlalchemy as sa | ||
| import sqlmodel | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "71b291295ae1" | ||
| down_revision = "37cd6f86330a" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_index("ix_column_dimension_column", table_name="column") | ||
| op.drop_index("ix_column_dimension_id", table_name="column") | ||
| op.drop_index("ix_column_id", table_name="column") | ||
| op.drop_index("ix_column_name", table_name="column") | ||
| op.alter_column( | ||
| "database", | ||
| "description", | ||
| existing_type=sa.VARCHAR(), | ||
| nullable=False, | ||
| ) | ||
| op.alter_column("database", "read_only", existing_type=sa.BOOLEAN(), nullable=False) | ||
| op.alter_column("database", "async", existing_type=sa.BOOLEAN(), nullable=False) | ||
| op.alter_column( | ||
| "database", | ||
| "cost", | ||
| existing_type=postgresql.DOUBLE_PRECISION(precision=53), | ||
| nullable=False, | ||
| ) | ||
| op.drop_index("ix_database_URI", table_name="database") | ||
| op.drop_index("ix_database_async", table_name="database") | ||
| op.drop_index("ix_database_cost", table_name="database") | ||
| op.drop_index("ix_database_description", table_name="database") | ||
| op.drop_index("ix_database_id", table_name="database") | ||
| op.drop_index("ix_database_read_only", table_name="database") | ||
| op.alter_column("node", "description", existing_type=sa.VARCHAR(), nullable=False) | ||
| op.drop_index("ix_node_description", table_name="node") | ||
| op.drop_index("ix_node_id", table_name="node") | ||
| op.drop_index("ix_node_query", table_name="node") | ||
| op.drop_index("ix_nodecolumns_column_id", table_name="nodecolumns") | ||
| op.drop_index("ix_nodecolumns_node_id", table_name="nodecolumns") | ||
| op.drop_index("ix_noderelationship_child_id", table_name="noderelationship") | ||
| op.drop_index("ix_noderelationship_parent_id", table_name="noderelationship") | ||
| op.alter_column("query", "state", existing_type=sa.VARCHAR(), nullable=False) | ||
| op.alter_column( | ||
| "query", | ||
| "progress", | ||
| existing_type=postgresql.DOUBLE_PRECISION(precision=53), | ||
| nullable=False, | ||
| ) | ||
| op.drop_index("ix_query_catalog", table_name="query") | ||
| op.drop_index("ix_query_database_id", table_name="query") | ||
| op.drop_index("ix_query_executed_query", table_name="query") | ||
| op.drop_index("ix_query_finished", table_name="query") | ||
| op.drop_index("ix_query_progress", table_name="query") | ||
| op.drop_index("ix_query_scheduled", table_name="query") | ||
| op.drop_index("ix_query_schema_", table_name="query") | ||
| op.drop_index("ix_query_started", table_name="query") | ||
| op.drop_index("ix_query_state", table_name="query") | ||
| op.drop_index("ix_query_submitted_query", table_name="query") | ||
| op.alter_column( | ||
| "table", | ||
| "cost", | ||
| existing_type=postgresql.DOUBLE_PRECISION(precision=53), | ||
| nullable=False, | ||
| ) | ||
| op.drop_index("ix_table_catalog", table_name="table") | ||
| op.drop_index("ix_table_cost", table_name="table") | ||
| op.drop_index("ix_table_database_id", table_name="table") | ||
| op.drop_index("ix_table_id", table_name="table") | ||
| op.drop_index("ix_table_node_id", table_name="table") | ||
| op.drop_index("ix_table_schema_", table_name="table") | ||
| op.drop_index("ix_table_table", table_name="table") | ||
| op.drop_index("ix_tablecolumns_column_id", table_name="tablecolumns") | ||
| op.drop_index("ix_tablecolumns_table_id", table_name="tablecolumns") | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_index( | ||
| "ix_tablecolumns_table_id", | ||
| "tablecolumns", | ||
| ["table_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| "ix_tablecolumns_column_id", | ||
| "tablecolumns", | ||
| ["column_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index("ix_table_table", "table", ["table"], unique=False) | ||
| op.create_index("ix_table_schema_", "table", ["schema_"], unique=False) | ||
| op.create_index("ix_table_node_id", "table", ["node_id"], unique=False) | ||
| op.create_index("ix_table_id", "table", ["id"], unique=False) | ||
| op.create_index("ix_table_database_id", "table", ["database_id"], unique=False) | ||
| op.create_index("ix_table_cost", "table", ["cost"], unique=False) | ||
| op.create_index("ix_table_catalog", "table", ["catalog"], unique=False) | ||
| op.alter_column( | ||
| "table", | ||
| "cost", | ||
| existing_type=postgresql.DOUBLE_PRECISION(precision=53), | ||
| nullable=True, | ||
| ) | ||
| op.create_index( | ||
| "ix_query_submitted_query", | ||
| "query", | ||
| ["submitted_query"], | ||
| unique=False, | ||
| ) | ||
| op.create_index("ix_query_state", "query", ["state"], unique=False) | ||
| op.create_index("ix_query_started", "query", ["started"], unique=False) | ||
| op.create_index("ix_query_schema_", "query", ["schema_"], unique=False) | ||
| op.create_index("ix_query_scheduled", "query", ["scheduled"], unique=False) | ||
| op.create_index("ix_query_progress", "query", ["progress"], unique=False) | ||
| op.create_index("ix_query_finished", "query", ["finished"], unique=False) | ||
| op.create_index( | ||
| "ix_query_executed_query", | ||
| "query", | ||
| ["executed_query"], | ||
| unique=False, | ||
| ) | ||
| op.create_index("ix_query_database_id", "query", ["database_id"], unique=False) | ||
| op.create_index("ix_query_catalog", "query", ["catalog"], unique=False) | ||
| op.alter_column( | ||
| "query", | ||
| "progress", | ||
| existing_type=postgresql.DOUBLE_PRECISION(precision=53), | ||
| nullable=True, | ||
| ) | ||
| op.alter_column("query", "state", existing_type=sa.VARCHAR(), nullable=True) | ||
| op.create_index( | ||
| "ix_noderelationship_parent_id", | ||
| "noderelationship", | ||
| ["parent_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| "ix_noderelationship_child_id", | ||
| "noderelationship", | ||
| ["child_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index("ix_nodecolumns_node_id", "nodecolumns", ["node_id"], unique=False) | ||
| op.create_index( | ||
| "ix_nodecolumns_column_id", | ||
| "nodecolumns", | ||
| ["column_id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index("ix_node_query", "node", ["query"], unique=False) | ||
| op.create_index("ix_node_id", "node", ["id"], unique=False) | ||
| op.create_index("ix_node_description", "node", ["description"], unique=False) | ||
| op.alter_column("node", "description", existing_type=sa.VARCHAR(), nullable=True) | ||
| op.create_index("ix_database_read_only", "database", ["read_only"], unique=False) | ||
| op.create_index("ix_database_id", "database", ["id"], unique=False) | ||
| op.create_index( | ||
| "ix_database_description", | ||
| "database", | ||
| ["description"], | ||
| unique=False, | ||
| ) | ||
| op.create_index("ix_database_cost", "database", ["cost"], unique=False) | ||
| op.create_index("ix_database_async", "database", ["async"], unique=False) | ||
| op.create_index("ix_database_URI", "database", ["URI"], unique=False) | ||
| op.alter_column( | ||
| "database", | ||
| "cost", | ||
| existing_type=postgresql.DOUBLE_PRECISION(precision=53), | ||
| nullable=True, | ||
| ) | ||
| op.alter_column("database", "async", existing_type=sa.BOOLEAN(), nullable=True) | ||
| op.alter_column("database", "read_only", existing_type=sa.BOOLEAN(), nullable=True) | ||
| op.alter_column( | ||
| "database", | ||
| "description", | ||
| existing_type=sa.VARCHAR(), | ||
| nullable=True, | ||
| ) | ||
| op.create_index("ix_column_name", "column", ["name"], unique=False) | ||
| op.create_index("ix_column_id", "column", ["id"], unique=False) | ||
| op.create_index("ix_column_dimension_id", "column", ["dimension_id"], unique=False) | ||
| op.create_index( | ||
| "ix_column_dimension_column", | ||
| "column", | ||
| ["dimension_column"], | ||
| unique=False, | ||
| ) | ||
| # ### end Alembic commands ### | ||
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.
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.
What's the goal of this update?
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 just ran
alembic revision --autogeneratewithout any changes to the model. All the changes you see here are because of the upgrade insqlmodel. This way, when we add a new migration (and I'm planning to because of #193) we'll see only relevant changes.