cloning:column:edit

Edit a column strategy in a .cloning.yaml, interactively or via flags.

Interactively edit a column strategy in an existing .cloning.yaml configuration file.

Usage

clonio cloning:column:edit [<file>] [options]

If file is omitted, the command searches for .cloning.yaml files in the current directory. If exactly one is found, it is selected automatically. With multiple files, an interactive selection prompt is shown.

Interactive Flow

When run without flags, the command walks through each step interactively:

  1. File — Select or auto-detect the .cloning.yaml file.
  2. Table — Choose from the tables defined in the YAML.
  3. Column — Choose an existing column or add a new one.
  4. Strategy — Select from all available strategies with descriptions.
  5. Parameters — Prompted based on the chosen strategy.
  6. Summary — A table showing all values is displayed before writing.
  7. Confirm — Apply or cancel the change.

Strategies

Strategy Description
keep Copy the original value as-is — no transformation applied.
fake Replace with a realistic fake value generated by FakerPHP.
hash Replace with a one-way hash of the original value. Useful for passwords and secrets.
mask Partially mask the value, preserving a configurable number of visible characters.
static Replace every value with a fixed string.
template Build a string by mixing literal text with {fakerMethod} placeholders, e.g. {userName}@acme.test.
remapping Replace primary-key values; foreign keys auto-detected from the live source schema.
exclude Leave the column out of the transfer. The target column must be nullable or have a default. No parameters.

fake Parameters

Parameter Option Description
Faker method --faker-method= FakerPHP method name (e.g. safeEmail, name, phoneNumber)
Faker arguments --faker-arguments= Comma-separated arguments passed to the faker method

Available faker methods in the interactive picker: safeEmail, userName, name, firstName, lastName, phoneNumber, address, city, postcode, countryCode, company, jobTitle, date, latitude, longitude, buildingNumber, text, sentence, url, ipv4, uuid, word, numberBetween, randomFloat.

Argument hints

After a faker method is selected (interactively or via --faker-method), Clonio prints a hint showing what arguments the method accepts:

  ℹ  numberBetween() arguments: min (int, default 0), max (int, default 2147483647)

Methods that take no arguments display:

  ℹ  safeEmail() takes no arguments — leave faker arguments blank.

The argument prompt is skipped automatically for methods with no arguments; the YAML will contain faker_arguments: [].

Argument reference for methods that accept parameters:

Method Arguments
date format (string, e.g. "Y-m-d"), max (string|null, e.g. "now")
latitude min (float, default -90), max (float, default 90)
longitude min (float, default -180), max (float, default 180)
text maxNbChars (int, default 200)
sentence nbWords (int, default 6), variableNbWords (bool, default true)
numberBetween min (int, default 0), max (int, default 2147483647)
randomFloat nbMaxDecimals (int|null), min (float, default 0), max (float, default 100)

hash Parameters

Parameter Option Description
Algorithm --algorithm= Hash algorithm: sha256, sha512, md5, sha1
Salt --salt= Optional salt prepended to the value before hashing

mask Parameters

Parameter Option Description
Visible characters --visible-chars= Number of characters to leave unmasked (default: 0)
Mask character --mask-char= Character used for masking (default: *)
Preserve format --preserve-format Keep the original character positions (e.g. email @ and dots)

static Parameters

Parameter Option Description
Value --value= The fixed string to replace every value with

template Parameters

Parameter Option Description
Template --template= Literal text with {fakerMethod} placeholders, e.g. {firstName}.{lastName}@example.test

remapping Parameters

Parameter Option Description
Remapping mode --remapping-use= random_integer (auto-bounded by column type ceiling) or new_uuid (UUIDv7)

The command opens the source connection declared at the YAML top-level (connection:), inspects the live schema, and:

  1. Validates that the chosen column is a primary key on the source table. If it is not, the command exits with code 4 and the YAML is left untouched.
  2. Auto-detects every foreign key in the source database that references <table>.<column>. The detected list is written into the arguments[].foreign_keys block — overwriting any prior list. Self-references (FK on the same table) are emitted with self_referential: true.

The output structure mirrors cloning:dump:

columns:
  id:
    strategy: remapping
    arguments:
      - use: random_integer
      - foreign_keys:
          - table: posts
            column: user_id
            self_referential: false

If the source connection cannot be reached (config missing, host unreachable, etc.), the command prints a warning, skips primary-key validation, and writes an empty foreign_keys: []. Re-run the command once the connection is available, or hand-edit the FK list, to populate the relationships.

Options

Option Description
file Path to the .cloning.yaml file (argument, optional)
--table= Table name
--column= Column name
--strategy= Strategy to apply: keep, fake, hash, mask, static, template, remapping
--template= (template) Template with {fakerMethod} placeholders
--remapping-use= (remapping) random_integer or new_uuid

Exit Codes

Code Meaning
0 Column updated successfully, or change was cancelled
4 Table or column not found, or unknown strategy
5 File not found or cannot be read

Examples

# Fully interactive
clonio cloning:column:edit

# Specify file and table interactively select column/strategy
clonio cloning:column:edit production-db.cloning.yaml --table=users

# Non-interactive: set email to fake with userName
clonio cloning:column:edit production-db.cloning.yaml \
  --table=users --column=email --strategy=fake --faker-method=userName

# Non-interactive: mask phone number keeping last 4 digits
clonio cloning:column:edit production-db.cloning.yaml \
  --table=contacts --column=phone --strategy=mask --visible-chars=4

# Non-interactive: set password to hash with salt
clonio cloning:column:edit production-db.cloning.yaml \
  --table=users --column=password --strategy=hash --algorithm=sha512 --salt=my-salt

# Non-interactive: replace all values with a static string
clonio cloning:column:edit production-db.cloning.yaml \
  --table=users --column=bio --strategy=static --value=redacted

# Non-interactive: enable random-integer key remapping for users.id
# (foreign keys auto-detected from the source schema)
clonio cloning:column:edit production-db.cloning.yaml \
  --table=users --column=id --strategy=remapping --remapping-use=random_integer

# Non-interactive: enable UUIDv7 key remapping
clonio cloning:column:edit production-db.cloning.yaml \
  --table=users --column=id --strategy=remapping --remapping-use=new_uuid