Skip to content

Commit 6c08a17

Browse files
authored
Hotfix: Address missing constraint issue (#1007)
## Fixes issue #1005 ## Description of Changes This fixes the issue we were having with trying to drop the `faces_user_id_fkey` in the push to `main`. What happened was the `faces_user_id_fkey` wasn't saved under a name in the previous database model. PosgreSQL will drop any attached constraints when a column is dropped (presuming there are no `CASCADE` effects), so I am removing the `drop_constraint` commands and JUST dropping the column. This will allow PostgreSQL to take care of the constraint problem for us. ## Tests and linting - [x] This branch is up-to-date with the `develop` branch. - [x] `pytest` passes on my local development environment. - [x] `pre-commit` passes on my local development environment. <details><summary>DB migration output</summary> ```console :/usr/src/app$ flask db upgrade [2023-08-03 21:48:37,989] INFO in __init__: OpenOversight startup ... INFO [sqlalchemy.engine.Engine] COMMIT INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. INFO [alembic.runtime.migration] Running upgrade 18f43ac4622f -> b38c133bed3c, add created_by and created_at columns :/usr/src/app$ flask db downgrade [2023-08-03 21:48:50,167] INFO in __init__: OpenOversight startup ... INFO [sqlalchemy.engine.Engine] COMMIT INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. INFO [alembic.runtime.migration] Running downgrade b38c133bed3c -> 18f43ac4622f, add created_by and created_at columns :/usr/src/app$ flask db upgrade [2023-08-03 21:48:58,053] INFO in __init__: OpenOversight startup ... INFO [sqlalchemy.engine.Engine] COMMIT INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. INFO [alembic.runtime.migration] Running upgrade 18f43ac4622f -> b38c133bed3c, add created_by and created_at columns :/usr/src/app$ ``` </details>
1 parent cb63dfe commit 6c08a17

File tree

1 file changed

+0
-7
lines changed

1 file changed

+0
-7
lines changed

OpenOversight/migrations/versions/2023-08-01-1905_b38c133bed3c_add_created_by_and_created_at_columns.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def upgrade():
5656

5757
with op.batch_alter_table("descriptions", schema=None) as batch_op:
5858
batch_op.add_column(sa.Column("created_by", sa.Integer(), nullable=True))
59-
batch_op.drop_constraint("descriptions_creator_id_fkey", type_="foreignkey")
6059
batch_op.create_foreign_key(
6160
"descriptions_created_by_fkey",
6261
"users",
@@ -86,7 +85,6 @@ def upgrade():
8685
nullable=False,
8786
)
8887
)
89-
batch_op.drop_constraint("faces_user_id_fkey", type_="foreignkey")
9088
batch_op.create_foreign_key(
9189
"faces_created_by_fkey", "users", ["created_by"], ["id"]
9290
)
@@ -150,8 +148,6 @@ def upgrade():
150148
nullable=True,
151149
)
152150
)
153-
batch_op.drop_constraint("incidents_last_updated_id_fkey", type_="foreignkey")
154-
batch_op.drop_constraint("incidents_creator_id_fkey", type_="foreignkey")
155151
batch_op.create_foreign_key(
156152
"incidents_last_updated_by_fkey",
157153
"users",
@@ -221,7 +217,6 @@ def upgrade():
221217
nullable=False,
222218
)
223219
)
224-
batch_op.drop_constraint("links_creator_id_fkey", type_="foreignkey")
225220
batch_op.create_foreign_key(
226221
"links_created_by_fkey",
227222
"users",
@@ -261,7 +256,6 @@ def upgrade():
261256

262257
with op.batch_alter_table("notes", schema=None) as batch_op:
263258
batch_op.add_column(sa.Column("created_by", sa.Integer(), nullable=True))
264-
batch_op.drop_constraint("notes_creator_id_fkey", type_="foreignkey")
265259
batch_op.create_foreign_key(
266260
"notes_created_by_fkey",
267261
"users",
@@ -321,7 +315,6 @@ def upgrade():
321315

322316
with op.batch_alter_table("raw_images", schema=None) as batch_op:
323317
batch_op.add_column(sa.Column("created_by", sa.Integer(), nullable=True))
324-
batch_op.drop_constraint("raw_images_user_id_fkey", type_="foreignkey")
325318
batch_op.create_foreign_key(
326319
"raw_images_created_by_fkey",
327320
"users",

0 commit comments

Comments
 (0)