traceSQL
Você precisa de um registro da base remota na sua máquina. Só que esse registro depende de um cliente, que tem pedidos, que têm itens, que apontam para produtos… e fazer dump da base inteira não é opção.
You need one record from the remote database on your machine. But that record depends on a customer, which has orders, which have items, which point to products… and dumping the whole database is not an option.
O TraceSQL parte de um registro, segue as relações e gera um .sql só com o que está ligado a ele.
TraceSQL starts from one record, follows the relations, and writes a .sql with only what is connected to it.
um binário. sem dump gigante. só os relacionados.one binary. no giant dump. just the related rows.
o objetivothe goal
uma base, sem puxar tudo
one database, without pulling everything
Manter a base local alinhada com a remota sem puxar tudo. Aqui está a base remota, com tabelas de todo tipo.
Keep your local database aligned with the remote one without pulling everything. Here is the remote database, with tables of every kind.
só o que se relaciona
only what relates
A partir do registro que você apontou, o TraceSQL acha as tabelas ligadas a ele. O resto da base fica de fora.
From the record you picked, TraceSQL finds the tables connected to it. The rest of the database stays out.
vira um .sql
becomes one .sql
As linhas relacionadas, com o schema necessário, viram um único arquivo, no dialeto do banco de destino.
The related rows, with the schema they need, become a single file in the target database's dialect.
chega no local
lands locally
A base local recebe só a fatia: o que você precisa para reproduzir um problema, testar uma migração ou popular um ambiente.
Your local database gets just the slice: what you need to reproduce a bug, test a migration or seed an environment.
como funcionahow it works
a base inteira
the whole database
Sua base remota tem dezenas de tabelas e milhões de linhas. Para reproduzir um problema você só precisa de uma fatia dela.
Your remote database has dozens of tables and millions of rows. To reproduce a bug you only need a slice of it.
aponte um registro
pick a record
Informe tabela, coluna e valor. Ex.: orders, id, 10. É o ponto de partida.
Give a table, column and value. E.g. orders, id, 10. That is the starting point.
siga as relações
follow the relations
Pais e filhos por foreign key, ou pelo padrão [tabela]_id quando não há FK. Limite a profundidade e ignore tabelas como _log.
Parents and children via foreign keys, or the [table]_id pattern when there are none. Cap the depth and skip tables such as _log.
gere o SQL
get the SQL
O resto fica de fora. Sai um arquivo com CREATE TABLE IF NOT EXISTS e INSERTs no dialeto de destino: Postgres, MySQL ou SQLite.
Everything else stays out. You get one file with CREATE TABLE IF NOT EXISTS and INSERTs in the target dialect: Postgres, MySQL or SQLite.
migre / importe
migrate / import
Rode o arquivo na base local. Com --new-ids, os IDs são regenerados e as referências entre tabelas continuam corretas.
Run the file on your local database. With --new-ids, IDs are regenerated and cross-table references stay correct.
teste a profundidadetry the depth
profundidade 0
depth 0
Só o registro base, orders #10, e mais nada. Exemplo fictício.
Just the base record, orders #10, and nothing else. Made-up example.
profundidade 1
depth 1
Pais e filhos diretos: customers, order_items, shipments. A tabela order_log fica de fora por causa do sufixo _log.
Direct parents and children: customers, order_items, shipments. order_log stays out because of the _log suffix.
profundidade 2
depth 2
Um nível além: os produtos dos itens e o país do cliente.
One level further: the items' products and the customer's country.
sem limite
no limit
Sem --depth o grafo inteiro é percorrido. Agora é com você: mexa na bolinha ou desligue o filtro _log.
Without --depth the whole graph is walked. Now it's up to you: move the knob or turn the _log filter off.
usaruse it
baixe o binário
get the binary
Nas Releases há binários para Linux, macOS e Windows (amd64 e arm64): tracesql-<os>-<arch>. Um arquivo só, sem instalar nada.
The Releases page has binaries for Linux, macOS and Windows (amd64 and arm64): tracesql-<os>-<arch>. A single file, nothing to install.
exporte
export
Sem flags, ele pergunta o que faltar no terminal. Também lê .env e variáveis TRACESQL_*.
With no flags it asks for whatever is missing. It also reads .env and TRACESQL_* variables.
importe no local
import locally
Rode o .sql na sua base. Origem e destino são independentes: Postgres, MySQL ou SQLite.
Run the .sql on your database. Source and target are independent: Postgres, MySQL or SQLite.
# 1. baixe e dê permissão $ chmod +x tracesql-linux-amd64 # 2. postgres remoto → .sql para mysql local $ ./tracesql-linux-amd64 \ --driver postgres \ --host db.exemplo.com --port 5432 \ --user app --database app \ --table orders --record 10 \ --depth 2 \ --ignore-table-suffix _log \ --new-ids \ --output-driver mysql \ --out ./orders_10.sql # 3. importe $ mysql local < orders_10.sql
Todas as flags e variáveis estão no README.All flags and variables are in the README (Portuguese).