-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add allegations
table
#1131
Draft
michplunkett
wants to merge
16
commits into
develop
Choose a base branch
from
add-allegations-table
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add allegations
table
#1131
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
613489b
Update database.py
michplunkett 5a29937
Update database.py
michplunkett 284474b
Update database.py
michplunkett f2977e4
Update database.py
michplunkett 2005ae6
Merge branch 'develop' into add-allegations-table
michplunkett 5e2cdbc
Create 2024-10-29-1755_8895cbef5743_make_allegations_table.py
michplunkett 0711bd6
Update 2024-10-29-1755_8895cbef5743_make_allegations_table.py
michplunkett 29ea013
Merge branch 'develop' into add-allegations-table
michplunkett bca2be4
Merge branch 'develop' into add-allegations-table
michplunkett 02fac91
Merge branch 'develop' into add-allegations-table
michplunkett d001e74
Merge branch 'develop' into add-allegations-table
michplunkett 20144f4
Merge branch 'develop' into add-allegations-table
michplunkett b6f389c
Merge branch 'develop' into add-allegations-table
michplunkett 20147ec
Merge branch 'develop' into add-allegations-table
michplunkett 73315c4
Merge branch 'develop' into add-allegations-table
michplunkett 3472f80
Merge branch 'develop' into add-allegations-table
michplunkett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
OpenOversight/migrations/versions/2024-10-29-1755_8895cbef5743_make_allegations_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""make allegations table | ||
|
||
Revision ID: 8895cbef5743 | ||
Revises: 99c50fc8d294 | ||
Create Date: 2024-10-29 17:55:02.500162 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
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") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, I cannot get alembic to generate a migration for this table addition. Is there anything that looks out of place, @sea-kelp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a number of things with the LPL OO alembic but couldn't get it to generate the revision. I was however able to cherry pick the commits (613489b..f2977e4) into our OpenOversight repo and generate the revision there. I'm wondering if there's maybe a change that we haven't ported over yet that's causing the issue?
OrcaCollective@cadea71
Obviously, our models might be slightly different from yours so I wouldn't recommend directly using this generated migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember seeing some comments that each individual models needs to be imported into Alembic's
env.py
file. I'll take a look at the Orca one and see what the differences are.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's super hacky, but I added the table without it creating a migration and then removed the table and it created a migration. I'm just going to reverse the code on upgrade and downgrade, and take that result. I'm not super happy with how it ended up working, but I'll take it at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I downgrade and then upgrade the flask db command, it will error since the table will already be created when the application starts out.
I then continually used the flask db downgrade command and we get errors for other downgrades as well. I think this means we are consistent, but there are certainly some difficulties between the ORM and flask to maybe look into at some point.