aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-08-10 14:01:10 +0100
committerGitHub <noreply@github.com>2020-08-10 16:01:10 +0300
commitd87dbd751908051f1ca28c6658ef5170cfe8f214 (patch)
tree398218eb7ae761a4920e1d2df89ba68840c04601
parent02e990a89bcb1e55ea4b71f51cc5c24bfe11f885 (diff)
downloadgitea-d87dbd751908051f1ca28c6658ef5170cfe8f214.tar.gz
gitea-d87dbd751908051f1ca28c6658ef5170cfe8f214.zip
Fix Migration 145 on MSSQL if varchar is changed to nvarchar (#12445)
* Handle MSSQL constraints Signed-off-by: Andrew Thornton <art27@cantab.net> * Update models/migrations/v145.go * Prevent hang with Sync2 * Agh it's uniques not indexes * Let us try a different way of finding constraints on the language column Signed-off-by: Andrew Thornton <art27@cantab.net> * minor simplification Signed-off-by: Andrew Thornton <art27@cantab.net> * Try drop index instead? Signed-off-by: Andrew Thornton <art27@cantab.net>
-rw-r--r--models/migrations/v145.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/models/migrations/v145.go b/models/migrations/v145.go
index 436c95fab9..ee79c20e97 100644
--- a/models/migrations/v145.go
+++ b/models/migrations/v145.go
@@ -47,9 +47,31 @@ func increaseLanguageField(x *xorm.Engine) error {
return err
}
case setting.Database.UseMSSQL:
+ // Yet again MSSQL just has to be awkward.
+ // Here we have to drop the constraints first and then rebuild them
+ constraints := make([]string, 0)
+ if err := sess.SQL(`SELECT i.name AS Name
+ FROM sys.indexes i INNER JOIN sys.index_columns ic
+ ON i.index_id = ic.index_id AND i.object_id = ic.object_id
+ INNER JOIN sys.tables AS t
+ ON t.object_id = i.object_id
+ INNER JOIN sys.columns c
+ ON t.object_id = c.object_id AND ic.column_id = c.column_id
+ WHERE t.name = 'language_stat' AND c.name = 'language'`).Find(&constraints); err != nil {
+ return fmt.Errorf("Find constraints: %v", err)
+ }
+ for _, constraint := range constraints {
+ if _, err := sess.Exec(fmt.Sprintf("DROP INDEX [%s] ON `language_stat`", constraint)); err != nil {
+ return fmt.Errorf("Drop table `language_stat` constraint `%s`: %v", constraint, err)
+ }
+ }
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE language_stat ALTER COLUMN language %s", sqlType)); err != nil {
return err
}
+ // Finally restore the constraint
+ if err := sess.CreateUniques(new(LanguageStat)); err != nil {
+ return err
+ }
case setting.Database.UsePostgreSQL:
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE language_stat ALTER COLUMN language TYPE %s", sqlType)); err != nil {
return err