Skip to content

Commit

Permalink
Hotfix: Address missing constraint issue (lucyparsons#1007)
Browse files Browse the repository at this point in the history
## Fixes issue
lucyparsons#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>
  • Loading branch information
michplunkett authored and sea-kelp committed Sep 25, 2023
1 parent 6e4353e commit f20ffb7
Showing 1 changed file with 0 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def upgrade():

with op.batch_alter_table("descriptions", schema=None) as batch_op:
batch_op.add_column(sa.Column("created_by", sa.Integer(), nullable=True))
batch_op.drop_constraint("descriptions_creator_id_fkey", type_="foreignkey")
batch_op.create_foreign_key(
"descriptions_created_by_fkey",
"users",
Expand Down Expand Up @@ -97,7 +96,6 @@ def upgrade():
nullable=False,
)
)
batch_op.drop_constraint("faces_user_id_fkey", type_="foreignkey")
batch_op.create_foreign_key(
"faces_created_by_fkey", "users", ["created_by"], ["id"]
)
Expand Down Expand Up @@ -223,7 +221,6 @@ def upgrade():
nullable=False,
)
)
batch_op.drop_constraint("links_creator_id_fkey", type_="foreignkey")
batch_op.create_foreign_key(
"links_created_by_fkey",
"users",
Expand Down Expand Up @@ -263,7 +260,6 @@ def upgrade():

with op.batch_alter_table("notes", schema=None) as batch_op:
batch_op.add_column(sa.Column("created_by", sa.Integer(), nullable=True))
batch_op.drop_constraint("notes_creator_id_fkey", type_="foreignkey")
batch_op.create_foreign_key(
"notes_created_by_fkey",
"users",
Expand Down Expand Up @@ -334,7 +330,6 @@ def upgrade():

with op.batch_alter_table("raw_images", schema=None) as batch_op:
batch_op.add_column(sa.Column("created_by", sa.Integer(), nullable=True))
batch_op.drop_constraint("raw_images_user_id_fkey", type_="foreignkey")
batch_op.create_foreign_key(
"raw_images_created_by_fkey",
"users",
Expand Down

0 comments on commit f20ffb7

Please sign in to comment.