From 350f2d4706729f3ac58233e25a1380f31114ecc5 Mon Sep 17 00:00:00 2001 From: Dan Callaghan Date: Feb 23 2018 06:47:20 +0000 Subject: make waiver.subject column type JSONB The waiver.subject column was previously using the Postgres JSON column type, but this does not support indexing or equality comparison. Use the newer JSONB column type instead, which supports btree indexes and can be efficiently queried with equality comparisons. Also, the database migration which created the waiver.subject accidentally created the column as TEXT not JSON. This is handled in a new migration with `USING subject::jsonb` which causes Postgres to parse the column values into JSON when converting the column. Dropped the dependency on sqlalchemy-utils since we are no longer using it for anything. Fixes #129. --- diff --git a/requirements.txt b/requirements.txt index 7a19292..14951b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,6 @@ SQLAlchemy kerberos >= 1.1.1 flask-oidc systemd -sqlalchemy-utils # packages for the unit tests pytest >= 2.4.2 mock diff --git a/waiverdb.spec b/waiverdb.spec index 53de761..6ceb951 100644 --- a/waiverdb.spec +++ b/waiverdb.spec @@ -23,11 +23,6 @@ BuildRequires: python-sqlalchemy %endif BuildRequires: python2-flask-restful BuildRequires: python2-flask-sqlalchemy -%if 0%{?fedora} > 27 -BuildRequires: python2-sqlalchemy-utils -%else -BuildRequires: python-sqlalchemy-utils -%endif BuildRequires: python2-kerberos BuildRequires: python2-systemd BuildRequires: python2-pytest @@ -43,7 +38,6 @@ BuildRequires: python-flask BuildRequires: python-sqlalchemy BuildRequires: python-flask-restful BuildRequires: python-flask-sqlalchemy -BuildRequires: python-sqlalchemy-utils BuildRequires: python-kerberos BuildRequires: systemd-python BuildRequires: pytest @@ -67,11 +61,6 @@ Requires: python-sqlalchemy %endif Requires: python2-flask-restful Requires: python2-flask-sqlalchemy -%if 0%{?fedora} > 27 -Requires: python2-sqlalchemy-utils -%else -Requires: python-sqlalchemy-utils -%endif Requires: python2-kerberos Requires: python2-systemd Requires: python2-mock diff --git a/waiverdb/migrations/versions/1797bff52162_change_subject_to_jsonb.py b/waiverdb/migrations/versions/1797bff52162_change_subject_to_jsonb.py new file mode 100644 index 0000000..1b9050e --- /dev/null +++ b/waiverdb/migrations/versions/1797bff52162_change_subject_to_jsonb.py @@ -0,0 +1,23 @@ +"""Change waiver.subject column type to JSONB + +Revision ID: 1797bff52162 +Revises: ed43eb9b221c +Create Date: 2018-02-23 16:37:44.190560 + +""" + +# revision identifiers, used by Alembic. +revision = '1797bff52162' +down_revision = 'ed43eb9b221c' + +from alembic import op +from sqlalchemy import Text +from sqlalchemy.dialects.postgresql import JSONB + + +def upgrade(): + op.alter_column('waiver', 'subject', type_=JSONB, postgresql_using='subject::jsonb') + + +def downgrade(): + op.alter_column('waiver', 'subject', type_=Text) diff --git a/waiverdb/models/waivers.py b/waiverdb/models/waivers.py index 094994f..e6c459c 100644 --- a/waiverdb/models/waivers.py +++ b/waiverdb/models/waivers.py @@ -3,13 +3,13 @@ import datetime from .base import db from sqlalchemy import or_, and_ -from sqlalchemy_utils import JSONType +from sqlalchemy.dialects.postgresql import JSONB class Waiver(db.Model): id = db.Column(db.Integer, primary_key=True) result_id = db.Column(db.Integer, nullable=True) - subject = db.Column(JSONType, nullable=False, index=True) + subject = db.Column(JSONB, nullable=False, index=True) testcase = db.Column(db.Text, nullable=False, index=True) username = db.Column(db.String(255), nullable=False) proxied_by = db.Column(db.String(255))