redash icon indicating copy to clipboard operation
redash copied to clipboard

Downgrading then upgrading redash schemas doesn't work

Open wlach opened this issue 10 months ago • 6 comments

Issue Summary

After updating to latest main (1672cd92801b2555b6a95a1c95e7b3328f0664d0) and then downgrading to a previous version, upgrading again doesn't work unless you do the following:

alter table queries alter schedule drop default;
alter table queries alter options drop default;
alter table events alter additional_properties drop default;
alter table organizations alter settings drop default;
alter table alerts alter options drop default;
alter table dashboards alter options drop default;
alter table dashboards alter layout drop default;
alter table changes alter change drop default;
alter table visualizations alter options drop default;
alter table widgets alter options drop default;

The problem seems to be that this migration sets a default on downgrade, where none existed before. When you try to add a json schema to that, redash aborts.

Additional gotcha:

The "schedule" column gets casted to the "null" string on downgrade. You need to do a manual:

update queries set schedule=null where schedule='null';

Looks like the migrations modified in the following PRs are the culprits:

https://github.com/getredash/redash/pull/6687 https://github.com/getredash/redash/pull/6707 https://github.com/getredash/redash/pull/6713

/cc @AndrewChubatiuk

wlach avatar Mar 28 '24 15:03 wlach

@wlach thanks for a finding could you please submit PR with a fix?

AndrewChubatiuk avatar Mar 28 '24 16:03 AndrewChubatiuk

@wlach thanks for a finding could you please submit PR with a fix?

Will see what I can do.

wlach avatar Mar 29 '24 13:03 wlach

Found an additional gotcha (schedule for queries can get set to the string "null" on downgrade), updated description.

wlach avatar Apr 01 '24 22:04 wlach

Oh, this all doesn't sound good.

Breaking the schema when downgrading is something we'd better fix.

The rough plan is to enable automatic schema upgrades when Redash starts (rather than a manual process). So being able to downgrade stuff when needed for some reason is probably pretty important.

justinclift avatar Apr 03 '24 11:04 justinclift

Yeah, it's a bit unfortunate -- I assume the alembic db migrations were automatically generated, and were just wrong in this case. I think we need to verify (via pg_dump or similar) that the schema is as you'd expect after an arbitrary number of upgrades and downgrades.

FWIW my testing setup is to do this to downgrade:

./manage.py db downgrade fd4fc850d7ea

And this to upgrade:

./manage.py db upgrade

wlach avatar Apr 03 '24 12:04 wlach

@wlach thanks for a finding could you please submit PR with a fix?

Will see what I can do.

Update: I haven't had time to look at this and am not sure when I will.

wlach avatar Apr 20 '24 11:04 wlach

@wlach This should be fixed in #7068, thanks to @ezraodio1. :smile:

justinclift avatar Jul 18 '24 21:07 justinclift