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

78 - Fix checksum migration issue #79

Merged
merged 6 commits into from
May 7, 2021
Merged

Conversation

mrsarm
Copy link
Contributor

@mrsarm mrsarm commented Apr 29, 2021

Issue: #78

Rollback changes in immutable migration file and applied intended changes in new SQL script:

  • Migrations files are signed with a md5 sum in the DB to avoid modifications. The SQL file was restored to its original state.
  • The changes were moved to a new a script, but because is not possible to add a new column to a materialized view, the change was applied recreating the view.
  • The changes to the view raw_contacts that was rolled back was redundant, because the same migration to add 'contact' to the list of values for doc->>'type' was added in an earlier migration script.
  • Add a section "Known issues" with a workaround in case somebody did started a fresh database with v3.2.0 and wants to avoid the same migration issue once it tries to upgrade to an upcoming version. Also add another workaround for a unresolved issue with a library when is installed.

…nges in new SQL script

- Migrations files are signed with a md5 sum in the DB to avoid modifications. The SQL file was restored to its original state
- The changes were moved to a new a script, but because is not possible to add a new column to a materialized view, the change was applied recreating the view
- The changes to the view `raw_contacts` that was rolled back was redundant, because the same migration to add 'contact' to the list of values for `doc->>'type'` was added in an earlier migration script
@mrsarm mrsarm requested a review from dianabarsan April 29, 2021 20:03
Copy link
Member

@dianabarsan dianabarsan left a comment

Choose a reason for hiding this comment

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

Great work!
I added a few small requests inline, but mostly around documentation and comments.

README.md Outdated Show resolved Hide resolved


## Known issues
Copy link
Member

Choose a reason for hiding this comment

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

We should really have a release-notes.md to contain this information, instead of the readme.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. @garethbowen do you want me to prepare a new PR for the release ? I can create there the release note file and move this content. The release version should be 3.2.1, right?

README.md Outdated Show resolved Hide resolved
-- NOTE: The recreation of the view above caused 4 other views to be dropped in cascade,
-- here are the scripts to recreate them:

CREATE VIEW contactview_hospital AS
Copy link
Member

Choose a reason for hiding this comment

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

Super sad we have to have all this duplicated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, next time we use Postgrator to mantain views, may be better to use *.js script to reuse better the SQL scripts.

Also it is sad that Postgres does not allow to add a column in a view without the need to recreate it manually, whether the engine needs to recreate the entirely view or not, it should be an internal decision made by the engine.

Copy link
Member

Choose a reason for hiding this comment

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

I actually read a little around this, and people were complaining that they can't update materialized views in pgadmin - which is arguably probably even more popular than Postgrator. It could be pgadmin has improved since those posts though, but my point is that this seems like it is a common problem with other pg tools and not something that's easily automated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes the problem is that Postgres does not support ALTER VIEW xxx ADD COLUMN ... like in tables does. It does allow to do some ALTER changes but the most basic one that is to add a column is not supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... and my point is that even if that is not possible without the recreation of the whole materialized view, that should be an implementation detail for the engine, not for the user, Postgres could support ALTER VIEW xxx ADD COLUMN ... syntax, adding a note in the documentation, like: if you add a column in a materialized view internally the engine will recreate the whole view and dependent views and indexes, and that can take a while, use with precaution ...

Copy link
Member

Choose a reason for hiding this comment

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

yea, I agree it's a less then ideal situation.


-- NOTE: The recreation of the view above caused 4 other views to be dropped in cascade,
-- here are the scripts to recreate them:

Copy link
Member

Choose a reason for hiding this comment

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

I think we should link to the original migration that created each of these (including the line numbers). Something like: https://github.com/medic/medic-couch2pg/blob/master/libs/analytics/migrations/201711071603.do.2635-removeNestedContactReferences.sql#L26

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes better to keep track of that, adding...

@mrsarm mrsarm merged commit baaaf21 into master May 7, 2021
@mrsarm mrsarm deleted the 78-fix-checksum-migration-issue branch May 13, 2021 14:35
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.

2 participants