{"record":{"id":"b5419b49a8820666","repo":"beekeeper-studio/beekeeper-studio","slug":"can-t-add-a-column-without-name-or-data-type-b5419b","errorCode":null,"errorMessage":"can't add a column without name or data type","messagePattern":"can't add a column without name or data type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/studio/src/shared/lib/sql/change_builder/ClickHouseChangeBuilder.ts","lineNumber":19,"sourceCode":"import { ChangeBuilderBase } from \"@shared/lib/sql/change_builder/ChangeBuilderBase\";\nimport { ClickHouseData } from \"@shared/lib/dialects/clickhouse\";\nimport { Dialect, SchemaItem } from \"@shared/lib/dialects/models\";\nimport _ from 'lodash'\n\nexport class ClickHouseChangeBuilder extends ChangeBuilderBase {\n  dialect: Dialect = 'clickhouse'\n  wrapIdentifier = ClickHouseData.wrapIdentifier\n  wrapLiteral = ClickHouseData.wrapLiteral\n  escapeString = ClickHouseData.escapeString\n\n  constructor(table: string, schema: string, private columns: SchemaItem[]) {\n    super(table, schema)\n  }\n\n  // new columns\n  addColumn(item: SchemaItem) {\n    if (!item.columnName || !item.dataType) {\n      throw new Error(\"can't add a column without name or data type\")\n    }\n\n    let dataType = this.wrapLiteral(item.dataType)\n    if (item.nullable) {\n      dataType = `Nullable(${dataType})`\n    }\n\n    return [\n      'ADD COLUMN',\n      this.wrapIdentifier(item.columnName),\n      dataType,\n      item.defaultValue ? `DEFAULT ${this.wrapLiteral(item.defaultValue)}` : null,\n      item.extra,\n      item.comment ? `COMMENT ${this.escapeString(item.comment, true)}` : null\n    ].filter((i) => !!i).join(\" \")\n  }\n\n  alterDefault(column: string, newDefault: string | boolean | null) {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/beekeeper-studio/beekeeper-studio/blob/4e3e03e3223b2b71a1af8926d455f533b80af837/apps/studio/src/shared/lib/sql/change_builder/ClickHouseChangeBuilder.ts#L1-L37","documentation":"ClickHouseChangeBuilder.addColumn builds an ALTER TABLE ... ADD COLUMN statement and refuses to proceed when the SchemaItem is missing either a columnName or a dataType. A column with no name or no type cannot be expressed in valid ClickHouse DDL, so the builder throws early instead of emitting broken SQL. This is a defensive guard against incomplete schema-edit inputs.","triggerScenarios":"Calling addColumn(item) with item.columnName === '' / undefined / null, or with item.dataType === '' / undefined / null. Typically happens when a UI form or script submits a partially filled row from a table-structure editor.","commonSituations":"User clicks Save/Add in the table structure editor without filling in the new column's name or type; a migration generator iterates schema items where some entries were auto-created as blanks; programmatic schema tooling passing SparseSchemaItem objects with optional fields left unset.","solutions":["Set both item.columnName and item.dataType on the SchemaItem before calling addColumn","Filter out blank/incomplete schema rows before passing them to the change builder","Add form-level validation in the UI so the add-column action cannot be triggered with an empty name or type","Wrap addColumn in try/catch and surface a user-facing message about the missing name/type"],"exampleFix":"// before\nbuilder.addColumn({ dataType: 'String' }) // throws\n// after\nbuilder.addColumn({ columnName: 'status', dataType: 'String', nullable: true })","handlingStrategy":"validation","validationCode":"function canAddColumn(item) { return Boolean(item && item.columnName && item.columnName.trim() && item.dataType && item.dataType.trim()); }\nif (!canAddColumn(item)) throw new Error('Column name and data type are required');","typeGuard":"function isCompleteSchemaItem(item): item is SchemaItem & { columnName: string; dataType: string } {\n  return typeof item?.columnName === 'string' && item.columnName.trim() !== '' && typeof item?.dataType === 'string' && item.dataType.trim() !== '';\n}","tryCatchPattern":"try {\n  builder.addColumn(item);\n} catch (e) {\n  if (e.message.includes(\"without name or data type\")) {\n    notifyUser('New column needs a name and a data type');\n  } else throw e;\n}","preventionTips":["Validate column-editor forms before submit (name + type required)","Filter out blank rows before building alter scripts","Give new columns a sensible default type in the UI","Unit-test addColumn with empty-name and empty-type items"],"tags":["validation","schema","ddl","clickhouse"],"backgroundTag":"invalid-schema-item","analyzedSha":"4e3e03e3223b2b71a1af8926d455f533b80af837","analyzedAt":"2026-08-31T23:21:23.379Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}