Skip to content
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

warehouse/migrations: add missing migrations for organizations #11238

Closed
wants to merge 1 commit into from

Conversation

woodruffw
Copy link
Member

Was crufting up another migration.

@woodruffw woodruffw requested a review from di April 22, 2022 22:09
@woodruffw woodruffw self-assigned this Apr 22, 2022
@di di added the blocked Issues we can't or shouldn't get to yet label Apr 22, 2022
@di
Copy link
Member

di commented Apr 22, 2022

Putting the 'blocked' label on this until we can review, probably don't want to merge this as-is.

@woodruffw
Copy link
Member Author

Just for my own edification: these probably originate from #11184, right?

@di
Copy link
Member

di commented Apr 23, 2022

Looks like there is some of #8324 in there as well. We probably need a CI check that ensures that no migrations would be autogenerated...

@di di force-pushed the tob-missing-migration branch from 0e3e449 to 0a7cd33 Compare April 25, 2022 22:27
@di di removed blocked Issues we can't or shouldn't get to yet labels Apr 25, 2022
@di
Copy link
Member

di commented Apr 25, 2022

This is now just changes that resulted from the organization-related work.

@divbzero @sterbo could you take a look and make sure these are as intended? See also https://warehouse.pypa.io/development/database-migrations.html regarding autogenerating migrations when changing models.

1 similar comment
@di
Copy link
Member

di commented Apr 25, 2022

This is now just changes that resulted from the organization-related work.

@divbzero @sterbo could you take a look and make sure these are as intended? See also https://warehouse.pypa.io/development/database-migrations.html regarding autogenerating migrations when changing models.

@di di force-pushed the tob-missing-migration branch from 160bee7 to 2910326 Compare April 25, 2022 22:39
@di di assigned divbzero and sterbo and unassigned woodruffw Apr 25, 2022
@divbzero
Copy link
Contributor

Ugh I was the last one to merge and test migrations for #11184.

Are these the right steps for testing migrations?

  1. git checkout upstream/main
  2. make initdb
  3. git rebase -i @ foo-feature-branch or something similar to get feature branch up-to-date
  4. docker-compose run web python -m warehouse db upgrade head

I thought I had done that but must have missed something.

@divbzero
Copy link
Contributor

@divbzero
Copy link
Contributor

I think I see what happened. We manually added server_default=sa.sql.false() to the migration script to reflect the SQLAlchemy model:
https://github.com/pypa/warehouse/blob/354f24d890c88a070973810905523050e8550cb3/warehouse/organizations/models.py#L155

But Alembic doesn’t translate default=False to server_default=... when autogenerating so it’s flagging the is_active column as not-in-sync.

@sterbo I recall you mentioned something about this in a discussion. What’s the right move here? Could we give up on having BOOLEAN DEFAULT FALSE being enforced at the database level?

@sterbo
Copy link
Contributor

sterbo commented Apr 26, 2022

I think I see what happened. We manually added server_default=sa.sql.false() to the migration script to reflect the SQLAlchemy model:

https://github.com/pypa/warehouse/blob/354f24d890c88a070973810905523050e8550cb3/warehouse/organizations/models.py#L155

But Alembic doesn’t translate default=False to server_default=... when autogenerating so it’s flagging the is_active column as not-in-sync.

@sterbo I recall you mentioned something about this in a discussion. What’s the right move here? Could we give up on having BOOLEAN DEFAULT FALSE being enforced at the database level?

I'm fine with not enforcing this at the database level. Banners and sponsors are configured in a similar fashion.

@di
Copy link
Member

di commented Apr 26, 2022

Are these the right steps for testing migrations?

You probably also want to try to autogenerate a migration whenever models have been changed with docker-compose run web python -m warehouse db revision --autogenerate --message "text"

But Alembic doesn’t translate default=False to server_default=... when autogenerating so it’s flagging the is_active column as not-in-sync.

I think you probably want to set server_default=sql.false() instead of default=False on the is_active column for these models, which would make this migration a no-op.

@sterbo
Copy link
Contributor

sterbo commented Apr 26, 2022

I think you probably want to set server_default=sql.false() instead of default=False on the is_active column for these models, which would make this migration a no-op.

it looks like that'll do the trick. we'll give that a whirl. thanks @di

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants