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

table unqiueness constraints on assignmentid, and workerid #450

Open
jacob-lee opened this issue Oct 26, 2020 · 1 comment
Open

table unqiueness constraints on assignmentid, and workerid #450

jacob-lee opened this issue Oct 26, 2020 · 1 comment

Comments

@jacob-lee
Copy link
Collaborator

In the Participant table, we have uniqueid as the primary key, but this in practice seems to be the combination: uniqueid == [assignmentid]:[workerid].

Technically, we don't need uniqueid, because the combination of assignmentid and workerid implicitly define a composite primary key. But, since we aren't ever updating any of those three columns it isn't that big a deal to have that functional dependency/redundancy.

Still, it seems like we should specify a joint uniqueness constraint on those two columns.

class Participant(Base):
    """
    Object representation of a participant in the database.
    """
    __tablename__ = TABLENAME

    uniqueid = Column(String(128), primary_key=True)
    assignmentid = Column(String(128), nullable=False)
    workerid = Column(String(128), nullable=False)
    hitid = Column(String(128), nullable=False)
    ...
class Participant(Base):
    """
    Object representation of a participant in the database.
    """
    __tablename__ = TABLENAME
    __table_args__ = (
        sqlalchemy.schema.UniqueConstraint(
            'assignmentid', 'workerid', name='worker_assignment_unique_constraint')
    )

    uniqueid = Column(String(128), primary_key=True)
    assignmentid = Column(String(128), nullable=False)
    workerid = Column(String(128), nullable=False)
    hitid = Column(String(128), nullable=False)
    ...

Any reason not to?

@deargle
Copy link
Collaborator

deargle commented Oct 26, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants