From 613489b9f14c9d8e8e79430ae5a04a939e060793 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:35:08 -0500 Subject: [PATCH 1/6] Update database.py --- OpenOversight/app/models/database.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index c50e0d59d..28124c86f 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -274,6 +274,12 @@ class Officer(BaseModel, TrackUpdates): cascade_backrefs=False, order_by="Salary.year.desc()", ) + allegations = db.relationship( + "Allegation", + back_populates = "officer", + cascade_backrefs=False, + order_by="Allegation.created_at" + ) __table_args__ = ( CheckConstraint("gender in ('M', 'F', 'Other')", name="gender_options"), @@ -704,6 +710,26 @@ class Incident(BaseModel, TrackUpdates): "Department", backref=db.backref("incidents", cascade_backrefs=False), lazy=True ) +class Allegation(BaseModel, TrackUpdates): + __tablename__ = "allegations" + + id = db.Column(db.Integer, primary_key=True) + incident_id = db.Column( + db.Integer, db.ForeignKey("incidents.id", name="allegations_incident_id_fkey") + ) + officer_id = db.Column( + db.Integer, db.ForeignKey("officers.id", name="allegations_officer_id_fkey") + ) + disposition = db.Column(db.Text(), nullable=True) + discipline = db.Column(db.Text(), nullable=True) + type = db.Column(db.Text(), nullable=True) + finding = db.Column(db.Text(), nullable=True) + officer = db.relationship( + "Officer", + back_populates = "allegations", + cascade_backrefs=False, + ) + class User(UserMixin, BaseModel): __tablename__ = "users" From 5a29937659955e559a0fee3ec537961380f47735 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:46:04 -0500 Subject: [PATCH 2/6] Update database.py --- OpenOversight/app/models/database.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index 28124c86f..05917acaf 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -274,12 +274,6 @@ class Officer(BaseModel, TrackUpdates): cascade_backrefs=False, order_by="Salary.year.desc()", ) - allegations = db.relationship( - "Allegation", - back_populates = "officer", - cascade_backrefs=False, - order_by="Allegation.created_at" - ) __table_args__ = ( CheckConstraint("gender in ('M', 'F', 'Other')", name="gender_options"), @@ -725,9 +719,10 @@ class Allegation(BaseModel, TrackUpdates): type = db.Column(db.Text(), nullable=True) finding = db.Column(db.Text(), nullable=True) officer = db.relationship( - "Officer", - back_populates = "allegations", - cascade_backrefs=False, + "Officer", backref=db.backref("allegations", cascade_backrefs=False), lazy=True + ) + incident = db.relationship( + "Incident", backref=db.backref("allegations", cascade_backrefs=False), lazy=True ) From 284474beccc594957a9e64b9f18ebab179ed84e0 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:15:20 -0500 Subject: [PATCH 3/6] Update database.py --- OpenOversight/app/models/database.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index 05917acaf..52bf4c70a 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -714,9 +714,9 @@ class Allegation(BaseModel, TrackUpdates): officer_id = db.Column( db.Integer, db.ForeignKey("officers.id", name="allegations_officer_id_fkey") ) - disposition = db.Column(db.Text(), nullable=True) + disposition = db.Column(db.Text(), nullable=False) discipline = db.Column(db.Text(), nullable=True) - type = db.Column(db.Text(), nullable=True) + type = db.Column(db.Text(), nullable=False) finding = db.Column(db.Text(), nullable=True) officer = db.relationship( "Officer", backref=db.backref("allegations", cascade_backrefs=False), lazy=True From f2977e4575a3edd7663467ec9a692d5ccb4a8c2c Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:14:36 -0500 Subject: [PATCH 4/6] Update database.py --- OpenOversight/app/models/database.py | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index 52bf4c70a..3c464e6f1 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -704,6 +704,7 @@ class Incident(BaseModel, TrackUpdates): "Department", backref=db.backref("incidents", cascade_backrefs=False), lazy=True ) + class Allegation(BaseModel, TrackUpdates): __tablename__ = "allegations" From 5e2cdbcf742b196f73a1d17e8309bab2eb8bd529 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:06:15 -0500 Subject: [PATCH 5/6] Create 2024-10-29-1755_8895cbef5743_make_allegations_table.py --- ...755_8895cbef5743_make_allegations_table.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py diff --git a/OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py b/OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py new file mode 100644 index 000000000..b826c25fa --- /dev/null +++ b/OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py @@ -0,0 +1,39 @@ +"""make allegations table + +Revision ID: 8895cbef5743 +Revises: 99c50fc8d294 +Create Date: 2024-10-29 17:55:02.500162 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + + +revision = '8895cbef5743' +down_revision = '99c50fc8d294' + + +def upgrade(): + op.create_table('allegations', + sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False), + sa.Column('last_updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False), + sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column('incident_id', sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column('officer_id', sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column('disposition', sa.TEXT(), autoincrement=False, nullable=False), + sa.Column('discipline', sa.TEXT(), autoincrement=False, nullable=True), + sa.Column('type', sa.TEXT(), autoincrement=False, nullable=False), + sa.Column('finding', sa.TEXT(), autoincrement=False, nullable=True), + sa.Column('created_by', sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column('last_updated_by', sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint(['created_by'], ['users.id'], name='allegations_created_by_fkey', ondelete='SET NULL'), + sa.ForeignKeyConstraint(['incident_id'], ['incidents.id'], name='allegations_incident_id_fkey'), + sa.ForeignKeyConstraint(['last_updated_by'], ['users.id'], name='allegations_last_updated_by_fkey', ondelete='SET NULL'), + sa.ForeignKeyConstraint(['officer_id'], ['officers.id'], name='allegations_officer_id_fkey'), + sa.PrimaryKeyConstraint('id', name='allegations_pkey') + ) + + +def downgrade(): + op.drop_table('allegations') From 0711bd6e5680a3d803b3a2a18a493bc35dddc16f Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:06:31 -0500 Subject: [PATCH 6/6] Update 2024-10-29-1755_8895cbef5743_make_allegations_table.py --- ...755_8895cbef5743_make_allegations_table.py | 70 +++++++++++++------ 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py b/OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py index b826c25fa..a3fb2eab6 100644 --- a/OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py +++ b/OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py @@ -5,35 +5,63 @@ Create Date: 2024-10-29 17:55:02.500162 """ -from alembic import op + import sqlalchemy as sa +from alembic import op from sqlalchemy.dialects import postgresql -revision = '8895cbef5743' -down_revision = '99c50fc8d294' +revision = "8895cbef5743" +down_revision = "99c50fc8d294" def upgrade(): - op.create_table('allegations', - sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False), - sa.Column('last_updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('incident_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('officer_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('disposition', sa.TEXT(), autoincrement=False, nullable=False), - sa.Column('discipline', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('type', sa.TEXT(), autoincrement=False, nullable=False), - sa.Column('finding', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('created_by', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('last_updated_by', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], name='allegations_created_by_fkey', ondelete='SET NULL'), - sa.ForeignKeyConstraint(['incident_id'], ['incidents.id'], name='allegations_incident_id_fkey'), - sa.ForeignKeyConstraint(['last_updated_by'], ['users.id'], name='allegations_last_updated_by_fkey', ondelete='SET NULL'), - sa.ForeignKeyConstraint(['officer_id'], ['officers.id'], name='allegations_officer_id_fkey'), - sa.PrimaryKeyConstraint('id', name='allegations_pkey') + op.create_table( + "allegations", + sa.Column( + "created_at", + postgresql.TIMESTAMP(timezone=True), + server_default=sa.text("now()"), + autoincrement=False, + nullable=False, + ), + sa.Column( + "last_updated_at", + postgresql.TIMESTAMP(timezone=True), + server_default=sa.text("now()"), + autoincrement=False, + nullable=False, + ), + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("incident_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("officer_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("disposition", sa.TEXT(), autoincrement=False, nullable=False), + sa.Column("discipline", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("type", sa.TEXT(), autoincrement=False, nullable=False), + sa.Column("finding", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("created_by", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("last_updated_by", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["created_by"], + ["users.id"], + name="allegations_created_by_fkey", + ondelete="SET NULL", + ), + sa.ForeignKeyConstraint( + ["incident_id"], ["incidents.id"], name="allegations_incident_id_fkey" + ), + sa.ForeignKeyConstraint( + ["last_updated_by"], + ["users.id"], + name="allegations_last_updated_by_fkey", + ondelete="SET NULL", + ), + sa.ForeignKeyConstraint( + ["officer_id"], ["officers.id"], name="allegations_officer_id_fkey" + ), + sa.PrimaryKeyConstraint("id", name="allegations_pkey"), ) def downgrade(): - op.drop_table('allegations') + op.drop_table("allegations")