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

Add migration to add user_group.roles column #9030

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions h/migrations/versions/1975edef158d_add_user_group_roles_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Add the user_group.roles column."""

from alembic import op
from sqlalchemy import CheckConstraint, Column, text
from sqlalchemy.dialects.postgresql import JSONB

revision = "1975edef158d"
down_revision = "146179fa8d5e"


def upgrade():
op.add_column(
"user_group",
Column(
"roles",
JSONB,
CheckConstraint(
" OR ".join(
f"""(roles = '["{role}"]'::jsonb)"""
for role in ["member", "moderator", "admin", "owner"]
),
name="validate_role_strings",
),
server_default=text("""'["member"]'::jsonb"""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullable=False,
),
)


def downgrade():
op.drop_column("user_group", "roles")
Loading