mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-05 12:47:29 +01:00
Add check constraint on MetaPackage name
This commit is contained in:
parent
284683e7e5
commit
4bd9411d87
@ -758,6 +758,8 @@ class MetaPackage(db.Model):
|
|||||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||||
dependencies = db.relationship("Dependency", backref="meta_package", lazy="dynamic")
|
dependencies = db.relationship("Dependency", backref="meta_package", lazy="dynamic")
|
||||||
|
|
||||||
|
mp_name_valid = db.CheckConstraint("name ~* '^[a-z0-9_]+$'")
|
||||||
|
|
||||||
def __init__(self, name=None):
|
def __init__(self, name=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
30
migrations/versions/838081950f27_.py
Normal file
30
migrations/versions/838081950f27_.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 838081950f27
|
||||||
|
Revises: 86512692b770
|
||||||
|
Create Date: 2020-07-12 01:33:19.499459
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '838081950f27'
|
||||||
|
down_revision = '86512692b770'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_check_constraint("mp_name_valid", "meta_package", "name ~* '^[a-z0-9_]+$'")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
DELETE FROM provides AS t USING meta_package AS m WHERE t.metapackage_id = m.id AND NOT (m.name ~* '^[a-z0-9_]+$');
|
||||||
|
DELETE FROM dependency AS t USING meta_package AS m WHERE t.meta_package_id = m.id AND NOT (m.name ~* '^[a-z0-9_]+$');
|
||||||
|
DELETE FROM meta_package WHERE NOT (name ~* '^[a-z0-9_]+$');
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_constraint("mp_name_valid", "meta_package", type_="check")
|
Loading…
Reference in New Issue
Block a user