Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allegations table #348

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions OpenOversight/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"))
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ###
Loading