From 376572e594adc4fce63a75ea7e82caf29056f73d Mon Sep 17 00:00:00 2001 From: sorenrehkopf Date: Fri, 4 Aug 2023 16:09:41 -0700 Subject: [PATCH 1/3] initial pass on model --- OpenOversight/app/models.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/OpenOversight/app/models.py b/OpenOversight/app/models.py index 332dc3086..b1d177244 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,30 @@ 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=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) + 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('incident.id'), nullable=False) + officer_id = db.Column(db.Integer, db.ForeignKey('officer.id'), nullable= True) + + + class User(UserMixin, BaseModel): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) From 9e77774c505b72dbce8574d2fb3385ce92836e71 Mon Sep 17 00:00:00 2001 From: sorenrehkopf Date: Fri, 4 Aug 2023 17:14:46 -0700 Subject: [PATCH 2/3] migration generated --- OpenOversight/app/models.py | 4 +- .../versions/171ee9412815_add_allegations.py | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 OpenOversight/migrations/versions/171ee9412815_add_allegations.py diff --git a/OpenOversight/app/models.py b/OpenOversight/app/models.py index b1d177244..850130858 100644 --- a/OpenOversight/app/models.py +++ b/OpenOversight/app/models.py @@ -606,8 +606,8 @@ class Allegation(BaseModel): 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('incident.id'), nullable=False) - officer_id = db.Column(db.Integer, db.ForeignKey('officer.id'), nullable= True) + incident_id = db.Column(db.Integer, db.ForeignKey('incidents.id'), nullable=False) + officer_id = db.Column(db.Integer, db.ForeignKey('officers.id'), nullable= True) diff --git a/OpenOversight/migrations/versions/171ee9412815_add_allegations.py b/OpenOversight/migrations/versions/171ee9412815_add_allegations.py new file mode 100644 index 000000000..7d02af73c --- /dev/null +++ b/OpenOversight/migrations/versions/171ee9412815_add_allegations.py @@ -0,0 +1,54 @@ +"""add-allegations + +Revision ID: 171ee9412815 +Revises: 8fc4d110de2c +Create Date: 2023-08-05 00:14:32.513077 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '171ee9412815' +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=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('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 ### From c431b280749670459b22fdde508845faef38d331 Mon Sep 17 00:00:00 2001 From: sorenrehkopf Date: Wed, 16 Aug 2023 16:12:05 -0700 Subject: [PATCH 3/3] add directive officer title and make allegation required --- OpenOversight/app/models.py | 4 +++- ...llegations.py => 051675f22efd_add_allegations.py} | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) rename OpenOversight/migrations/versions/{171ee9412815_add_allegations.py => 051675f22efd_add_allegations.py} (85%) diff --git a/OpenOversight/app/models.py b/OpenOversight/app/models.py index 850130858..5f079fdc6 100644 --- a/OpenOversight/app/models.py +++ b/OpenOversight/app/models.py @@ -596,11 +596,13 @@ class Allegation(BaseModel): db.DateTime, default=func.now(), onupdate=func.now(), index=True ) # details - allegation = db.Column(db.String(255), nullable=True) + 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) diff --git a/OpenOversight/migrations/versions/171ee9412815_add_allegations.py b/OpenOversight/migrations/versions/051675f22efd_add_allegations.py similarity index 85% rename from OpenOversight/migrations/versions/171ee9412815_add_allegations.py rename to OpenOversight/migrations/versions/051675f22efd_add_allegations.py index 7d02af73c..bbdbbfd9b 100644 --- a/OpenOversight/migrations/versions/171ee9412815_add_allegations.py +++ b/OpenOversight/migrations/versions/051675f22efd_add_allegations.py @@ -1,8 +1,8 @@ -"""add-allegations +"""add_allegations -Revision ID: 171ee9412815 +Revision ID: 051675f22efd Revises: 8fc4d110de2c -Create Date: 2023-08-05 00:14:32.513077 +Create Date: 2023-08-16 22:56:56.089583 """ from alembic import op @@ -10,7 +10,7 @@ # revision identifiers, used by Alembic. -revision = '171ee9412815' +revision = '051675f22efd' down_revision = '8fc4d110de2c' branch_labels = None depends_on = None @@ -22,11 +22,13 @@ def upgrade(): 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=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),