mattermost / migration-assist

A helper tool to automate MySQL -> Postgres migration for Mattermost
https://docs.mattermost.com/deploy/postgres-migration.html
2 stars 2 forks source link

[MM-60328] include proper search_path check to post-migrate #26

Closed isacikgoz closed 1 month ago

isacikgoz commented 2 months ago

Summary

After every migration, we should advise running migration-assist post-migrate command to determine the health of the DB in terms of schema and it's ownership.

Also make index creation optional. Will add documentation accordingly.

Ticket Link

https://mattermost.atlassian.net/browse/MM-60328

galtom commented 2 months ago

This "bug" affected me, and after hours of search I found the solution. Whet the migration finished I tried to start Mattermost, but it is failed because SELECT CURRENT_SCHEMA(); SQL command returned nothing:

mattermost=> SELECT CURRENT_SCHEMA();
 current_schema
----------------

(1 row)

The SEARCH_PATH looked liked this:

mattermost=> SHOW SEARCH_PATH;
     search_path
---------------------
 """$user"", public"
(1 row)

But it is wrong. To make it work, I had to set by hand the it as postgres user:

ALTER ROLE mmuser SET search_path = "$user", public;

After that, this is what the SEARCH_PATH and CURRENT_SCHEMA() looked like:

mattermost=# SELECT CURRENT_SCHEMA();
 current_schema
----------------
 public
(1 row)

mattermost=# SHOW SEARCH_PATH;
   search_path
-----------------
 "$user", public
(1 row)
isacikgoz commented 1 month ago

@agnivade Since migration-assist itself is not running pgloader, the idea here is to use migration-assist post-migrate as a safety check, after pgloader runs. That's why I made the index creation rely on the CLI flag. There will be a doc update to recommend checking whether they need to look into fixes. But I think new CheckPostgresSchemaOwnership implementation should fix the issue regardless.

agnivade commented 1 month ago

That's why I made the index creation rely on the CLI flag.

So to clarify: this schema check is only needed to run the index creation? I thought this was there as a sanity check to run Mattermost later?

isacikgoz commented 1 month ago

@agnivade nope, I mean this command will run (at least we'll advise that) after whenever a pgloader execution happens.