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

Integrate morph into the plugin #619

Merged
merged 5 commits into from
May 29, 2024
Merged

Integrate morph into the plugin #619

merged 5 commits into from
May 29, 2024

Conversation

mgdelacroix
Copy link
Member

Summary

This PR integrates morph into the plugin store code, moving all migrations to SQL files, splitting them for improved clarity and structure. It creates a new msteamssync_system_settings table that stores one row per data migration, allowing them to indicate when they've run and removing the need for checking the database status every time the plugin starts to see if each data migration should run.

The Migrate method implements a sequence of migrations that ensures that at every step all the requirements of the next migration are met or checked (either by morph or the data migration through the previously mentioned table), and every step logs when the migration starts, stops and the elapsed time.

@mgdelacroix mgdelacroix added the 2: Dev Review Requires review by a core committer label Apr 20, 2024
@mgdelacroix mgdelacroix force-pushed the integrate-morph branch 4 times, most recently from 4176f52 to 7ad31c9 Compare April 20, 2024 01:27
@mgdelacroix mgdelacroix marked this pull request as ready for review May 17, 2024 11:47
Copy link
Member

@lieut-data lieut-data left a comment

Choose a reason for hiding this comment

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

Thanks, @mgdelacroix! Besides the few comments below, wondering if we "need" 15 separate migrations or if we could just have a single monolithic migration to get us "up to date", and start adding new ones discretely thereafter?

}
currentVersion := len(applied)

s.api.LogDebug("== Ensuring migrations applied up to version ====================", "version", version, "current_version", currentVersion)
Copy link
Member

Choose a reason for hiding this comment

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

This is unrelated to this PR, but I've always found it odd that the morph logs are formatted (i.e. with ====... as it they were being consumed by a user at a console, when instead we mostly see them as messages inside server logs. 0/5

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, the idea was to make all migration logs (inside and outside of morph) similar, but we can change the ones that come from the store to avoid the padding and the =s if we want, 0/5 really on my side

return mErr
}

if remoteID != "" {
Copy link
Member

Choose a reason for hiding this comment

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

As I recall, these are data migrations that require running code vs. just SQL. Is the idea to continue to append to this method as such migrations are required, or in the long run would we split apart the two concepts (schema vs data)? I realize that would require some finagling given the need to run some data migrations "between" others.

@jespino, is this some shared channels complexity would could eliminate if we required users adopting two way sync to "reset" somehow?

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 think we will always need some sort of sequential process to be able to run data migrations in between the plain SQL ones. The idea with the ensureMigrationsAppliedUpToVersion + the constants that indicate the version needed for a data migration is to model that sequence and make it simple to follow and expand, but if we can find a way to get rid of it, I'd love to give it a try.

At some point we discussed making morph aware of data migrations, so the sequence was enforced by the migration system directly, but that's just an idea at this point.

@@ -0,0 +1 @@
SELECT 1;
Copy link
Member

Choose a reason for hiding this comment

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

nit: could morph just treat an empty file as a no-op?

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh, actually having an empty file is only a problem for MySQL, Postgres will process those perfectly, so I'm making that change

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 3225998

@mgdelacroix
Copy link
Member Author

@lieut-data we could do one big "init" migration only, but there are two downsides that I can think of:

  • There are some data migrations that can only run in an intermediate state, I'm thinking specifically on the whitelisted_users data migration, that we run just before migration 14, which deletes the table. We could have two steps then, or ask current plugin users to follow an update plan (so they update to the last version before morph, run the plugin and then update to the first version including it, for example), but that's added complexity.
  • The migration will run as a single big transaction for instances that already have the plugin installed. The queries are thought to be no-ops for the current last version of the plugin's database, but if something unexpected happens, I think we'd be in a better situation having small steps to rollback and rerun.

They had a simple `SELECT 1` before because that's what we've done in
other instances as we had to support MySQL. Postgres is able to
process empty migrations, so as the plugin only supports running on
Postgres, the files are now empty.
@mgdelacroix
Copy link
Member Author

/update-branch

@mgdelacroix mgdelacroix requested a review from sbishel May 24, 2024 09:51
Copy link
Member

@sbishel sbishel left a comment

Choose a reason for hiding this comment

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

Nice to get this in.

@mgdelacroix mgdelacroix merged commit d674879 into main May 29, 2024
9 checks passed
@mgdelacroix mgdelacroix deleted the integrate-morph branch May 29, 2024 14:54
@mgdelacroix mgdelacroix added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants