You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
6.0KB

  1. # @name: models.py
  2. # @version: 0.1
  3. # @creation_date: 2021-10-20
  4. # @license: The MIT License <https://opensource.org/licenses/MIT>
  5. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  6. # @purpose: Database models for tables in the database
  7. # @acknowledgements:
  8. # https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login
  9. from flask_login import UserMixin
  10. from . import db
  11. from datetime import datetime
  12. # table for users
  13. class User(UserMixin, db.Model):
  14. __tablename__ = 'User'
  15. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  16. email = db.Column(db.String(100), unique=True)
  17. password = db.Column(db.String(100))
  18. name = db.Column(db.String(1000))
  19. # table for tools
  20. class Tool(db.Model):
  21. __tablename__ = 'Tool'
  22. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  23. created = db.Column(db.DateTime, default=datetime.utcnow)
  24. name = db.Column(db.Text)
  25. description = db.Column(db.Text)
  26. projectUrl = db.Column(db.Text)
  27. repositoryUrl = db.Column(db.Text)
  28. expertiseToUse = db.Column(db.Text)
  29. expertiseToHost = db.Column(db.Text)
  30. dependencies = db.Column(db.Text)
  31. ingestFormats = db.Column(db.Text)
  32. outputFormats = db.Column(db.Text)
  33. status = db.Column(db.Text)
  34. practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
  35. book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))
  36. practices = db.relationship('Practice', foreign_keys=[practice_id], backref='tool')
  37. books = db.relationship('Book', foreign_keys=[book_id], backref='tool')
  38. # table for practices
  39. class Practice(db.Model):
  40. __tablename__ = 'Practice'
  41. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  42. created = db.Column(db.DateTime, default=datetime.utcnow)
  43. name = db.Column(db.Text)
  44. description = db.Column(db.Text)
  45. tool_id = db.Column(db.Integer, db.ForeignKey('Tool.id'))
  46. typology_id = db.Column(db.Integer, db.ForeignKey('Typology.id'))
  47. book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))
  48. reference_id = db.Column(db.Integer, db.ForeignKey('Reference.id'))
  49. tools = db.relationship('Tool', foreign_keys=[tool_id], backref='practice')
  50. typologies = db.relationship('Typology', foreign_keys=[typology_id], backref='practice')
  51. books = db.relationship('Book', foreign_keys=[book_id], backref='practice')
  52. references = db.relationship('Reference', foreign_keys=[reference_id], backref='practice')
  53. # table for sensitivities
  54. class Sensitivity(db.Model):
  55. __tablename__ = 'Sensitivity'
  56. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  57. created = db.Column(db.DateTime, default=datetime.utcnow)
  58. name = db.Column(db.Text)
  59. description = db.Column(db.Text)
  60. practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
  61. typology_id = db.Column(db.Integer, db.ForeignKey('Typology.id'))
  62. reference_id = db.Column(db.Integer, db.ForeignKey('Reference.id'))
  63. practices = db.relationship('Practice', foreign_keys=[practice_id], backref='sensitivity')
  64. typologies = db.relationship('Typology', foreign_keys=[typology_id], backref='sensitivity')
  65. references = db.relationship('Reference', foreign_keys=[reference_id], backref='sensitivity')
  66. # table for typologies
  67. class Typology(db.Model):
  68. __tablename__ = 'Typology'
  69. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  70. created = db.Column(db.DateTime, default=datetime.utcnow)
  71. name = db.Column(db.Text)
  72. description = db.Column(db.Text)
  73. tool_id = db.Column(db.Integer, db.ForeignKey('Tool.id'))
  74. book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))
  75. practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
  76. reference_id = db.Column(db.Integer, db.ForeignKey('Reference.id'))
  77. tools = db.relationship('Tool', foreign_keys=[tool_id], backref='typology')
  78. books = db.relationship('Book', foreign_keys=[book_id], backref='typology_books')
  79. practices = db.relationship('Practice', foreign_keys=[practice_id], backref='typology')
  80. references = db.relationship('Reference', foreign_keys=[reference_id], backref='typology')
  81. # table for workflows
  82. class Workflow(db.Model):
  83. __tablename__ = 'Workflow'
  84. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  85. created = db.Column(db.DateTime, default=datetime.utcnow)
  86. # table for publishers
  87. class Publisher(db.Model):
  88. __tablename__ = 'Publisher'
  89. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  90. created = db.Column(db.DateTime, default=datetime.utcnow)
  91. name = db.Column(db.Text)
  92. description = db.Column(db.Text)
  93. publisherUrl = db.Column(db.Text)
  94. book_id = db.Column(db.Integer, db.ForeignKey('Book.id'))
  95. books = db.relationship('Book', foreign_keys=[book_id], backref='publisher')
  96. # table for books
  97. class Book(db.Model):
  98. __tablename__ = 'Book'
  99. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  100. created = db.Column(db.DateTime, default=datetime.utcnow)
  101. name = db.Column(db.Text)
  102. description = db.Column(db.Text)
  103. tool_id = db.Column(db.Integer, db.ForeignKey('Tool.id'))
  104. typology_id = db.Column(db.Integer, db.ForeignKey('Typology.id'))
  105. practice_id = db.Column(db.Integer, db.ForeignKey('Practice.id'))
  106. workflow_id = db.Column(db.Integer, db.ForeignKey('Workflow.id'))
  107. tools = db.relationship('Tool', foreign_keys=[tool_id], backref='book')
  108. typology = db.relationship('Typology', foreign_keys=[typology_id], backref='book')
  109. practices = db.relationship('Practice', foreign_keys=[practice_id], backref='book')
  110. workflow = db.relationship('Workflow', foreign_keys=[workflow_id], backref='book')
  111. # table for references
  112. class Reference(db.Model):
  113. __tablename__ = 'Reference'
  114. id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  115. created = db.Column(db.DateTime, default=datetime.utcnow)
  116. zoteroUrl = db.Column(db.Text)