-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Fix migration v141 #14387
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
Merged
Merged
Fix migration v141 #14387
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5ca9235
Fix mig 141
6543 4e2b63d
Add Migration to fix it
6543 2579a16
update null values to false first
6543 f340581
Alter Table if posible
6543 d43a529
use dropTableColumns instead of recreateTable
6543 76cbc60
MySQL use Alter
6543 d339e41
Postgres use Alter
6543 a9c7a23
Update models/migrations/v167.go
6543 b9524f3
Apply suggestions from code review
6543 7ad2a22
use 2x add col & 2x update & 2x drop col
6543 f133ec7
Merge branch 'master' into fix-db-migration_141
6543 7b36b45
Merge branch 'master' into fix-db-migration_141
6543 74510e6
Merge branch 'master' into fix-db-migration_141
6543 6a7130c
let sqlite be the only issue
6543 0087076
use recreate since it just WORKS
6543 f934e44
Merge branch 'master' into fix-db-migration_141
6543 245b671
Merge branch 'master' into fix-db-migration_141
6543 c32e1b1
Merge branch 'master' into fix-db-migration_141
6543 2b9e079
Merge branch 'master' into fix-db-migration_141
6543 4f597ea
Merge branch 'master' into fix-db-migration_141
6543 70d8fe9
Merge branch 'master' into fix-db-migration_141
6543 b51ac5d
Merge branch 'master' into fix-db-migration_141
6543 c40e6bf
Merge branch 'master' into fix-db-migration_141
6543 5a7ca76
Merge branch 'master' into fix-db-migration_141
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright 2021 The Gitea Authors. All rights reserved. | ||
| // Use of this source code is governed by a MIT-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package migrations | ||
|
|
||
| import ( | ||
| "xorm.io/builder" | ||
| "xorm.io/xorm" | ||
| "xorm.io/xorm/schemas" | ||
| ) | ||
|
|
||
| func recreateUserTableToFixDefaultValues(x *xorm.Engine) error { | ||
| type User struct { | ||
| ID int64 `xorm:"pk autoincr"` | ||
| KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"` | ||
| TmpCol bool `xorm:"NOT NULL DEFAULT false"` | ||
| } | ||
|
|
||
| if _, err := x.Where(builder.IsNull{"keep_activity_private"}). | ||
| Cols("keep_activity_private"). | ||
| Update(User{KeepActivityPrivate: false}); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| switch x.Dialect().URI().DBType { | ||
6543 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
6543 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| case schemas.MYSQL: | ||
| _, err := x.Exec("ALTER TABLE `user` MODIFY COLUMN keep_activity_private tinyint(1) DEFAULT 0 NOT NULL;") | ||
| return err | ||
| case schemas.POSTGRES: | ||
| if _, err := x.Exec("ALTER TABLE `user` ALTER COLUMN keep_activity_private SET NOT NULL;"); err != nil { | ||
| return err | ||
| } | ||
| _, err := x.Exec("ALTER TABLE `user` ALTER COLUMN keep_activity_private SET DEFAULT false;") | ||
| return err | ||
| } | ||
6543 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
6543 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sess := x.NewSession() | ||
| defer sess.Close() | ||
| if err := sess.Begin(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := sess.Sync2(new(User)); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if _, err := sess.Exec("UPDATE `user` SET tmp_col=keep_activity_private;"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := dropTableColumns(sess, "user", "keep_activity_private"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := sess.Sync2(new(User)); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if _, err := sess.Exec("UPDATE `user` SET keep_activity_private=tmp_col;"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := dropTableColumns(sess, "user", "tmp_col"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return sess.Commit() | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.