-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add command to recreate tables #12407
Conversation
Provides new command: `gitea doctor recreate-table` which will recreate db tables and copy the old data in to the new table. This function can be used to remove the old warning of struct defaults being out of date. Fix go-gitea#8868 Fix go-gitea#3265 Fix go-gitea#8894 Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Of course mssql is being awkward so let's see if shortening the temp table name a little helps |
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Gave it a try:
For example. Table
Log of `./gitea doctor recreate-table topic`
|
It won't appear in --list as it is not a doctor check |
You've got so many warnings there it's impossible to tell if this is failing. You should see the warnings once as the db is initialised. Three second time round they should disappear. Just run Xorm is recreating the tables here so it should get the defaults right so if it doesn't the there is a bug in xorm. |
It does seem to run sucessful, but no matter how many time I run, it does not get rid of the
|
Codecov Report
@@ Coverage Diff @@
## master #12407 +/- ##
==========================================
- Coverage 43.42% 43.29% -0.13%
==========================================
Files 648 648
Lines 71581 71760 +179
==========================================
- Hits 31081 31071 -10
- Misses 35470 35660 +190
+ Partials 5030 5029 -1
Continue to review full report at Codecov.
|
Signed-off-by: Andrew Thornton <art27@cantab.net>
Copying from other PR. It still doesn't quite do it for me (MariaDB 10.5.5):
|
@silverwind OK having looked a bit more in to that that's a bug of Xorm. The issue is: func (session *Session) Sync2(beans ...interface{}) error {...} Calls: func (db *mysql) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {...} Which calls func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey bool) (string, error) {...} which at: if col.Default != "" {
if _, err := bd.WriteString("DEFAULT "); err != nil {
return "", err
}
if _, err := bd.WriteString(col.Default); err != nil {
return "", err
}
if err := bd.WriteByte(' '); err != nil {
return "", err
}
} skips out the Default if it's empty. However this conflicts with later parts of Sync2, in particular: if col.Default != oriCol.Default {
switch {
case col.IsAutoIncrement: // For autoincrement column, don't check default
case (col.SQLType.Name == schemas.Bool || col.SQLType.Name == schemas.Boolean) &&
((strings.EqualFold(col.Default, "true") && oriCol.Default == "1") ||
(strings.EqualFold(col.Default, "false") && oriCol.Default == "0")):
default:
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
tbName, col.Name, oriCol.Default, col.Default)
}
} Where func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
args := []interface{}{db.uri.DBName, tableName}
s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," +
" `COLUMN_KEY`, `EXTRA`,`COLUMN_COMMENT` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?" +
" ORDER BY `INFORMATION_SCHEMA`.`COLUMNS`.ORDINAL_POSITION"
rows, err := queryer.QueryContext(ctx, s, args...)
if err != nil {
return nil, nil, err
}
defer rows.Close()
cols := make(map[string]*schemas.Column)
colSeq := make([]string, 0)
for rows.Next() {
col := new(schemas.Column)
col.Indexes = make(map[string]int)
var columnName, isNullable, colType, colKey, extra, comment string
var colDefault *string
err = rows.Scan(&columnName, &isNullable, &colDefault, &colType, &colKey, &extra, &comment)
if err != nil {
return nil, nil, err
}
col.Name = strings.Trim(columnName, "` ")
col.Comment = comment
if "YES" == isNullable {
col.Nullable = true
}
if colDefault != nil {
col.Default = *colDefault
col.DefaultIsEmpty = false
} else {
col.DefaultIsEmpty = true
}
... |
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
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.
Tested with latest XORM update against MariaDB, working fine from a functional perspective.
Signed-off-by: Andrew Thornton <art27@cantab.net>
make lg-tm work |
Provides new command:
gitea doctor recreate-table
which will recreatedb tables and copy the old data in to the new table.
This function can be used to remove the old warning of struct defaults being
out of date.
Fix #8868 - at least partially - there is a bug in Xorm see #12407 (comment)
Fix #3265
Fix #8994
Signed-off-by: Andrew Thornton art27@cantab.net