Skip to content

Conversation

@mxc-maggiechen
Copy link
Contributor

@mxc-maggiechen mxc-maggiechen commented Nov 12, 2025

Notion ticket link

Drop position + department enums

Implementation description

  • Add a migration file that changes all position columns from a column of type enum to type string
    • The enums are also making filtering by positions very difficult and jank (related PR: [INTF25] Build filter for fetch review dashboard query #83)
    • And having enums postgres isn't a good idea in general, it makes the database too inflexible to changes
    • The following changes will be made to the database:
      • users table - positions column - type enum_positions_title -> type string (or character varying (255)
      • applicant_records table - positions column - type enum_positions_title -> string (or character varying (255)
      • positions table - title column - type enum_positions_title -> type string (or character varying (255)
      • positions table - department column - type enum_positions_department -> type string (or character varying (255)
  • Updated sequelize models to reflect type change
  • Updated types to reflect type change

Steps to test

  1. Run docker exec recruitment_tools_backend node migrate up to apply the new migration

  2. Check the following tables and columns in pgAdmin that they are of the correct type:

    • users table - positions column - type string (or character varying (255)
    • applicant_records table - positions column - type string (or character varying (255)
    • positions table - title column - type string (or character varying (255)
    • positions table - department column - type string (or character varying (255)
  3. Run docker exec recruitment_tools_backend node migrate down to undo the changes

  4. Check the following tables and columns in pgAdmin that they are restored to the original rtoe:

    • users table - positions column - type enum_positions_title
    • applicant_records table - positions column - type enum_positions_title
    • positions table - title column - type enum_positions_title
    • positions table - department column - type enum_positions_department

What should reviewers focus on?

  • The migration script logically make sense and makes the correct updates
  • The correct column types changes are made
  • Node migrate down restores database to the previous state before the migration

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • I have run the appropriate linter(s)
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to jump through a lot of hoops to get this migration working... because FK restraints in the database and enum restraints in the database prevented some of the changes. But, the general logic for the migration is as follows:

Drop foreign keys on the columns with the position enums we are trying to remove.
Delete the positions table and recreated it with columns of type string instead of enums.
Convert columns previously of type position enums to string enums.
Re-add the foreign keys to those columns.
At this point, no columns are using the position enums, drop enums.

For the down migration, the same logic applies but it changes the columns from type string back to type position enums.

Copy link
Member

Choose a reason for hiding this comment

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

Foreign keys do be a pain in the ass...

Copy link
Collaborator

@ruiichen ruiichen left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

Copy link
Member

@ericahan22 ericahan22 left a comment

Choose a reason for hiding this comment

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

looks good! column types are as described when running (and reverting) the migration

@mxc-maggiechen mxc-maggiechen merged commit 5345a50 into main Nov 19, 2025
1 check passed
@mxc-maggiechen mxc-maggiechen deleted the INTF25-drop-enums-from-database branch November 19, 2025 02:18
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.

3 participants