diff --git a/OpenOversight/app/models.py b/OpenOversight/app/models.py index 332dc3086..5f079fdc6 100644 --- a/OpenOversight/app/models.py +++ b/OpenOversight/app/models.py @@ -201,6 +201,7 @@ class Officer(BaseModel): salaries = db.relationship( "Salary", back_populates="officer", order_by="Salary.year.desc()" ) + allegations = db.relationship("Allegation", backref="officer", lazy=True) __table_args__ = ( CheckConstraint("gender in ('M', 'F', 'Other')", name="gender_options"), @@ -569,6 +570,7 @@ class Incident(BaseModel): lazy="subquery", backref=db.backref("incidents"), ) + allegations = db.relationship("Allegation", backref="incident", lazy="subquery") department_id = db.Column(db.Integer, db.ForeignKey("departments.id")) department = db.relationship("Department", backref="incidents", lazy=True) creator_id = db.Column(db.Integer, db.ForeignKey("users.id")) @@ -585,6 +587,32 @@ class Incident(BaseModel): ) +class Allegation(BaseModel): + __tablename__ = "allegations" + # db meta + id = db.Column(db.Integer, primary_key=True) + date_created = db.Column(db.DateTime, default=func.now()) + date_updated = db.Column( + db.DateTime, default=func.now(), onupdate=func.now(), index=True + ) + # details + allegation = db.Column(db.String(255), nullable=False) + directive = db.Column(db.Text(), nullable=True) + disposition = db.Column(db.String(255), nullable=True) + discipline = db.Column(db.String(255), nullable=True) + finding = db.Column(db.String(255), nullable=True) + officer_name = db.Column(db.String(255), nullable=True) + officer_title_at_time_of_incident = db.Column(db.String(255), nullable=True) + star_no = db.Column(db.String(120), index=True, unique=False, nullable=True) + incident_type = db.Column(db.String(255), nullable=True) + case = db.Column(db.String(255), nullable=True) + source = db.Column(db.String(255), nullable=True) + # fks + incident_id = db.Column(db.Integer, db.ForeignKey('incidents.id'), nullable=False) + officer_id = db.Column(db.Integer, db.ForeignKey('officers.id'), nullable= True) + + + class User(UserMixin, BaseModel): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) diff --git a/OpenOversight/migrations/versions/051675f22efd_add_allegations.py b/OpenOversight/migrations/versions/051675f22efd_add_allegations.py new file mode 100644 index 000000000..bbdbbfd9b --- /dev/null +++ b/OpenOversight/migrations/versions/051675f22efd_add_allegations.py @@ -0,0 +1,56 @@ +"""add_allegations + +Revision ID: 051675f22efd +Revises: 8fc4d110de2c +Create Date: 2023-08-16 22:56:56.089583 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '051675f22efd' +down_revision = '8fc4d110de2c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('allegations', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('date_created', sa.DateTime(), nullable=True), + sa.Column('date_updated', sa.DateTime(), nullable=True), + sa.Column('allegation', sa.String(length=255), nullable=False), + sa.Column('directive', sa.Text(), nullable=True), + sa.Column('disposition', sa.String(length=255), nullable=True), + sa.Column('discipline', sa.String(length=255), nullable=True), + sa.Column('finding', sa.String(length=255), nullable=True), + sa.Column('officer_name', sa.String(length=255), nullable=True), + sa.Column('officer_title_at_time_of_incident', sa.String(length=255), nullable=True), + sa.Column('star_no', sa.String(length=120), nullable=True), + sa.Column('incident_type', sa.String(length=255), nullable=True), + sa.Column('case', sa.String(length=255), nullable=True), + sa.Column('source', sa.String(length=255), nullable=True), + sa.Column('incident_id', sa.Integer(), nullable=False), + sa.Column('officer_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['incident_id'], ['incidents.id'], ), + sa.ForeignKeyConstraint(['officer_id'], ['officers.id'], ), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('allegations', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_allegations_date_updated'), ['date_updated'], unique=False) + batch_op.create_index(batch_op.f('ix_allegations_star_no'), ['star_no'], unique=False) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('allegations', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_allegations_star_no')) + batch_op.drop_index(batch_op.f('ix_allegations_date_updated')) + + op.drop_table('allegations') + # ### end Alembic commands ###