|
| 1 | +from flask import Flask |
| 2 | +from flask_sqlalchemy import SQLAlchemy |
| 3 | +from datetime import datetime |
| 4 | + |
| 5 | +db = SQLAlchemy() |
| 6 | + |
| 7 | +class DmpOrg(db.Model): |
| 8 | + __tablename__ = 'dmp_orgs' |
| 9 | + |
| 10 | + id = db.Column(db.Integer, primary_key=True, autoincrement=True) |
| 11 | + created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) |
| 12 | + name = db.Column(db.String, nullable=False) |
| 13 | + description = db.Column(db.Text, nullable=True) |
| 14 | + link = db.Column(db.String, nullable=False) |
| 15 | + repo_owner = db.Column(db.String, nullable=False) |
| 16 | + |
| 17 | + # Relationship to DmpIssueUpdate |
| 18 | + issues = db.relationship('DmpIssueUpdate', backref='organization', lazy=True) |
| 19 | + |
| 20 | + # Updated relationship name to avoid conflict |
| 21 | + dmp_issues = db.relationship('DmpIssue', backref='organization', lazy=True) |
| 22 | + |
| 23 | + def __repr__(self): |
| 24 | + return f"<DmpOrg(id={self.id}, name={self.name})>" |
| 25 | + |
| 26 | + def to_dict(self): |
| 27 | + return { |
| 28 | + 'id': self.id, |
| 29 | + 'created_at': self.created_at.isoformat(), |
| 30 | + 'name': self.name, |
| 31 | + 'description': self.description, |
| 32 | + 'link': self.link, |
| 33 | + 'repo_owner': self.repo_owner |
| 34 | + } |
| 35 | + |
| 36 | +class DmpIssue(db.Model): |
| 37 | + __tablename__ = 'dmp_issues' |
| 38 | + |
| 39 | + id = db.Column(db.Integer, primary_key=True, autoincrement=True) |
| 40 | + issue_url = db.Column(db.String, nullable=False) |
| 41 | + issue_number = db.Column(db.Integer, nullable=False) |
| 42 | + mentor_username = db.Column(db.String, nullable=True) |
| 43 | + contributor_username = db.Column(db.String, nullable=True) |
| 44 | + title = db.Column(db.String, nullable=False) |
| 45 | + org_id = db.Column(db.Integer, db.ForeignKey('dmp_orgs.id'), nullable=False) |
| 46 | + description = db.Column(db.Text, nullable=True) |
| 47 | + repo = db.Column(db.String, nullable=True) |
| 48 | + |
| 49 | + |
| 50 | + # Relationship to Prupdates |
| 51 | + pr_updates = db.relationship('Prupdates', backref='pr_details', lazy=True) |
| 52 | + |
| 53 | + def __repr__(self): |
| 54 | + return f"<DmpIssue(id={self.id}, title={self.title})>" |
| 55 | + |
| 56 | + def to_dict(self): |
| 57 | + return { |
| 58 | + 'id': self.id, |
| 59 | + 'issue_url': self.issue_url, |
| 60 | + 'issue_number': self.issue_number, |
| 61 | + 'mentor_username': self.mentor_username, |
| 62 | + 'contributor_username': self.contributor_username, |
| 63 | + 'title': self.title, |
| 64 | + 'org_id': self.org_id, |
| 65 | + 'description': self.description, |
| 66 | + 'repo': self.repo |
| 67 | + } |
| 68 | + |
| 69 | +class DmpIssueUpdate(db.Model): |
| 70 | + __tablename__ = 'dmp_issue_updates' |
| 71 | + |
| 72 | + created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) |
| 73 | + body_text = db.Column(db.Text, nullable=False) |
| 74 | + comment_link = db.Column(db.String, nullable=False) |
| 75 | + comment_id = db.Column(db.BigInteger, primary_key=True, nullable=False) |
| 76 | + comment_api = db.Column(db.String, nullable=False) |
| 77 | + comment_updated_at = db.Column(db.DateTime, nullable=False) |
| 78 | + dmp_id = db.Column(db.Integer, db.ForeignKey('dmp_orgs.id'), nullable=False) |
| 79 | + created_by = db.Column(db.String, nullable=False) |
| 80 | + |
| 81 | + def __repr__(self): |
| 82 | + return f"<DmpIssueUpdate(comment_id={self.comment_id}, dmp_id={self.dmp_id})>" |
| 83 | + |
| 84 | + def to_dict(self): |
| 85 | + return { |
| 86 | + 'created_at': self.created_at.isoformat(), |
| 87 | + 'body_text': self.body_text, |
| 88 | + 'comment_link': self.comment_link, |
| 89 | + 'comment_id': self.comment_id, |
| 90 | + 'comment_api': self.comment_api, |
| 91 | + 'comment_updated_at': self.comment_updated_at.isoformat(), |
| 92 | + 'dmp_id': self.dmp_id, |
| 93 | + 'created_by': self.created_by |
| 94 | + } |
| 95 | + |
| 96 | +class Prupdates(db.Model): |
| 97 | + __tablename__ = 'dmp_pr_updates' |
| 98 | + |
| 99 | + created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) |
| 100 | + pr_id = db.Column(db.Integer, nullable=False,primary_key=True) |
| 101 | + status = db.Column(db.String, nullable=False) |
| 102 | + title = db.Column(db.String, nullable=False) |
| 103 | + pr_updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) |
| 104 | + merged_at = db.Column(db.DateTime) |
| 105 | + closed_at = db.Column(db.DateTime) |
| 106 | + dmp_id = db.Column(db.Integer, db.ForeignKey('dmp_issues.id'), nullable=False) # ForeignKey relationship |
| 107 | + link = db.Column(db.String, nullable=False) |
| 108 | + |
| 109 | + def __repr__(self): |
| 110 | + return f'<PullRequest {self.pr_id} - {self.title}>' |
| 111 | + |
| 112 | + def to_dict(self): |
| 113 | + return { |
| 114 | + 'created_at': self.created_at.isoformat(), |
| 115 | + 'pr_id': self.pr_id, |
| 116 | + 'status': self.status, |
| 117 | + 'title': self.title, |
| 118 | + 'pr_updated_at': self.pr_updated_at.isoformat(), |
| 119 | + 'merged_at': self.merged_at.isoformat() if self.merged_at else None, |
| 120 | + 'closed_at': self.closed_at.isoformat() if self.closed_at else None, |
| 121 | + 'dmp_id': self.dmp_id, |
| 122 | + 'link': self.link |
| 123 | + } |
| 124 | + |
| 125 | +class DmpWeekUpdate(db.Model): |
| 126 | + __tablename__ = 'dmp_week_updates' |
| 127 | + |
| 128 | + id = db.Column(db.Integer, primary_key=True, autoincrement=True) |
| 129 | + issue_url = db.Column(db.String, nullable=False) |
| 130 | + week = db.Column(db.Integer, nullable=False) |
| 131 | + total_task = db.Column(db.Integer, nullable=False) |
| 132 | + completed_task = db.Column(db.Integer, nullable=False) |
| 133 | + progress = db.Column(db.Integer, nullable=False) |
| 134 | + task_data = db.Column(db.Text, nullable=False) |
| 135 | + dmp_id = db.Column(db.Integer, nullable=False) |
| 136 | + |
| 137 | + def __repr__(self): |
| 138 | + return f"<DmpWeekUpdate(id={self.id}, week={self.week}, dmp_id={self.dmp_id})>" |
| 139 | + |
| 140 | +# if __name__ == '__main__': |
| 141 | +# db.create_all() |
0 commit comments