From 4e1ed88ebe6e0bab308b81e231c230c82b5f82fa Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 04 2014 10:22:53 +0000 Subject: Add the GlobalId table This table allows us to have a global identifier for the issues and requests within a project. For example: issue 1: global id: 1 issue 2: global id: 2 request 1: global id: 3 issue 3: global id: 4 request 2: global id: 5 --- diff --git a/progit/model.py b/progit/model.py index acafbe3..e6a4850 100644 --- a/progit/model.py +++ b/progit/model.py @@ -392,3 +392,37 @@ class PullRequest(BASE): return 'PullRequest(%s, project:%s, user:%s, title:%s)' % ( self.id, self.repo.name, self.user.user, self.title ) + + +class GlobalId(BASE): + """ Store the mapping of the project with their issue and pull-request + and provides us with a way to get global identifier per project + + Table -- global_id + """ + + __tablename__ = 'global_id' + + id = sa.Column(sa.Integer, primary_key=True) + project_id = sa.Column( + sa.Integer, + sa.ForeignKey( + 'projects.id', ondelete='CASCADE', onupdate='CASCADE'), + nullable=False) + issue_id = sa.Column( + sa.Integer, + sa.ForeignKey( + 'issues.id', ondelete='CASCADE', onupdate='CASCADE'), + nullable=True) + request_id = sa.Column( + sa.Integer, + sa.ForeignKey( + 'pull_requests.id', ondelete='CASCADE', onupdate='CASCADE'), + nullable=True) + + __table_args__ = ( + # Both fields should not be NULL + sa.CheckConstraint('NOT(request_id IS NULL AND issue_id IS NULL)'), + # Both fields should not be not NULL (ie: only one of them should) + sa.CheckConstraint('NOT(request_id IS NOT NULL AND issue_id IS NOT NULL)'), + )