-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 broken v27 migration - change mirror interval from int to bigint #1504
Conversation
models/migrations/v29.go
Outdated
return err | ||
} | ||
|
||
_, err = x.Query("ALTER TABLE mirror MODIFY `interval` BIGINT;") |
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.
This might be better?
if engine.Dialect().DataSourceName() == "mysql" { engine.Exec("ALTER TABLE mirror MODIFY interval BIGINT"); }
But I guess the same fix need to be applied for Postgresql as well.
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.
Confirmed in Postgres #1505
models/migrations/v29.go
Outdated
_, err = x.Exec("ALTER TABLE mirror ALTER COLUMN `interval` SET DATA TYPE bigint") | ||
case "tidb": | ||
_, err = x.Exec("ALTER TABLE mirror MODIFY `interval` BIGINT") | ||
case "sqlite3": |
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.
missing mssql
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.
Added
models/migrations/v29.go
Outdated
|
||
switch dialect { | ||
case "mysql": | ||
_, err = x.Exec("ALTER TABLE mirror MODIFY `interval` BIGINT") |
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.
why not use sess.Exec
since we have in a transaction?
LGTM |
Doesn't this fix need also change in models/migrations/v27.go ? Since the failed migration will still occur on applying v27 before this migration ? |
In fact all this change should be done in v27 since normally failing migration would stop the migration and people would be in blocked in v26 ? |
|
Yes. I'm wrong. @cez81 You are right. You should change the migration v27 but not add a new one. |
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"INDEX"` | ||
Repo *Repository `xorm:"-"` | ||
Interval time.Duration |
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.
Are 5 fields being dropped here from the Mirror struct ? Is this intentional ? Would it affect database structure ?
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.
No, just don't need them during the migration. As I understand it Xorm will notice and warn but fields are still there. Same as repo struct above. It has more fields not listed.
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.
^
models/migrations/v27.go
Outdated
case "mysql": | ||
_, err = sess.Exec("ALTER TABLE mirror MODIFY `interval` BIGINT") | ||
case "postgres": | ||
_, err = sess.Exec("ALTER TABLE mirror ALTER COLUMN `interval` SET DATA TYPE bigint") |
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 dunno if XORM takes care of this @lunny but PostgreSQL quotes for identifiers should be doublequote, not backtick.
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.
Good catch, I haven't used PostgreSQL.
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.
Looks like SQL Server also uses doublequotes.
Mirror.interval column type needed to be changed to bigint. Correct interval where the interval set is < MinInterval.
62214aa
to
9994626
Compare
Rebased to pass Drone build |
LGTM |
Fix for #1496. Migration to v27 didn't alter the column type to bigint (#1407). This fix will alter the column type and set all mirror intervals that are < Mirror.MinInterval to Mirror.DefaultInterval.
Sqlite is ok because uses same integer type.