Browse Source

Make the token_id column of the commit_flags table nullable

We need this as flags set from the CI integration do not use tokens
and thus can't provide one.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Pierre-Yves Chibon 3 years ago
parent
commit
1815160207

+ 33 - 0
alembic/versions/c0bffa4e8fbc_token_if_in_commit_flag_can_be_null.py

@@ -0,0 +1,33 @@
+"""token_if in commit flag can be null
+
+Revision ID: c0bffa4e8fbc
+Revises: 2b39a728a38f
+Create Date: 2021-01-08 11:12:45.380762
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'c0bffa4e8fbc'
+down_revision = '2b39a728a38f'
+
+
+def upgrade():
+    op.alter_column(
+        'commit_flags',
+        column_name='token_id',
+        nullable=False,
+        existing_nullable=True
+    )
+
+
+def downgrade():
+    op.alter_column(
+        'commit_flags',
+        column_name='token_id',
+        nullable=True,
+        existing_nullable=False
+    )

+ 3 - 1
pagure/lib/model.py

@@ -2552,7 +2552,9 @@ class CommitFlag(BASE):
         index=True,
     )
     token_id = sa.Column(
-        sa.String(64), sa.ForeignKey("tokens.id"), nullable=False
+        sa.String(64),
+        sa.ForeignKey("tokens.id", ondelete="CASCADE", onupdate="CASCADE"),
+        nullable=True,
     )
     user_id = sa.Column(
         sa.Integer,