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

Update backfill migration to also set label in dataReceived column #1048

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

ktuite
Copy link
Member

@ktuite ktuite commented Nov 21, 2023

Closes getodk/central#540

I debated between adding a new migration that would fill in this data, or changing the old migration file. I decided to change the old migration file, the one that added baseVersion and that introduced the column dataReceived, to also populate the label field in dataReceived.

I was nervous about getting that change right so I wrote a test, but I've committed the code with the test skipped.

What has been done to verify that this works as intended?

A test.

Why is this the best possible solution? Were any other approaches considered?

I think this is tidier. The change is simple, it'll mean fewer migrations have to run on upgrade. The only downside is some of our test data may not have the label populated.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

no

Does this change require updates to the API documentation? If so, please update docs/api.md as part of this PR.

no

Before submitting this PR, please make sure you have:

  • run make test-full and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

@ktuite ktuite requested a review from matthew-white November 21, 2023 18:17
// Create two entity defs
await container.run(sql`
INSERT INTO entity_defs ("entityId", "createdAt", "creatorId", "current", "label", "data")
VALUES (${newEntity.id}, now(), 5, true, 'some label', '{"foo": "bar"}')`);
Copy link
Member

Choose a reason for hiding this comment

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

Seems like current should be false if another def is about to be created.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's not the best/most coherent entity def 😅 but at least current is not a relevant part of the migration.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will make these improvements in case anyone (future me?) decides to "borrow" this entity-insertion code in the future...

VALUES (${newEntity.id}, now(), 5, true, 'some label', '{"foo": "bar"}')`);

await container.run(sql`
INSERT INTO entity_defs ("entityId", "createdAt", "creatorId", "current", "label", "data", "version")
Copy link
Member

Choose a reason for hiding this comment

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

Should version be specified for both defs? The baseVersion of the first def will be null after the migration, but I think its version should be 1.

Copy link
Member Author

Choose a reason for hiding this comment

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

The column has a default value of 1, which I visually saw, and is how the baseVersion gets set to null.

@ktuite ktuite merged commit 46ce2f5 into master Nov 21, 2023
4 checks passed
@ktuite ktuite deleted the ktuite/data-received-migration branch November 21, 2023 19:37
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.

Database backfill of dataReceived does not include label
2 participants