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

Fix MySQL database migration 0.21.0 -> 0.22.0 #3350

Merged
merged 3 commits into from
May 12, 2024
Merged

Conversation

leo9800
Copy link
Contributor

@leo9800 leo9800 commented May 12, 2024

This pull request addresses #3348, which implements the fix I worked out, mentioned in the issue.

SQLite migrations and PostgreSQL migrations seems to be fine, as they are not trying DROPping non-exist columns.

Besides, a version bump (e.g. 0.22.0 -> 0.22.1) is suggested to aware the downstream users to upgrade.

@leo9800 leo9800 requested a review from boojack as a code owner May 12, 2024 02:08
@wzc90
Copy link
Contributor

wzc90 commented May 12, 2024

In MySQL versions prior to 8.0.16, the ALTER TABLE ... DROP COLUMN IF EXISTS syntax is not supported. However, starting from MySQL version 8.0.16 and onward, the IF EXISTS clause is supported to conditionally drop a column only if it exists, which prevents errors from occurring when the specified column does not exist.

So, if you are using MySQL 8.0.16 or later, the statement:

ALTER TABLE `memo` DROP COLUMN IF EXISTS `tags`;

will work as expected, and it will drop the tags column if it exists without causing an error. If you are using an older version of MySQL, this statement would result in an error, and you would need to use a different approach to check for the existence of the column before attempting to drop it.

So the best approach is to directly remove this line of code. @boojack @leo9800

@@ -1,4 +1,4 @@
ALTER TABLE `memo` ADD COLUMN `tags_temp` JSON;
UPDATE `memo` SET `tags_temp` = '[]';
ALTER TABLE `memo` DROP COLUMN `tags`;
ALTER TABLE `memo` DROP COLUMN IF EXISTS `tags`;
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this line as it shouldn't exist.

@boojack boojack merged commit 93e8fa4 into usememos:main May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants