Skip to content
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

Enable admin to add new officers and units for any department #310

Merged
merged 23 commits into from
Dec 10, 2017

Conversation

redshiftzero
Copy link
Member

@redshiftzero redshiftzero commented Sep 24, 2017

Status

Ready for review

Description of Changes

This PR:

  • Adds department_id columns to Officer and Unit
  • Adds manage.py command to link existing officers and units to the first department
  • Adds admin-only "Add officer" feature (for any department). Closes "Add cop" admin only route #213.
  • Adds admin-only "Add unit" feature (for any department).

screen shot 2017-09-24 at 12 00 12 pm
screen shot 2017-09-24 at 12 00 19 pm
screen shot 2017-09-24 at 12 00 26 pm

Notes for Deployment

$ pip install -r ../requirements.txt
$ python manage.py db upgrade
$ python manage.py link_officers_to_department

Tests and linting

  • I have rebased my changes on current develop

  • pytests pass in the development environment on my local machine

  • flake8 checks pass

Copy link
Contributor

@r4v5 r4v5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions, nothing block-worthy. Nice work!

Column('middle_initial', String(length=120)),
Column('race', String(length=120)),
Column('gender', String(length=120)),
Column('employment_date', DateTime),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has the potential for weird timezone bugs, but i don’t know how much potential it has.

Specifically i don’t remember if postgres’s datetime support includes zone or assumes the application handles it; there’s a potential for discrepancy when initializing these with dates (at time 00:00) and being returned referencing the day before/after we intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @r4v5. Filed this as a followup in #323 (note that this table exists and the column is already populated in the prod database)

from migrate.changeset import schema
pre_meta = MetaData()
post_meta = MetaData()
unit_types = Table('unit_types', post_meta,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is this table holding? units or unit types? unit type to me implies a general type with a one-to-many relationship from unit type to department but we make department id an int column, implying 1-to-1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, ‘descrip’ feels like a weird choice of column name; is there a reason to not just use name here?
(asking these questions early while refactoring/migrations are still relatively easy)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm so this table holds the unit names / descriptions, I linked them to department as I think it's nice to store it this way because when a user adds an officer assignment, the webapp could show them only the units that are associated with that police department

Column('gender', String(length=120)),
Column('employment_date', DateTime),
Column('birth_year', Integer),
Column('pd_id', Integer),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is pd_id and how does it differ from department_id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true - pd_id is not used, so removed in e68da55

department_id=form.department.data.id)
db.session.add(officer)
db.session.commit()
assignment = Assignment(officer_id=officer.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth noting that because we commit the session for officer before assignment, it’s possible to fail to create an officer+assignment duo due to things like db constraints or connectivity loss and have actually created the officer underlying it, which sounds like a way to accidentally get duplicate officers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified this to commit the two together in a91f3f7

@@ -33,6 +33,7 @@ class Officer(db.Model):
pd_id = db.Column(db.Integer, index=True, unique=False)
assignments = db.relationship('Assignment', backref='officer', lazy='dynamic')
face = db.relationship('Face', backref='officer', lazy='dynamic')
department_id = db.Column(db.Integer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we not want to explicitly state these are foreign keys here and in the migration?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also what happens if someone changes departments, say from UCPD to OPD?

@@ -62,6 +63,7 @@ class Unit(db.Model):

id = db.Column(db.Integer, primary_key=True)
descrip = db.Column(db.String(120), index=True, unique=False)
department_id = db.Column(db.Integer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same FK comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 495df5d

@redshiftzero
Copy link
Member Author

Well, I tried to squash the migrations in this PR, got annoyed at how finicky sqlalchemy-migrate is, so I ripped it out and replaced it with alembic (via Flask-Migrate). I've upgrade tested this and all went well. Deployment instructions in the PR are updated. I'm going to merge this now since I'm about to push more changes on top of the changes in this PR

@redshiftzero redshiftzero merged commit 76ffaad into develop Dec 10, 2017
@r4v5 r4v5 deleted the add-officers-units-multi-city branch July 1, 2018 20:28
AetherUnbound pushed a commit that referenced this pull request Jul 5, 2023
Bumps [sass](https://github.com/sass/dart-sass) from 1.61.0 to 1.62.1.
- [Release notes](https://github.com/sass/dart-sass/releases)
- [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md)
- [Commits](sass/dart-sass@1.61.0...1.62.1)

---
updated-dependencies:
- dependency-name: sass
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants