beekeeper-studio/beekeeper-studio · error

reorderColumns must be added via a subclass

Error message

reorderColumns must be added via a subclass

What it means

reorderColumns on ChangeBuilderBase is intentionally a stub that throws — column reordering is not universally supported by SQL dialects, so only subclasses for dialects that support it (e.g. MySQL) implement it. Calling it on a base/dialect that lacks an override hits this error.

Source

Thrown at apps/studio/src/shared/lib/sql/change_builder/ChangeBuilderBase.ts:253

    const result = `
      ALTER TABLE ${fromTable}
      ADD CONSTRAINT ${fkName}
      FOREIGN KEY (${fromColumn})
      REFERENCES ${toTable} (${toColumn})
      ${onUpdate}
      ${onDelete}
    `
    return result
  }

  createRelations(specs: CreateRelationSpec[]): string | null {
    if (!specs?.length) return null
    return specs.map((spec) => this.singleRelation(spec)).join(";")
  }

  // shouldn't be abstract because not all clients support reordering a column
  reorderColumns(_oldColumnOrder: ExtendedTableColumn[], _newColumnOrder: ExtendedTableColumn[]): string {
    throw new Error('reorderColumns must be added via a subclass')
  }

  dropRelations(names: string[]): string | null {
    if (!names?.length) return null

    return names.map((name: string) => {
      const t = this.tableName
      const c = this.wrapIdentifier(name)
      return `ALTER TABLE ${t} DROP CONSTRAINT ${c}`
    }).join(";")
  }
}

View on GitHub (pinned to 4e3e03e322)

Solutions

  1. Check dialect support before calling: only call reorderColumns for dialects that implement it
  2. Implement reorderColumns in a subclass for dialects that support it
  3. Fall back to a full table rebuild/recreate flow for dialects without native support

Example fix

// before
const sql = builder.reorderColumns(oldOrder, newOrder); // throws on unsupported dialects
// after
const sql = builder.supportsColumnReorder
  ? builder.reorderColumns(oldOrder, newOrder)
  : null;
Defensive patterns

Strategy: fallback

Validate before calling

const supportsReorder = builder.constructor !== ChangeBuilderBase || builder.reorderColumns !== ChangeBuilderBase.prototype.reorderColumns;
if (!supportsReorder) return null;

Type guard

function supportsReorder(builder) { return typeof builder.reorderColumns === 'function' && builder.reorderColumns !== ChangeBuilderBase.prototype.reorderColumns; }

Try / catch

try {
  return builder.reorderColumns(oldOrder, newOrder);
} catch (e) {
  if (e.message.includes('reorderColumns must be added via a subclass')) {
    return rebuildTableForReorder(builder, oldOrder, newOrder); // recreate-table fallback
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking table column reordering against a dialect whose ChangeBuilder doesn't override reorderColumns (e.g. SQLite, Cassandra); generic table-edit code assuming all dialects support reordering.

Common situations: Feature-flagged UI showing drag-to-reorder columns regardless of database type; switching a connection to a different DB type where reordering is unsupported.

Related errors


AI-assisted analysis of beekeeper-studio/beekeeper-studio@4e3e03e322 (2026-08-31). Data as JSON: /api/errors/8da333564458ea3f. Report an issue: GitHub.