-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/mcrypt_to_ccrypt
- Loading branch information
Showing
13 changed files
with
355 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
36 changes: 36 additions & 0 deletions
36
migrations/versions/3a5712474808_make_user_active_field_non_nullable.py
This file contains 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,36 @@ | ||
"""Make User.active field non nullable | ||
Revision ID: 3a5712474808 | ||
Revises: 9b3a5a7145d7 | ||
Create Date: 2024-11-08 22:00:41.161934 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from userdatamodel.models import User | ||
from sqlalchemy.orm import Session | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "3a5712474808" # pragma: allowlist secret | ||
down_revision = "9b3a5a7145d7" # pragma: allowlist secret | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
conn = op.get_bind() | ||
session = Session(bind=conn) | ||
session.query(User) | ||
active_users_count = session.query(User).filter(User.active.is_(True)).count() | ||
if active_users_count > 0: | ||
# if we have at least one user where "active" is explicitly set to "True", then we'll assume NULL is to mean "False": | ||
op.execute('UPDATE "User" SET active = False WHERE active IS NULL') | ||
else: | ||
# else, we assume NULL means "True" | ||
op.execute('UPDATE "User" SET active = True WHERE active IS NULL') | ||
op.alter_column("User", "active", nullable=False, server_default="True") | ||
|
||
|
||
def downgrade(): | ||
op.alter_column("User", "active", nullable=True, server_default=None) |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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.