]> git.lizzy.rs Git - cheatdb.git/commitdiff
Add constraint for release tasks and approval
authorrubenwardy <rw@rubenwardy.com>
Sat, 18 Jan 2020 23:10:11 +0000 (23:10 +0000)
committerrubenwardy <rw@rubenwardy.com>
Sat, 18 Jan 2020 23:10:11 +0000 (23:10 +0000)
app/models.py
migrations/versions/306ce331a2a7_.py [new file with mode: 0644]
utils/bash.sh [new file with mode: 0755]

index cd7a88ad4234f121014698f02bf67e2e1e3f297c..3752363cacc729bd5083bf9edba2b9d2059fed1a 100644 (file)
@@ -732,6 +732,8 @@ class PackageRelease(db.Model):
        max_rel_id = db.Column(db.Integer, db.ForeignKey("minetest_release.id"), nullable=True, server_default=None)
        max_rel    = db.relationship("MinetestRelease", foreign_keys=[max_rel_id])
 
+       # If the release is approved, then the task_id must be null and the url must be present
+       CK_approval_valid = db.CheckConstraint("not approved OR (task_id IS NULL AND (url = '') IS NOT FALSE)")
 
        def getEditURL(self):
                return url_for("packages.edit_release",
diff --git a/migrations/versions/306ce331a2a7_.py b/migrations/versions/306ce331a2a7_.py
new file mode 100644 (file)
index 0000000..7e7c0ce
--- /dev/null
@@ -0,0 +1,26 @@
+"""empty message
+
+Revision ID: 306ce331a2a7
+Revises: 6dca6eceb04d
+Create Date: 2020-01-18 23:00:40.487425
+
+"""
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects import postgresql
+
+# revision identifiers, used by Alembic.
+revision = '306ce331a2a7'
+down_revision = '6dca6eceb04d'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+       conn = op.get_bind()
+       op.create_check_constraint("CK_approval_valid", "package_release", "not approved OR (task_id IS NULL AND NOT url = '')")
+
+
+def downgrade():
+       conn = op.get_bind()
+       op.drop_constraint("CK_approval_valid", "package_release", type_="check")
diff --git a/utils/bash.sh b/utils/bash.sh
new file mode 100755 (executable)
index 0000000..f75fc41
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+docker exec -it contentdb_app_1 bash