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

[WARN] Table repository Column <table> default is NULL, struct default is #8868

Closed
2 of 7 tasks
samangh opened this issue Nov 7, 2019 · 3 comments · Fixed by #12407 or #12694
Closed
2 of 7 tasks

[WARN] Table repository Column <table> default is NULL, struct default is #8868

samangh opened this issue Nov 7, 2019 · 3 comments · Fixed by #12407 or #12694
Labels
status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR type/upstream This is an issue in one of Gitea's dependencies and should be reported there

Comments

@samangh
Copy link

samangh commented Nov 7, 2019

  • Gitea version (or commit ref): 1.9.5 built with GNU Make 4.1, go1.12.11 : bindata, sqlite, sqlite_unlock_notify
  • Operating system: Debian Stable
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant

Description

Upon starting gitea, I get a large number of Table repository Column <table> default is NULL, struct default is errors.

This maybe related #3265.

Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column full_name db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column keep_email_private db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column must_change_password db default is 0, struct default is false
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column login_type db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column login_name db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column type db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column location db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column website db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column rands db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column salt db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column language db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column description db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column created_unix db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column updated_unix db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column last_login_unix db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column last_repo_visibility db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column is_active db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column is_admin db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column allow_git_hook db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column allow_import_local db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column allow_create_organization db default is 1, struct default is true
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column prohibit_login db default is 0, struct default is false
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column use_custom_avatar db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column num_followers db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column num_stars db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column num_repos db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column num_teams db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column num_members db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column diff_view_style db default is '''', struct default is ''
Nov  6 14:34:20 server gitea[21171]: [WARN] Table user Column theme db default is '''', struct default is ''
Nov  6 14:34:20 server gitea[21171]: [WARN] Table public_key Column created_unix db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table public_key Column updated_unix db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table access_token Column uid db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table access_token Column name db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table access_token Column token_hash db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table access_token Column token_salt db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table access_token Column token_last_eight db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table access_token Column created_unix db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table access_token Column updated_unix db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table repository Column owner_id db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table repository Column description db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table repository Column website db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table repository Column default_branch db default is 'NULL', struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table repository Column num_watches db default is NULL, struct default is
Nov  6 14:34:20 server gitea[21171]: [WARN] Table repository Column num_stars db default is NULL, struct default is
@samangh samangh changed the title Table repository Column <table> default is NULL, struct default is [WARN] Table repository Column <table> default is NULL, struct default is Nov 7, 2019
@lunny lunny added the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Nov 7, 2019
@lunny
Copy link
Member

lunny commented Nov 7, 2019

This maybe an issue of xorm.

@ltguillaume
Copy link

Is there anything I should do about this manually?

zeripath added a commit to zeripath/gitea that referenced this issue Aug 2, 2020
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>
@zeripath
Copy link
Contributor

OK at least part of this is a bug of xorm.

The issue is: xorm.io/xorm/session_schema.go:228

func (session *Session) Sync2(beans ...interface{}) error {...}

Calls: xorm.io/xorm/dialects/mysql.go:517

func (db *mysql) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {...}

Which calls xorm.io/xorm/dialects/dialect.go:227

func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey bool) (string, error) {...}

which at: xorm.io/xorm/dialects/dialect.go:261

	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: xorm.io/xorm/session_schema.go:353

			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 oriCol.Default is read in as "NULL" if has not been specified, at: xorm.io/xorm/dialects/mysql.go:308

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
		}
...

@lunny lunny added the type/upstream This is an issue in one of Gitea's dependencies and should be reported there label Aug 30, 2020
zeripath added a commit that referenced this issue Sep 6, 2020
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 #8868
Fix #3265
Fix #8894

Signed-off-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR type/upstream This is an issue in one of Gitea's dependencies and should be reported there
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants