-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
Execute all pending migrations regardless of their timestamp #1203
Execute all pending migrations regardless of their timestamp #1203
Conversation
76b5336
to
b28d053
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disclaimer: I'm not a maintainer of this project, I just wanted to share a small review :)
app/pkg/dbx/migrate.go
Outdated
for rows.Next() { | ||
var version int | ||
_ = rows.Scan(&version) | ||
dbVersionMap[version] = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I first had trouble understanding why you used a map "version => boolean" but I understood while writing my suggestion. I don't know about performances, but anyway I think this is not a big deal because the bottleneck of this function is the SQL request.
Here is my original suggestion:
Instead of using a temporary map, you can build the final array by removing versions already applied (found in the database).
You need to start from a copy of all versions:
pendingMigrations := slices.Clone(versions)
And then modify the loop as follow:
for rows.Next() { | |
var version int | |
_ = rows.Scan(&version) | |
dbVersionMap[version] = true | |
} | |
for rows.Next() { | |
var version int | |
_ = rows.Scan(&version) | |
i := slices.Index(pendingMigrations, version) | |
if i != -1 { | |
pendingMigrations = slices.Delete(pendingMigrations, i, i + 1) | |
} | |
} |
I think this simplifies a little bit the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also agree this is more readable, at the beginning, I started to implement the solution using slices
package and then I imagined that we don't want to import new package on this file, So I managed to find a solution without importing package 😅
I will refactor this part with slices
based on your suggestion 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a Go specialist, and I don't know the exact impact of importing a package. Because slices
is part of the standard library, and I guess is already used somewhere else in the project (or in any dependency), I imagine those functions were already included in the final executable. If not, it may be appropriate to do without them, indeed.
Thanks a lot @Quentinchampenois ! And also thanks for the review @indyteo 👍 I'll take a look at this soon :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Quentinchampenois - made a few suggestions, hopefully they all make sense.
@Quentinchampenois Forgot to mention - would be good if you could include some tests too (there is already a test file that should get you started - shout if you need any more help with this) |
133aef6
to
267a72b
Compare
Hello @mattwoberts thanks for the review and feedbacks ! I applied your suggestions from the change request, and I also added a new test, feel free to share feedback or ask for changes |
Co-authored-by: Matt Roberts <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Thanks @Quentinchampenois !
Nice, thank you both for your time ! |
FYI, I've had to revert this for now... When I deployed the change to our production server, I got loads of errors related to SQL migration files could not be run. When I looked into the existing migrations, there were loads of migrations not recorded in here, that the migrator logic was trying to run. It looks like the migration table and logic was added later on - so early SQL migrations (2017 / 18) didn't have a log of being run - causing all sorts of havoc. So - it's reverted out of main for now. I'm not sure what the best approach is to handle this - I suspect there will be many self hosters in a similar situation who would potentially break their instance with this migration code. |
Maybe you should try to get the exact date (based on migrations "versions" which are basically timestamps, by looking at the 1st that got recorded inside your database) at which the migration logic had been implemented, and add a condition here to ignore older migrations (except on 1st run, where all migrations should always run). The issue will be for instances that ran some migration (but not all) in 2017, before the actual system got implemented (i.e. no migration recorded but some tables found in database). And maybe the solution is just to abort because it requires human maintenance to find out the version of the database of the self-hosted instance... And it will probably not affects a lot of users anyway. Those users would face a similar issue anyway when upgrading to the actual system, because it would try to re-run old migrations as well, right? |
* Fix typo in `Welcome Message` section (getfider#1111) * fix: make linter happy again * chore: update playwright to fix build * more subdomain restrictions * feature: send welcome email on signup * fix: unencrypted smtp login * send welcome email * skip email on self hosted * update readme * typo * fix: postgres encoding error doing searches * fix: use hostname for powered by link * update to go 1.19 and node 18.x (getfider#1118) * fix: disallow external url during oauth login * fix: use non-breaking spaces for assertions * dont write to body when method is head * Scrollbars would always be visible in the `VotesModal` component (getfider#1134) * enhancement: add overflow-auto utility class * fix: auto remove scrollbars if there not necessary Before with overflow-scroll there where always two scrollbars, now it will change depending on the content of the container * fix error on cname lookup * use jwt to prevent redirect_uri changes * npm ci --maxsockets 1 * better validation for redirect * Update go to 1.22 * Node 18 -> 22 * Fix build script. * csrf middleware * Added migration to create missing posts.user_id index * Show email on the member listing * Only include email when listing the members. * lint fix. * fix: added an empty view query params checker and setting it to 'all' * Update golint-ci * More time for lint-server * feat: migrated form/Select class component to functional component (based this off of the form/Input component), changed the version in go.mod to 1.22 * Update FUNDING.yml Changed funding options * fix: added back 1.22.0 to go.mod * feat: add Arabic locales * Also publish on tag pushes. * chore(deps): bump ws Bumps and [ws](https://github.com/websockets/ws). These dependencies needed to be updated together. Updates `ws` from 8.4.2 to 8.18.0 - [Release notes](https://github.com/websockets/ws/releases) - [Commits](websockets/ws@8.4.2...8.18.0) Updates `ws` from 7.5.7 to 8.18.0 - [Release notes](https://github.com/websockets/ws/releases) - [Commits](websockets/ws@8.4.2...8.18.0) --- updated-dependencies: - dependency-name: ws dependency-type: indirect - dependency-name: ws dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * chore(deps-dev): bump @babel/traverse from 7.17.10 to 7.25.4 Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.17.10 to 7.25.4. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.25.4/packages/babel-traverse) --- updated-dependencies: - dependency-name: "@babel/traverse" dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * Another way to trigger on tag/releases. * Wasn't picking up the tag name properly * Trigger a build when we push to stable too. * chore(deps-dev): bump webpack from 5.72.0 to 5.94.0 Bumps [webpack](https://github.com/webpack/webpack) from 5.72.0 to 5.94.0. - [Release notes](https://github.com/webpack/webpack/releases) - [Commits](webpack/webpack@v5.72.0...v5.94.0) --- updated-dependencies: - dependency-name: webpack dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> * Userlist integration added - new signup will create company and user in userlist.com * Updating a user feeds into userlist * Updating the billing status in userlist. * Add test for the changes to billing lock function * Integration with user actions. * Lint and test fixes * Moved the action struct to a dto. * Updated the version of upload artifact * Updated the download-artifact too. * Tag the docker image correctly. * Go mod tidy * Ignorne pem files * chore(deps): bump golang.org/x/image Bumps [golang.org/x/image](https://github.com/golang/image) from 0.0.0-20211028202545-6944b10bf410 to 0.18.0. - [Commits](https://github.com/golang/image/commits/v0.18.0) --- updated-dependencies: - dependency-name: golang.org/x/image dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * chore(deps): bump json5 Bumps and [json5](https://github.com/json5/json5). These dependencies needed to be updated together. Updates `json5` from 2.2.1 to 2.2.3 - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](json5/json5@v2.2.1...v2.2.3) Updates `json5` from 1.0.1 to 2.2.3 - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](json5/json5@v2.2.1...v2.2.3) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * refactor: Update Contributing doc * refactor: Update broken link in Makefile * feature: add ability to copy comment link * fix(migration): Looks for pending migrations * refactor: Rewrite versions string * refactor: Get pending versions using slices * refactor: Copy versions slice to local variable * fix: Use pq.Array as SQL query param * fix: Close connection using defer statement * fix: Handle errors during version scan * test: Ensure migration will be executed even with past timestamp * lint: Fix typo in sql request in tests * test: Check error while fetching versions * lint: Light refactor * feat: Copy versions array to local var Co-authored-by: Matt Roberts <[email protected]> * Fixes getfider#1156 * Fix: No webhook message when post deleted with no comment. * Fixed tests, added one for no-comment-delete of post. * First set of proposed UI tweaks. * Fixing tests * Added missing description * Fixed tests for google font * Settings tweaks * My settings UI tweaks * More webhooks tweaks * No duplicate emails on the "show votes" * Fixed lint issue * WIP notifications modal. * Remove the paddle webhooks from CSRF checks. * Revert "Merge pull request getfider#1203 from Quentinchampenois/fix/pending_migrations" This reverts commit 42c9a98, reversing changes made to a9c05c5. * Fix: Can't access tenant from context in paddle webhook logic (but don't need to anyway) * Billing status should be forced to string * No need to log this * Changing to use matrix strategy for parallel builds * Notifications dropdown * Username component shouldn't show email unless explicitly requested * Formatting. * Revert "Changing to use matrix strategy for parallel builds" This reverts commit 55dfbc9. * Missing route * Margin bottom fixes * Some minor changes to the styles * Localised notifications modal * Locale files updated * Moved the userlist logic so it runs for social signups too. * Fixed previous userlist change. * Changed the email details for welcome emails. * No notifications improvements. * Console.logs removed * Formatting * More notification spacing tweaks * More styling, plus "mark all as read" * Borders in the notifications modal * Show posts mobile view. * Small tweaks to the powered by link * Changed how google fonts are included. * Order notifications by date desc * Messing about with reactions * Working reactions UI and backend * Lint checks * Viewing reactions for anonymous users * Sort the reactions by count * Make comments stand out more Techincally this is part of the UI stuff, but it stands out when you have the reactions in there so adding it here. * More tests * Validate that the reaction is one of the allowed emoji responses. * Update Dockerfile to Debian Bookworm and NodeJS 22 * Update gomarkdown/markdown dependency * Changed some bits on the main readme. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Matthew Yarmolinsky <[email protected]> Co-authored-by: goenning <[email protected]> Co-authored-by: Ik <[email protected]> Co-authored-by: Matt Roberts <[email protected]> Co-authored-by: mway-niels <[email protected]> Co-authored-by: Brian Pham <[email protected]> Co-authored-by: Dinh Nguyen Pham <[email protected]> Co-authored-by: Maher El Gamil <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: quentinchampenois <[email protected]> Co-authored-by: indyteo <[email protected]> Co-authored-by: Kim Tiago Baptista <[email protected]>
@mattwoberts sorry to learn it caused troubles ! |
Description
Hello,
At the moment, pending migrations are only executed if the version number is more recent than the last migration version.
This PR aims to find all pending migrations present in filesystem regardless of their timestamp before executing them.
Notes
Feel free to give feedback, ask for changes or share good practice with go 👍
Thanks !