-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for default notification rules
Rules with NULL id_role are used if there are no rules for current user.
- Loading branch information
Showing
8 changed files
with
223 additions
and
151 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
59 changes: 59 additions & 0 deletions
59
backend/geonature/migrations/versions/09a637f06b96_default_notification_rules.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,59 @@ | ||
"""Default notification rules | ||
Revision ID: 09a637f06b96 | ||
Revises: 4cf3fd5d06f5 | ||
Create Date: 2023-01-13 09:55:53.525869 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "09a637f06b96" | ||
down_revision = "4cf3fd5d06f5" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# Allows NULL id_role to define default rules | ||
op.alter_column( | ||
schema="gn_notifications", | ||
table_name="t_notifications_rules", | ||
column_name="id_role", | ||
nullable=True, | ||
) | ||
# Create partial index on (code_method, code_category) where id_role IS NULL. | ||
# This allows to create only one default rule for each method / category couple. | ||
op.create_index( | ||
schema="gn_notifications", | ||
table_name="t_notifications_rules", | ||
index_name="un_method_category", | ||
columns=["code_method", "code_category"], | ||
postgresql_where=sa.text("id_role IS NULL"), | ||
) | ||
op.add_column( | ||
schema="gn_notifications", | ||
table_name="t_notifications_rules", | ||
column=sa.Column("subscribed", sa.Boolean, nullable=False, server_default=sa.true()), | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column( | ||
schema="gn_notifications", | ||
table_name="t_notifications_rules", | ||
column_name="subscribed", | ||
) | ||
op.drop_index( | ||
schema="gn_notifications", | ||
table_name="t_notifications_rules", | ||
index_name="un_method_category", | ||
) | ||
op.alter_column( | ||
schema="gn_notifications", | ||
table_name="t_notifications_rules", | ||
column_name="id_role", | ||
nullable=False, | ||
) |
Oops, something went wrong.