class Project(db.Model): """ Represents information about a research project """ __tablename__ = 'projects' id = db.Column(db.Integer, primary_key=True) neutral_id = db.Column(db.String(32), unique=True, nullable=False, index=True) title = db.Column(db.Text(), nullable=False) acronym = db.Column(db.Text(), nullable=True) abstract = db.Column(db.Text(), nullable=True) website = db.Column(db.Text(), nullable=True) publications = db.Column(postgresql.ARRAY(db.Text(), dimensions=1, zero_indexes=True), nullable=True) access_duration = db.Column(postgresql.DATERANGE(), nullable=False) project_duration = db.Column(postgresql.DATERANGE(), nullable=False) country = db.Column(db.Enum(ProjectCountry), nullable=True) participants = db.relationship("Participant", back_populates="project") allocations = db.relationship("Allocation", back_populates="project") categorisations = db.relationship("Categorisation", back_populates="project") def __repr__(self): return f"<Project { self.neutral_id }>"
class Grant(db.Model): """ Represents information about a research grant """ __tablename__ = 'grants' id = db.Column(db.Integer, primary_key=True) organisation_id = db.Column(db.Integer, db.ForeignKey('organisations.id'), nullable=True) neutral_id = db.Column(db.String(32), unique=True, nullable=False, index=True) reference = db.Column(db.Text(), unique=True, nullable=False) title = db.Column(db.Text(), nullable=False) abstract = db.Column(db.Text(), nullable=True) website = db.Column(db.Text(), nullable=True) publications = db.Column(postgresql.ARRAY(db.Text(), dimensions=1, zero_indexes=True), nullable=True) duration = db.Column(postgresql.DATERANGE(), nullable=False) status = db.Column(db.Enum(GrantStatus), nullable=False) total_funds = db.Column(db.Numeric(24, 2), nullable=True) total_funds_currency = db.Column(db.Enum(GrantCurrency), nullable=True) funder = db.relationship('Organisation', back_populates='grants') allocations = db.relationship("Allocation", back_populates="grant") def __repr__(self): return f"<Grant { self.neutral_id } ({ self.reference })>"
def upgrade(): op.add_column( 'mp_group_membership', sa.Column('interval', postgresql.DATERANGE()), ) op.execute("update mp_group_membership " "set interval = daterange('2012-12-19', 'infinity')") op.alter_column('mp_group_membership', 'interval', nullable=False)
def upgrade(): # Grant # op.create_table( 'grants', sa.Column('id', sa.Integer(), nullable=False), sa.Column('neutral_id', sa.String(length=32), nullable=False), sa.Column('reference', sa.Text(), nullable=False), sa.Column('title', sa.Text(), nullable=False), sa.Column('abstract', sa.Text(), nullable=True), sa.Column('website', sa.Text(), nullable=True), sa.Column('publications', postgresql.ARRAY(sa.Text(), dimensions=1, zero_indexes=True), nullable=True), sa.Column('duration', postgresql.DATERANGE(), nullable=False), sa.Column('status', sa.Enum(*grant_status, name='grant_status'), nullable=False), sa.Column('total_funds', sa.Numeric(24, 2), nullable=True), sa.Column('total_funds_currency', postgresql.ENUM(*grant_currency, name='grant_currency'), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('reference')) op.create_index(op.f('ix_grants_neutral_id'), 'grants', ['neutral_id'], unique=True) # Allocation # op.create_table( 'allocations', sa.Column('id', sa.Integer(), nullable=False), sa.Column('neutral_id', sa.String(length=32), nullable=False), sa.Column('project_id', sa.Integer(), nullable=False), sa.Column('grant_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ('grant_id', ), ['grants.id'], ), sa.ForeignKeyConstraint( ('project_id', ), ['projects.id'], ), sa.PrimaryKeyConstraint('id')) op.create_index(op.f('ix_allocations_neutral_id'), 'allocations', ['neutral_id'], unique=True)
def upgrade(): op.create_table( "financials", sa.Column("entry_id", sa.Integer(), nullable=False), sa.Column( "entry_type", postgresql.ENUM("EXPENSE", "GOAL", "INCOME", name="financialentrytype"), nullable=False, ), sa.Column("description", sa.Text(), nullable=True), sa.Column("amount", sa.Numeric(scale=2), nullable=False), sa.Column("date_range", postgresql.DATERANGE(), nullable=False), sa.Column( "is_approximate", sa.Boolean(), server_default="false", nullable=False ), sa.PrimaryKeyConstraint("entry_id", name=op.f("pk_financials")), ) op.create_index( "ix_financials_date_range_gist", "financials", ["date_range"], unique=False, postgresql_using="gist", )
def upgrade(): op.add_column('mandate', sa.Column('interval', postgresql.DATERANGE(), nullable=True))