from datetime import datetime import sqlalchemy from flask_sqlalchemy import SQLAlchemy from flask_login import UserMixin ########################################### # Model classes for describing SQL tables # ########################################### # The "db" object gets bound to the Flask app in app.py. db = SQLAlchemy() class UploadSolar(db.Model): __tablename__ = 'upload_solar' id = db.Column(db.Integer, primary_key=True) upload_user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=True) institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=True) upload_hash = db.Column(db.String, nullable=False) timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) region = db.Column(db.String, nullable=True) program = db.Column(db.String, nullable=True) subject = db.Column(db.String, nullable=True) subject_custom = db.Column(db.String, nullable=True) grade = db.Column(db.Integer, nullable=True) text_type = db.Column(db.String, nullable=True) text_type_custom = db.Column(db.String, nullable=True) school_year = db.Column(db.String, nullable=True) grammar_corrections = db.Column(db.String, nullable=True) upload_file_hashes = db.Column(sqlalchemy.types.ARRAY(db.String), nullable=True) upload_file_names = db.Column(sqlalchemy.types.ARRAY(db.String), nullable=True) upload_file_codes = db.Column(sqlalchemy.types.ARRAY(db.String), nullable=True) class ContractsSolar(db.Model): __tablename__ = 'contracts_solar' id = db.Column(db.Integer, primary_key=True) institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False) upload_user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=True) timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) file_contract = db.Column(db.String, nullable=False) original_filename = db.Column(db.String, nullable=True) contract_type = db.Column(db.String, nullable=False) class RegisteredUser(UserMixin, db.Model): __tablename__ = 'registered_user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) email = db.Column(db.String, nullable=False, unique=True) role = db.Column(db.String, nullable=False) pass_hash = db.Column(db.String, nullable=False) active = db.Column(db.Boolean, nullable=True) last_login = db.Column(db.DateTime, nullable=True) registered = db.Column(db.DateTime, nullable=True) is_removed = db.Column(db.Boolean, nullable=False, default=False, server_default="false") class UserInstitutionMapping(db.Model): __tablename__ = 'user_institution_mapping' id = db.Column(db.Integer, primary_key=True) user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=False) institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False) role = db.Column(db.String, nullable=False) class UserCooperationHistory(db.Model): __tablename__ = 'user_cooperation' id = db.Column(db.Integer, primary_key=True) user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=False) institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False) role = db.Column(db.String, nullable=False) school_year = db.Column(db.String, nullable=False) badge_text = db.Column(db.String, nullable=True) class Institution(db.Model): __tablename__ = 'institution' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False, unique=True) region = db.Column(db.String, nullable=False) is_removed = db.Column(db.Boolean, nullable=False, default=False, server_default="false") class CorpusAccess(db.Model): __tablename__ = 'corpus_access' id = db.Column(db.Integer, primary_key=True) institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False) corpus = db.Column(db.String, nullable=False) class InstitutionContract(db.Model): __tablename__ = 'institution_contract' id = db.Column(db.Integer, primary_key=True) institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False) corpus = db.Column(db.String, nullable=False) timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) file_contract = db.Column(db.String, nullable=True) original_filename = db.Column(db.String, nullable=True)