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

Add unique constraints to audit tables for extra safety #12

Open
cancan101 opened this issue Apr 3, 2015 · 1 comment
Open

Add unique constraints to audit tables for extra safety #12

cancan101 opened this issue Apr 3, 2015 · 1 comment

Comments

@cancan101
Copy link

CREATE_NON_LINKED_TABLE = 'CREATE TABLE %s (id INTEGER PRIMARY KEY AUTOINCREMENT, original, cleaned, UNIQUE(original))'
CREATE_LINKED_TABLE = 'CREATE TABLE %s (id INTEGER PRIMARY KEY AUTOINCREMENT, original, cleaned, study INTEGER, UNIQUE(original, study), FOREIGN KEY(study) REFERENCES studyinstanceuid(id))'

and then:

def audit_save(tag, cleaned, study_uid_pk=None):
...
    try:
        if tag.name.lower() == 'study instance uid':
            db.execute(INSERT_OTHER % table_name(tag), (original, cleaned))
            return cleaned
        else:
            db.execute(INSERT_LINKED % table_name(tag), (original, cleaned, study_uid_pk))
            return cleaned
    except sqlite3.IntegrityError:
        return audit_get(tag=tag, study_uid_pk=study_uid_pk)
@jeffmax
Copy link
Contributor

jeffmax commented Apr 3, 2015

Could you submit this as a pull request?

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