Find an element’s ID and history
Every table, column, constraint and other object of a schema is an
element, and each has an ID, its ElementID, that
stays the same when the element is renamed. retrofit element list prints
the live elements with their IDs, and retrofit element history prints the
ops that changed one of them.
retrofit element list and retrofit element history are
the reference: every flag, each record’s fields, and each refusal and exit
code.
List the elements
Run element list in the project:
retrofit element list
Each line is one live element: its kind, its schema, the ref that
op add accepts for it, and its ID. Add --kind table to list only the
tables, and repeat --kind for a second kind. Add --schema users to list
one schema of several.
To list the schema as it stood at an earlier point in the
oplog, pass that point as --at: seal for the last
Seal, or an op’s opid with
--schema.
retrofit element list --at seal
Script over every table
Read --as=json in a script: a name may hold any byte, and each JSON
record names the element’s id, name, schema, ref, parent and, for
a partition, partition_of. This loop prefixes every table’s name with
app_ and leaves out partitions, which RenameTable does not take by
name:
retrofit element list --as=json --kind table \
| jq -r 'select(.type=="item" and .partition_of == null)
| "retrofit op add RenameTable --schema \(.schema | @sh) \(.id) \("app_" + .name | @sh)"' \
| sh
Key a loop that changes the schema on id, as this one does. A ref
names the element as of the run that listed it, and each rename the loop
appends changes what a name spells.
List again before acting on IDs from an earlier run. An ID holds until an
op replaces it: import --force replaces every ID, and a
ChangePrimaryKey replaces the IDs of the foreign keys that depend on the
key.
Read one element’s history
Pass a name to element history:
retrofit element history people
Each line is one op that created, changed, renamed, moved or dropped the element, in log order. A name finds the live element first. When no live element has the name, it finds the element that had it before: a dropped table, or a renamed one by its earlier name.
To read the history of what element list printed, pass each ID with the
record’s schema:
retrofit element list --as=json --schema users --kind table \
| jq -r 'select(.type=="item") | .id' \
| xargs -n1 retrofit element history --schema users
Pick one of two candidates
A name that two elements have had matches both, and the run prints each
candidate in place of a history: its ID, name, kind and, for a dropped
one, the op that ended it. A constraint and the index named after it share
a ref the same way. Pass the candidate’s kind as --kind, or its ID:
retrofit element history --kind constraint people_pkey
retrofit element history a575bf81e78a
Related
retrofit element list: every flag, each record’s fields and each refusal.retrofit element history: how the operand binds, which ops belong, and each refusal.- The oplog: what an ElementID is, and why ops bind to it.