-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing indexes and mark aliases as created by partner (#2058)
* Add missing indexes and mark aliases as created by partner * Configure if we should skip the partner aliases or not
- Loading branch information
Showing
5 changed files
with
98 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""empty message | ||
Revision ID: 52510a633d6f | ||
Revises: 818b0a956205 | ||
Create Date: 2024-03-12 12:46:24.161644 | ||
""" | ||
import sqlalchemy_utils | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "52510a633d6f" | ||
down_revision = "818b0a956205" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"alias", sa.Column("flags", sa.BigInteger(), server_default="0", nullable=False) | ||
) | ||
with op.get_context().autocommit_block(): | ||
op.create_index(op.f("ix_alias_flags"), "alias", ["flags"], unique=False) | ||
op.create_index(op.f("ix_job_state"), "job", ["state"], unique=False) | ||
op.create_index( | ||
"ix_state_run_at_taken_at", | ||
"job", | ||
["state", "run_at", "taken_at"], | ||
unique=False, | ||
) | ||
op.create_index( | ||
op.f("ix_notification_user_id"), "notification", ["user_id"], unique=False | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.get_context().autocommit_block(): | ||
op.drop_index(op.f("ix_notification_user_id"), table_name="notification") | ||
op.drop_index("ix_state_run_at_taken_at", table_name="job") | ||
op.drop_index(op.f("ix_job_state"), table_name="job") | ||
op.drop_index(op.f("ix_alias_flags"), table_name="alias") | ||
op.drop_column("alias", "flags") | ||
# ### end Alembic commands ### |
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,29 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
|
||
|
||
from app.log import LOG | ||
from app.models import Alias, SLDomain | ||
from app.db import Session | ||
|
||
parser = argparse.ArgumentParser( | ||
prog="Mark partner created aliases with the PARTNER_CREATED flag", | ||
) | ||
args = parser.parse_args() | ||
|
||
domains = SLDomain.filter(SLDomain.partner_id.isnot(None)).all() | ||
|
||
for domain in domains: | ||
LOG.i(f"Checking aliases for domain {domain.domain}") | ||
for alias in ( | ||
Alias.filter( | ||
Alias.email.like(f"%{domain.domain}"), | ||
Alias.flags.op("&")(Alias.FLAG_PARTNER_CREATED) == 0, | ||
) | ||
.enable_eagerloads(False) | ||
.yield_per(100) | ||
.all() | ||
): | ||
alias.flags = alias.flags | Alias.FLAG_PARTNER_CREATED | ||
LOG.i(f" * Updating {alias.email} to {alias.flags}") | ||
Session.commit() |