openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.12k stars 724 forks source link

Add scripts to save and restore baseline data #12947

Closed mkllnk closed 3 weeks ago

mkllnk commented 1 month ago

What? Why?

Sometimes a staging database gets changed by pull requests which are not finished yet. Those changes should be reverted and some of these changes may actually break the application. So here are a couple of scripts for testers to execute on the server.

What should we test?

# Log into the staging server with ssh and run these:
~/apps/openfoodnetwork/current/script/ci/save-staging-baseline.sh
~/apps/openfoodnetwork/current/script/ci/restore-staging-baseline.sh

Release notes

Changelog Category (reviewers may add a label for the release notes):

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

filipefurtad0 commented 3 weeks ago

Hey @mkllnk ,

Thanks for this. Maybe a good way to verify all works as expected, could be to:

Then, I think we could test for two distinct scenarios: i) create some test data - like a new order or user ii) run a migration which could break things somehow, or just change the DB structure somehow

Then finally, run ~/apps/openfoodnetwork/current/script/ci/restore-staging-baseline.sh

And verify changes i) and ii) are correctly reverted.

I'll give this a try.

filipefurtad0 commented 3 weeks ago

Staging failed in staging-UK:

https://github.com/openfoodfoundation/openfoodnetwork/actions/runs/11620487686

But worked for staging-FR:

https://github.com/openfoodfoundation/openfoodnetwork/actions/runs/11620645440

Running the command for saving the baseline, took a couple of minutes to complete, and yielded:

Last login: Wed Oct 30 21:50:00 2024 from 220.253.199.227
openfoodnetwork@vps-2a25f087:~$ ~/apps/openfoodnetwork/current/script/ci/save-staging-baseline.sh
Staging baseline data saved.

Making changes:

After running the restore command:

Yielded quite a lot of output, among which these lines:

ERROR:  permission denied to create extension "pg_stat_statements"
HINT:  Must be superuser to create this extension.
ERROR:  extension "pg_stat_statements" does not exist

And ended with:

ERROR:  must be member of role "postgres"
ERROR:  must be member of role "postgres"
ERROR:  must be member of role "postgres"
ERROR:  must be member of role "postgres"
ERROR:  must be member of role "postgres"
ERROR:  must be member of role "postgres"
Staging baseline data restored.

Checked that:

Looking great!! :tada:

Merging.