-
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
Enable admin to add new officers and units for any department #310
Conversation
a7e29d4
to
90bb847
Compare
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.
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), |
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.
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.
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.
from migrate.changeset import schema | ||
pre_meta = MetaData() | ||
post_meta = MetaData() | ||
unit_types = Table('unit_types', post_meta, |
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.
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.
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.
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)
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.
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), |
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.
what is pd_id and how does it differ from department_id?
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.
true - pd_id
is not used, so removed in e68da55
OpenOversight/app/main/views.py
Outdated
department_id=form.department.data.id) | ||
db.session.add(officer) | ||
db.session.commit() | ||
assignment = Assignment(officer_id=officer.id, |
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.
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.
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.
Modified this to commit the two together in a91f3f7
OpenOversight/app/models.py
Outdated
@@ -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) |
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.
do we not want to explicitly state these are foreign keys here and in the 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.
also what happens if someone changes departments, say from UCPD to OPD?
OpenOversight/app/models.py
Outdated
@@ -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) |
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.
same FK comment
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.
Fixed in 495df5d
We no longer need these: all these migrations have been applied in master
in officers and units tables
And update migration
d11d449
to
8c09314
Compare
Well, I tried to squash the migrations in this PR, got annoyed at how finicky |
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>
Status
Ready for review
Description of Changes
This PR:
Officer
andUnit
manage.py
command to link existing officers and units to the first departmentNotes for Deployment
Tests and linting
I have rebased my changes on current
develop
pytests pass in the development environment on my local machine
flake8
checks pass