diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-12 18:12:54 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-12 18:12:54 -0700 |
commit | 8c526bb10266e344a347b4ab1d6f905bf6b3600e (patch) | |
tree | 9759725dc55a2a40da7e723b6e894fd8d81ce9a3 | |
parent | bb5cb7102d6426e3054e586e8923ae1ec300825e (diff) | |
download | fatcat-8c526bb10266e344a347b4ab1d6f905bf6b3600e.tar.gz fatcat-8c526bb10266e344a347b4ab1d6f905bf6b3600e.zip |
much improve _id readability with _ident for identifier tables
-rw-r--r-- | fatcat/api.py | 2 | ||||
-rw-r--r-- | fatcat/models.py | 66 | ||||
-rw-r--r-- | fatcat/sql.py | 36 |
3 files changed, 52 insertions, 52 deletions
diff --git a/fatcat/api.py b/fatcat/api.py index 3c407cfe..c62d14a2 100644 --- a/fatcat/api.py +++ b/fatcat/api.py @@ -17,5 +17,5 @@ def api_work_get(work_id): @app.route('/v0/work/random', methods=['GET']) def api_work_random(): - work = WorkId.query.order_by(db.func.random()).first() + work = WorkIdent.query.order_by(db.func.random()).first() return redirect('/v0/work/{}'.format(work.id)) diff --git a/fatcat/models.py b/fatcat/models.py index abac8de9..ee73d61e 100644 --- a/fatcat/models.py +++ b/fatcat/models.py @@ -18,45 +18,45 @@ from fatcat import db class WorkContrib(db.Model): __tablename__ = "work_contrib" work_rev= db.Column(db.ForeignKey('work_revision.id'), nullable=False, primary_key=True) - creator_id = db.Column(db.ForeignKey('creator_id.id'), nullable=False, primary_key=True) + creator_id = db.Column(db.ForeignKey('creator_ident.id'), nullable=False, primary_key=True) type = db.Column(db.String, nullable=True) stub = db.Column(db.String, nullable=True) - creator = db.relationship("CreatorId") + creator = db.relationship("CreatorIdent") work = db.relationship("WorkRevision") class ReleaseContrib(db.Model): __tablename__ = "release_contrib" release_rev = db.Column(db.ForeignKey('release_revision.id'), nullable=False, primary_key=True) - creator_id = db.Column(db.ForeignKey('creator_id.id'), nullable=False, primary_key=True) + creator_id = db.Column(db.ForeignKey('creator_ident.id'), nullable=False, primary_key=True) type = db.Column(db.String, nullable=True) stub = db.Column(db.String, nullable=True) - creator = db.relationship("CreatorId") + creator = db.relationship("CreatorIdent") release = db.relationship("ReleaseRevision") class ReleaseRef(db.Model): __tablename__ = "release_ref" id = db.Column(db.Integer, primary_key=True, nullable=False) release_rev = db.Column(db.ForeignKey('release_revision.id'), nullable=False) - target_release_id = db.Column(db.ForeignKey('release_id.id'), nullable=True) + target_release_id = db.Column(db.ForeignKey('release_ident.id'), nullable=True) index = db.Column(db.Integer, nullable=True) stub = db.Column(db.String, nullable=True) doi = db.Column(db.String, nullable=True) release = db.relationship("ReleaseRevision") - target = db.relationship("ReleaseId") + target = db.relationship("ReleaseIdent") class FileRelease(db.Model): __tablename__ = "file_release" id = db.Column(db.Integer, primary_key=True, nullable=False) file_rev= db.Column(db.ForeignKey('file_revision.id'), nullable=False) - release_id = db.Column(db.ForeignKey('release_id.id'), nullable=False) + release_id = db.Column(db.ForeignKey('release_ident.id'), nullable=False) - release = db.relationship("ReleaseId") + release = db.relationship("ReleaseIdent") file = db.relationship("FileRevision") -class WorkId(db.Model): +class WorkIdent(db.Model): """ If revision_id is null, this was deleted. If redirect_id is not null, this has been merged with the given id. In this @@ -64,22 +64,22 @@ class WorkId(db.Model): an optimization. If the merged work is "deleted", revision_id can be null and redirect_id not-null. """ - __tablename__ = 'work_id' + __tablename__ = 'work_ident' id = db.Column(db.Integer, primary_key=True, nullable=False) live = db.Column(db.Boolean, nullable=False, default=False) revision_id = db.Column(db.ForeignKey('work_revision.id'), nullable=True) - redirect_id = db.Column(db.ForeignKey('work_id.id'), nullable=True) + redirect_id = db.Column(db.ForeignKey('work_ident.id'), nullable=True) revision = db.relationship("WorkRevision") class WorkLog(db.Model): __tablename__ = 'work_log' # ID is a monotonic int here; important for ordering! id = db.Column(db.Integer, primary_key=True, nullable=False) - work_id = db.Column(db.ForeignKey('work_id.id'), nullable=False) + work_ident_id = db.Column(db.ForeignKey('work_ident.id'), nullable=False) old_revision_id = db.Column(db.ForeignKey('work_revision.id'), nullable=True) - old_redirect_id = db.Column(db.ForeignKey('work_id.id'), nullable=True) + old_redirect_id = db.Column(db.ForeignKey('work_ident.id'), nullable=True) new_revision_id = db.Column(db.ForeignKey('work_revision.id'), nullable=True) - new_redirect_id = db.Column(db.ForeignKey('work_id.id'), nullable=True) + new_redirect_id = db.Column(db.ForeignKey('work_ident.id'), nullable=True) # TODO: is this right? edit_id = db.Column(db.ForeignKey('edit.id')) @@ -91,17 +91,17 @@ class WorkRevision(db.Model): title = db.Column(db.String) work_type = db.Column(db.String) - primary_release_id = db.Column(db.ForeignKey('release_id.id'), nullable=True) + primary_release_id = db.Column(db.ForeignKey('release_ident.id'), nullable=True) creators = db.relationship('WorkContrib', lazy='subquery', backref=db.backref('works', lazy=True)) -class ReleaseId(db.Model): - __tablename__ = 'release_id' +class ReleaseIdent(db.Model): + __tablename__ = 'release_ident' id = db.Column(db.Integer, primary_key=True) live = db.Column(db.Boolean, nullable=False, default=False) revision_id = db.Column(db.ForeignKey('release_revision.id')) - redirect_id = db.Column(db.ForeignKey('release_id.id'), nullable=True) + redirect_id = db.Column(db.ForeignKey('release_ident.id'), nullable=True) revision = db.relationship("ReleaseRevision") class ReleaseRevision(db.Model): @@ -110,8 +110,8 @@ class ReleaseRevision(db.Model): edit_id = db.Column(db.ForeignKey('edit.id')) extra_json = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True) - work_id = db.ForeignKey('work_id.id') - container_id = db.Column(db.ForeignKey('container_id.id'), nullable=True) + work_ident_id = db.ForeignKey('work_ident.id') + container_id = db.Column(db.ForeignKey('container_ident.id'), nullable=True) title = db.Column(db.String, nullable=False) license = db.Column(db.String, nullable=True) # TODO: oa status foreign key release_type = db.Column(db.String) # TODO: foreign key @@ -121,17 +121,17 @@ class ReleaseRevision(db.Model): pages = db.Column(db.String, nullable=True) issue = db.Column(db.String, nullable=True) - #work = db.relationship("WorkId", lazy='subquery') - container = db.relationship("ContainerId", lazy='subquery') + #work = db.relationship("WorkIdent", lazy='subquery') + container = db.relationship("ContainerIdent", lazy='subquery') creators = db.relationship('ReleaseContrib', lazy='subquery') refs = db.relationship('ReleaseRef', lazy='subquery') -class CreatorId(db.Model): - __tablename__ = 'creator_id' +class CreatorIdent(db.Model): + __tablename__ = 'creator_ident' id = db.Column(db.Integer, primary_key=True) live = db.Column(db.Boolean, nullable=False, default=False) revision_id = db.Column(db.ForeignKey('creator_revision.id')) - redirect_id = db.Column(db.ForeignKey('creator_id.id'), nullable=True) + redirect_id = db.Column(db.ForeignKey('creator_ident.id'), nullable=True) revision = db.relationship("CreatorRevision") class CreatorRevision(db.Model): @@ -139,18 +139,18 @@ class CreatorRevision(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) edit_id = db.Column(db.ForeignKey('edit.id')) extra_json = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True) - #creator_ids = db.relationship("CreatorId", backref="revision", lazy=False) + #creator_ids = db.relationship("CreatorIdent", backref="revision", lazy=False) name = db.Column(db.String) sortname = db.Column(db.String) orcid = db.Column(db.String) # TODO: identifier table -class ContainerId(db.Model): - __tablename__ = 'container_id' +class ContainerIdent(db.Model): + __tablename__ = 'container_ident' id = db.Column(db.Integer, primary_key=True) live = db.Column(db.Boolean, nullable=False, default=False) revision_id = db.Column(db.ForeignKey('container_revision.id')) - redirect_id = db.Column(db.ForeignKey('container_id.id'), nullable=True) + redirect_id = db.Column(db.ForeignKey('container_ident.id'), nullable=True) revision = db.relationship("ContainerRevision") class ContainerRevision(db.Model): @@ -160,17 +160,17 @@ class ContainerRevision(db.Model): extra_json = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True) name = db.Column(db.String) - #XXX: container_id = db.Column(db.ForeignKey('container_id.id')) + #XXX: container_id = db.Column(db.ForeignKey('container_ident.id')) publisher = db.Column(db.String) # TODO: foreign key sortname = db.Column(db.String) issn = db.Column(db.String) # TODO: identifier table -class FileId(db.Model): - __tablename__ = 'file_id' +class FileIdent(db.Model): + __tablename__ = 'file_ident' id = db.Column(db.Integer, primary_key=True) live = db.Column(db.Boolean, nullable=False, default=False) revision_id = db.Column('revision', db.ForeignKey('file_revision.id')) - redirect_id = db.Column(db.ForeignKey('file_id.id'), nullable=True) + redirect_id = db.Column(db.ForeignKey('file_ident.id'), nullable=True) revision = db.relationship("FileRevision") class FileRevision(db.Model): diff --git a/fatcat/sql.py b/fatcat/sql.py index b73ec464..f268d7be 100644 --- a/fatcat/sql.py +++ b/fatcat/sql.py @@ -14,18 +14,18 @@ def populate_db(): name="Noam D. Elkies", sortname="Elkies, N", orcid=None) - n_elkies_id = CreatorId(revision=n_elkies) + n_elkies_id = CreatorIdent(revision=n_elkies) pi_work = WorkRevision( title="Why is π^2 so close to 10?", work_type="journal-article") - pi_work_id = WorkId(revision=pi_work) + pi_work_id = WorkIdent(revision=pi_work) pi_release = ReleaseRevision( title=pi_work.title, - work_id=pi_work.id, + work_ident_id=pi_work.id, release_type="journal-article") pi_contrib = ReleaseContrib(creator=n_elkies_id) pi_release.creators.append(pi_contrib) - pi_release_id = ReleaseId(revision=pi_release) + pi_release_id = ReleaseIdent(revision=pi_release) pi_work.primary_release = pi_release # TODO: @@ -61,7 +61,7 @@ def populate_complex_db(count=100): sortname="{}, {}".format(last, first[0]), orcid=None) author_revs.append(ar) - author_ids.append(CreatorId(revision=ar)) + author_ids.append(CreatorIdent(revision=ar)) container_revs = [] container_ids = [] @@ -73,7 +73,7 @@ def populate_complex_db(count=100): sortname="Fake Journal of Stuff", issn="1234-5678") container_revs.append(cr) - container_ids.append(ContainerId(revision=cr)) + container_ids.append(ContainerIdent(revision=cr)) title_start = ("All about ", "When I grow up I want to be", "The final word on", "Infinity: ", "The end of") @@ -87,14 +87,14 @@ def populate_complex_db(count=100): for _ in range(count): title = "{} {}".format(random.choice(title_start), random.choice(title_ends)) work = WorkRevision(title=title) - work_id = WorkId(revision=work) + work_id = WorkIdent(revision=work) authors = set(random.sample(author_ids, 5)) release = ReleaseRevision( title=work.title, creators=[ReleaseContrib(creator=a) for a in list(authors)], #work=work, container=random.choice(container_ids)) - release_id = ReleaseId(revision=release) + release_id = ReleaseIdent(revision=release) work.primary_release = release authors.add(random.choice(author_ids)) release2 = ReleaseRevision( @@ -102,7 +102,7 @@ def populate_complex_db(count=100): creators=[ReleaseContrib(creator=a) for a in list(authors)], #work=work, container=random.choice(container_ids)) - release_id2 = ReleaseId(revision=release2) + release_id2 = ReleaseIdent(revision=release2) work_revs.append(work) work_ids.append(work_id) release_revs.append(release) @@ -118,7 +118,7 @@ def populate_complex_db(count=100): url="http://archive.invalid/{}".format(file_sha), releases=[FileRelease(release=release_id), FileRelease(release=release_id2)], ) - file_id = FileId(revision=file_rev) + file_id = FileIdent(revision=file_rev) file_revs.append(file_rev) file_ids.append(file_id) @@ -148,7 +148,7 @@ def add_crossref(meta): sortname="{}, {}".format(am['family'], am['given']), orcid=None) author_revs.append(ar) - author_ids.append(CreatorId(revision=ar)) + author_ids.append(CreatorIdent(revision=ar)) # container container = ContainerRevision( @@ -157,11 +157,11 @@ def add_crossref(meta): #container_id=None, publisher=meta['publisher'], sortname=meta['short-container-title'][0]) - container_id = ContainerId(revision=container) + container_id = ContainerIdent(revision=container) # work and release work = WorkRevision(title=title) - work_id = WorkId(revision=work) + work_id = WorkIdent(revision=work) release = ReleaseRevision( title=title, creators=[ReleaseContrib(creator=a) for a in author_ids], @@ -174,7 +174,7 @@ def add_crossref(meta): issue=meta.get('issue', None), volume=meta.get('volume', None), pages=meta.get('page', None)) - release_id = ReleaseId(revision=release) + release_id = ReleaseIdent(revision=release) work.primary_release = release extra = json.dumps({ 'crossref': { @@ -206,7 +206,7 @@ def add_crossref(meta): def hydrate_work(wid): wid = int(wid) - work = WorkId.query.filter(WorkId.id==wid).first_or_404() + work = WorkIdent.query.filter(WorkIdent.id==wid).first_or_404() hydro = { "_type": "work", "id": wid, @@ -223,7 +223,7 @@ def hydrate_work(wid): if work.revision.primary_release_id: primary = hydrate_release(work.revision.primary_release_id) creators = [c.creator_id for c in WorkContrib.query.filter(WorkContrib.work == work).all()] - #releases = [r.id for r in ReleaseId.query.filter(ReleaseId.revision.work_id==work.id).all()] + #releases = [r.id for r in ReleaseIdent.query.filter(ReleaseIdent.revision.work_id==work.id).all()] releases = [] hydro.update({ "work_type": work.revision.work_type, @@ -238,7 +238,7 @@ def hydrate_work(wid): def hydrate_release(rid): wid = int(rid) - release = ReleaseId.query.filter(ReleaseId.id==rid).first_or_404() + release = ReleaseIdent.query.filter(ReleaseIdent.id==rid).first_or_404() return { "_type": "release", @@ -247,7 +247,7 @@ def hydrate_release(rid): "edit_id": release.revision.edit_id, "is_live": release.live, - "work_id": release.revision.work_id, + "work_id": release.revision.work_ident_id, "release_type": release.revision.release_type, "title": release.revision.title, "creators": [], |