Repository navigation
Officers database refactor #195
Description
Description
We used to have permissions based off officer terms, but there was no clean way to give permissions outside of that. Since there is usually a transition period and a constraint of there being only one of each role is going to be enforced later on, that also made the Officer term table unreliable. Furthermore, historical data is missing computing IDs for several entries, without a clear way to recover them. This makes the Officer term table requiring a Site User to exist not very practical, as they currently share either an empty or NA value in the database.
We also should differentiate Executives and Non-Executives/Representative terms since they operate with different rules and Executives can also hold Representative roles.
Tasks
- Constraints are things the database should enforce.
- Validators are things Pydantic models can enforce. These can match the database constraints, but some of them are unreasonable, like determining if something is unique.
Officer Info
- Contains information about every single Officer.
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | INT |
PK |
Unique ID |
| computing_id | VARCHAR(16) |
UNIQUE, NULLABLE, FK -> site_user.computing_id, ON DELETE SET NULL |
SFU Computing ID |
| legal_name | VARCHAR(128) |
||
| preferred_name | VARCHAR(128) |
NULLABLE |
The Officer's preferred first name |
| discord_id | VARCHAR(32) |
UNIQUE, NULLABLE |
Discord Snowflake ID |
| phone_number | VARCHAR(30) |
NULLABLE |
|
| github_username | VARCHAR(39) |
UNIQUE, NULLABLE |
|
| google_drive_email | VARCHAR(256) |
UNIQUE, NULLABLE |
Google drive email, including the @gmail.com |
- Clean up phone numbers from historical data that seem incorrect (they're stored as
intin the pre-rewrite database lmao). - Fix
github_username,discord_id, andgoogle_drive_emailto beNULLinstead of an empty string on existing data.
Officer Position
- Contains every type of Officer that has ever existed.
- New table, ensures validation code doesn't drift from our defined positions.
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | INT |
PK, AUTO_INC |
ID of the position |
| position | VARCHAR(64) |
UNIQUE |
Name of the position |
- Remove the current
StrEnumthat define this.
Officer Position Version
- Contains the version of a position, to ensure historical data isn't affected by changing roles.
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | INT |
PK |
Unique ID |
| position_id | INT |
FK -> officer_position.id |
ID of the position this version affects |
| category | VARCHAR(32) |
in executive, appointed_rep, elected_rep |
The type of Officer |
| multiple_allowed | BOOLEAN |
NULLABLE |
True if multiples of this Position can exist at one time. Only relevant to executives. |
| effective_from | DATE |
Date this version was effective from | |
| effective_to | DATE |
NULLABLE |
Date this version was effective to |
Constraints
- If
category = executive, thenmultiple_allowedmust not beNULL - If
category <> executive, thenmultiple_allowedmust beNULL -
effective_to >= effective_from, wheneffective_tois not NULL - Versions of the same Position must not have overlapping effective periods.
EXCLUDE USING gist (
position_id WITH =,
daterange(effective_from, effective_to, '[]') WITH &&
)Endpoints
-
GET /position: Returns a list of officer roles.active: Truthy value that defaults tofalse. If true, returns the position versions whereeffective_version.effective_toIS NULL or has not passed yet andeffective_from>= current date.
-
POST /position: Create a new position and version. -
POST /position/<position_id>: Create a new version, and set theeffective_todate on the old version to the suppliedeffective_fromdate, minus 1 day. -
PATCH /position/<version_id>: Set theeffective_todate on a role.
Officer Term
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | INT |
PK |
Unique ID |
| officer_id | INT |
FK -> officer_info.id |
ID of the Officer who served this term |
| position_version_id | INT |
FK -> officer_position_version.id |
ID of the position this Officer served |
| start_date | DATE |
Start date of the term | |
| end_date | DATE |
NULLABLE |
End date of the term |
| photo_url | TEXT |
NULLABLE |
URL on the media server for their photo |
Constraints
- (Check)
end_date IS NULL OR end_date >= start_date. - (Trigger) An Officer Term must fall entirely within the effective period of its referenced Position Version.
- (Trigger) An Officer cannot have overlapping Officer Terms where both Position Versions are categorized as
executive. - (Trigger) If a Position Version is categorized as
executiveand hasmultiple_allowed = false, there cannot be another overlapping Officer Term referencing a version of the same underlying Position.
Endpoints
- Remove
GET /officer/all. - Remove
GET /officer/current. - Add
GET /officerendpoint.current: Optional, defaults tofalse. If true, only retrieve officers with term that has started and hasn't ended, if false returns all officers.
Officer Term Data
- Contains information we don't really collect anymore and is missing on a lot of historical data.
| Column | Type | Constraints | Description |
|---|---|---|---|
| officer_term_id | INT |
PK, FK -> officer_term.id |
Officer term this data was tied to. |
| favourite_course_0 | VARCHAR(16) |
NULLABLE |
Favourite SFU course |
| favourite_course_1 | VARCHAR(16) |
NULLABLE |
Favourite SFU course |
| favourite_pl_0 | VARCHAR(32) |
NULLABLE |
Favourite programming language |
| favourite_pl_1 | VARCHAR(32) |
NULLABLE |
Favourite programming language |
| biography | TEXT |
NULLABLE |
A blurb about the officer during this term |
Other changes
- The first migration will need
CREATE EXTENSION IF NOT EXISTS btree_gist;- Endpoint
/officers/allon the production database returns 500 #159 : this should be fixed once the data has been cleaned and the changes implemented.
Tests
Tests should be updated, as indicated in #165.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity