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

Migration for PR #5660 #5664

Closed
wants to merge 5 commits into from
Closed

Migration for PR #5660 #5664

wants to merge 5 commits into from

Conversation

flozia
Copy link
Collaborator

@flozia flozia commented Feb 26, 2025

References:

PR: #5660
Jira: MNTOR-4065

Description

Migration file for PR #5660 that is adding new optional columns to onerep_profiles.

Screenshot (if applicable)

Not applicable.

How to test

  • Run npm run db:migrate: The table onerep_profiles should contain the applied changes.
  • Run npm run db:rollback: The table onerep_profiles should have its initial state.

Copy link

@flozia flozia force-pushed the mntor-4065-migrations branch 2 times, most recently from 516c52c to 855444a Compare February 26, 2025 12:55
@flozia flozia removed request for rhelmer and mansaj February 26, 2025 13:07
@flozia flozia marked this pull request as draft February 26, 2025 13:07
@flozia flozia marked this pull request as ready for review February 26, 2025 13:13
@flozia flozia force-pushed the mntor-4065-migrations branch from bbbb69d to 0340c6c Compare February 26, 2025 13:16
@flozia flozia requested review from Vinnl, rhelmer and mansaj February 26, 2025 13:17
export function up(knex) {
return knex.schema.alterTable("onerep_profiles", async (table) => {
table
.specificType("first_names", "character varying(255)[]")
Copy link
Collaborator

Choose a reason for hiding this comment

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

With backend/DB design not being my speciality, I don't want to have a strong opinion here, but I suppose the following are reasons why it's OK to use array types and JSON rather than the more cumbersome foreign tables:

  • We don't care about DBMS portability,
  • we won't be selecting rows based on the contents of these columns,
  • we'll rarely write to these columns, and
  • when we do write to them, we'll often update all elements in one go.

Writing this down more for myself, but happy to learn if anyone has corrections or additions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I’ve considered adding a new table, but that might be too much overhead. We are already using jsonb in a couple of places. That means:

  • we don’t have DBMS portability either way
  • I don’t anticipate that we need to select rows based on these columns
  • writing to those columns happens only if users update their profile info
  • we only update the elements in those columns all at once

Comment on lines 55 to 62
table.dropColumns(
"first_names",
"last_names",
"middle_names",
"phone_numbers",
"addresses",
);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rolling back the migration doesn't actually drop these columns for me...

Copy link
Collaborator

@Vinnl Vinnl Feb 26, 2025

Choose a reason for hiding this comment

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

They do if I remove the knex.raw above. Possibly that should not be part of the alterTable function? (And that function then needn't be async?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this @Vinnl! I made this change only when splitting out this migration PR and checked the wrong version of my local table. Updated in a272232. Is it now also working as expected for you?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, works now!

@flozia flozia requested a review from Vinnl February 26, 2025 15:27
Copy link
Collaborator

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

I was now able to run this migration, and on rollback I saw the data getting carried over from the new columns to the old ones :shipit:

Comment on lines 55 to 62
table.dropColumns(
"first_names",
"last_names",
"middle_names",
"phone_numbers",
"addresses",
);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, works now!

Copy link
Collaborator

@rhelmer rhelmer left a comment

Choose a reason for hiding this comment

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

I wish we didn't need so much knex.raw here, but I agree that we're not aiming to be RDBMS-agnostic at all, and arrays are a very useful feature of Postgres.

The code looks fine but my main concern is how this is tested, we should have a plan for how to test this on stage.

I'm a little worried about the rollback down function, we should make sure to test that thoroughly. It would be far easier to roll back than to restore a database backup, but I really don't want to have to use it.

@flozia
Copy link
Collaborator Author

flozia commented Mar 6, 2025

@rhelmer @Vinnl I’m moving the migration of the addresses column to the separate PR #5688 so #5660 is not blocked.

@flozia flozia requested review from Vinnl and rhelmer March 6, 2025 13:28
Copy link
Collaborator

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

👍

@flozia
Copy link
Collaborator Author

flozia commented Mar 10, 2025

Closed in favor of PR #5696 to workaround the stuck Deploy Preview Action as suggested by @mansaj.

@flozia flozia closed this Mar 10, 2025
Copy link

Cleanup completed - database 'blurts-server-pr-5664' destroyed, cloud run service 'blurts-server-pr-5664' destroyed

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