-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: adding demoted, migration, API change for upcoming event #7589
Conversation
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('events', sa.Column('is_demoted', sa.Boolean(), nullable=False)) |
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.
Where is server_default?
This migration will fail. Please test the changes carefully
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 migration will fail. Please test the changes carefully
But I have tested it with frontend, it's working. did server_default is not added itself in autogenerated migration?
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.
No
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('events', sa.Column('is_demoted', sa.Boolean(), nullable=False)) | ||
op.add_column('events_version', sa.Column('is_demoted', sa.Boolean(), autoincrement=False, nullable=True)) | ||
op.execute("UPDATE events SET is_demoted=False") |
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 won't work, the first command itself will fail
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('events_version', 'is_demoted') | ||
op.drop_column('events', 'is_demoted') | ||
op.execute("UPDATE events SET is_demoted=True") |
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.
If you drop the column is_demoted, how can you set it to True? And even if you could, would you make all events demoted? Now, no event is being shown on frontend, WOW
Please be careful and think about these things :/
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 thought about it. But you have said before once that downgrade should be opposite of upgrade 😕
Codecov Report
@@ Coverage Diff @@
## development #7589 +/- ##
============================================
Coverage 67.20% 67.20%
============================================
Files 271 271
Lines 13732 13734 +2
============================================
+ Hits 9228 9230 +2
Misses 4504 4504
Continue to review full report at Codecov.
|
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('events', sa.Column('is_demoted', sa.Boolean(), nullable=False, server_default=False)) |
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.
op.add_column('events', sa.Column('is_demoted', sa.Boolean(), nullable=False, server_default=False)) | |
op.add_column('events', sa.Column('is_demoted', sa.Boolean(), nullable=False, server_default='False')) |
server_default needs to be quoted
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('events', sa.Column('is_demoted', sa.Boolean(), nullable=False, server_default=False)) | ||
op.add_column('events_version', sa.Column('is_demoted', sa.Boolean(), autoincrement=False, nullable=True, server_default=False)) | ||
op.execute("UPDATE events SET is_demoted=False") |
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.
op.execute("UPDATE events SET is_demoted=False") |
Handled by server default
Then sorry, correct definition is downgrade should restore the DB structure and state to where it was before migration. So, you drop the column, it is already restored Secondly, let's say you set default demoted to false, it makes sense, would you restore demoted to true on downgrade? It doesn't make sense, it'll make all events demoted. All events were never demoted, so demoted was never = true, so it is not restoring to correct state In case of making custom forms public Original State: Migration: Loss of state Correct Migration: Downgrade: Data Loss Thus, only make those fields private which you made public to restore to the original state. Make speaker fields x, y, z private Development is not just taking an idea that you heard previously and applying it without thought. |
Fixes fossasia/open-event-frontend#4963
continuing #7588
Checklist
development
branch.