ruvnet/ruflo · error · Error

Schema name too long (${schema.length} chars, max 63): "${sc

Error message

Schema name too long (${schema.length} chars, max 63): "${schema}"

What it means

Thrown by validateSchemaName() when the schema exceeds PostgreSQL's 63-character NAMEDATALEN-1 identifier limit. Postgres would silently truncate over-long identifiers, which can cause two distinct logical schemas to collide after truncation — the helper fails loudly instead.

Source

Thrown at v3/@claude-flow/cli/src/commands/ruvector/pg-utils.ts:25

/**
 * Valid PostgreSQL identifier pattern.
 * Allows only ASCII letters, digits, and underscores.
 * Must start with a letter or underscore.
 */
const VALID_PG_IDENTIFIER = /^[a-zA-Z_][a-zA-Z0-9_]*$/;

/**
 * Validate a PostgreSQL schema name.
 * Throws if the name contains characters that could enable SQL injection.
 * Safe names are returned as-is (no quoting needed since they match the identifier pattern).
 */
export function validateSchemaName(schema: string): string {
  if (!schema || schema.length === 0) {
    throw new Error('Schema name must not be empty');
  }
  if (schema.length > 63) {
    throw new Error(`Schema name too long (${schema.length} chars, max 63): "${schema}"`);
  }
  if (!VALID_PG_IDENTIFIER.test(schema)) {
    throw new Error(
      `Invalid schema name: "${schema}". Must contain only letters, digits, and underscores, and start with a letter or underscore.`
    );
  }
  return schema;
}

/**
 * Validate a PostgreSQL timestamp string.
 * Only allows ISO 8601 format to prevent SQL injection via timestamp fields.
 */
const VALID_TIMESTAMP = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:?\d{2})?$/;

export function validateTimestamp(value: string): string {
  if (!VALID_TIMESTAMP.test(value)) {
    throw new Error(`Invalid timestamp format: "${value}". Expected ISO 8601.`);

View on GitHub (pinned to 6b01dc5a68)

Solutions

  1. Shorten the schema name to <= 63 characters.
  2. If uniqueness must be preserved over a long input, hash it (e.g. `sha256(input).slice(0,16)`) and use the hash as the schema name.
  3. For tenant isolation, prefer a shorter tenant key as the schema identifier and store the full name elsewhere.

Example fix

// before
const schema = `tenant_${longOrgName}_${longProductId}`; // > 63 chars
// after
const schema = `t_${crypto.createHash('sha256').update(longOrgName+longProductId).digest('hex').slice(0,16)}`;
Defensive patterns

Strategy: validation

Validate before calling

function shortenSchemaName(name: string, max = 63): string {
  if (name.length <= max) return name;
  const hash = require('crypto').createHash('sha256').update(name).digest('hex').slice(0, 16);
  return `t_${hash}`;
}

Type guard

const fitsPgIdentifier = (v: string): boolean => v.length <= 63;

Try / catch

try {
  validateSchemaName(schema);
} catch (e) {
  const msg = e instanceof Error ? e.message : String(e);
  if (msg.startsWith('Schema name too long')) {
    schema = shortenSchemaName(schema);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing a programmatically-generated schema name (e.g. a long tenant or namespace identifier) that exceeds 63 characters.

Common situations: Multi-tenant systems deriving schema names from org/product/IDs concatenated together, hashes with long prefixes, or copy-pasting a URL/path into the schema slot.

Related errors


AI-assisted analysis of ruvnet/ruflo@6b01dc5a68 (2026-08-12). Data as JSON: /api/errors/e1f173968e25ee5e. Report an issue: GitHub.