gastownhall/beads · error

reading SHOW CREATE TABLE

Error message

reading SHOW CREATE TABLE %s: %w

What it means

Wraps a failure to run and read SHOW CREATE TABLE for a table. This is the only way Dolt exposes generated-column shape — INFORMATION_SCHEMA.COLUMNS returns EXTRA and GENERATION_EXPRESSION empty for generated columns — so wispDepHasStoredGeneratedDependsOnID depends on it. Thrown when the query fails or the row cannot be scanned (e.g., the table does not exist at call time).

Solutions

  1. Confirm the table still exists before calling (or re-run the repair, which re-checks presence).
  2. Inspect the wrapped driver error; restore connectivity if the server is down.
  3. If the table genuinely does not exist and the repair expected it, determine whether a prior migration step already replaced it — re-running the repair flow should take the correct branch.
  4. Check Dolt server version supports SHOW CREATE TABLE output with generated-column expression.
Defensive patterns

Strategy: validation

Validate before calling

// ensure the table exists before asking for its DDL
exists, err := schemaTableExists(ctx, db, table)
if err != nil || !exists { /* skip SHOW CREATE TABLE path */ }

Type guard

func isMissingTableErr(err error) bool {
    return strings.Contains(err.Error(), "doesn't exist") || strings.Contains(err.Error(), "not found")
}

Try / catch

ddl, err := schemaShowCreateTable(ctx, db, table)
if err != nil {
    if isMissingTableErr(err) { return nil /* table already replaced/dropped */ }
    return err
}

Prevention

When it happens

Trigger: SHOW CREATE TABLE `<table>` errors: the table was dropped between the existence check and this call, the server is down, or the Scan into (name, ddl) fails because no row was returned.

Common situations: Race where a concurrent migration drops/renames the table mid-repair; querying a database where the table never existed because the caller skipped the presence check; connection failure.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/bca2ed949fe911fc. Report an issue: GitHub.

Appendix: source

Thrown at internal/storage/schema/migration_repairs.go:745

	if err := db.QueryRowContext(ctx, `
		SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
		WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND CONSTRAINT_NAME = ?
	`, table, constraint).Scan(&count); err != nil {
		return false, fmt.Errorf("checking constraint %s on %s: %w", constraint, table, err)
	}
	return count > 0, nil
}

// schemaShowCreateTable returns a table's CREATE statement. It is the only
// place Dolt exposes generated-column shape: INFORMATION_SCHEMA.COLUMNS returns
// EXTRA and GENERATION_EXPRESSION empty for a generated column, and IS_GENERATED
// does not exist there at all.
func schemaShowCreateTable(ctx context.Context, db DBConn, table string) (string, error) {
	var name, ddl string
	// table is a package constant, never caller input; SHOW CREATE TABLE takes
	// no placeholders.
	if err := db.QueryRowContext(ctx, "SHOW CREATE TABLE `"+table+"`").Scan(&name, &ddl); err != nil {
		return "", fmt.Errorf("reading SHOW CREATE TABLE %s: %w", table, err)
	}
	return ddl, nil
}

// schemaColumnInPrimaryKey reports whether column is (one of) table's PRIMARY
// KEY column(s) specifically -- distinct from schemaHasPrimaryKey, which only
// says a primary key exists without saying which column(s) it covers.
func schemaColumnInPrimaryKey(ctx context.Context, db DBConn, table, column string) (bool, error) {
	var count int
	if err := db.QueryRowContext(ctx, `
		SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
		WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ? AND CONSTRAINT_NAME = 'PRIMARY'
	`, table, column).Scan(&count); err != nil {
		return false, err
	}
	return count > 0, nil
}

View on GitHub (pinned to 71377f2769)