diff --git a/README.md b/README.md index a9e1088..ca331e1 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,60 @@ # go-migrate -Migrador de datos entre SQL Server y PostgreSQL con procesamiento en paralelo. +Data migrator between SQL Server and PostgreSQL with parallel ETL processing. -## Compilar +## Build ```bash go build -o go-migrate ./cmd/go_migrate ``` -## Uso +## Usage ```bash -./go-migrate [opciones] [] +./go-migrate [options] [] ``` -### Opciones +### Options -| Flag | Descripción | +| Flag | Description | |------|-------------| -| `-config ` | Ruta al archivo de configuración YAML. También se puede pasar como argumento posicional. Si no se indica, se busca `config.yaml`. | -| `-validate` | Compara la cantidad de filas entre origen y destino por cada job. No migra datos. | -| `-dry-run` | Valida conexiones, acceso a storage (si aplica) y cuenta filas en origen sin migrar. | +| `-config ` | Path to the YAML configuration file. Can also be passed as a positional argument. Defaults to `config.yaml` in the current directory. | +| `-validate` | Compares the row count between source and target for each job. Does not migrate data. | +| `-dry-run` | Validates connections, storage access (if applicable), and counts source rows without migrating. | -### Ejemplos +### Examples ```bash -# Migrar con config.yaml por defecto +# Migrate using the default config.yaml ./go-migrate -# Usar un archivo de configuración específico -./go-migrate -config produccion.yaml +# Use a specific configuration file +./go-migrate -config production.yaml -# Validar que origen y destino tengan la misma cantidad de filas -./go-migrate -validate -config produccion.yaml +# Validate that source and target have the same row count +./go-migrate -validate -config production.yaml -# Verificar conectividad sin migrar -./go-migrate -dry-run -config produccion.yaml +# Check connectivity without migrating +./go-migrate -dry-run -config production.yaml ``` -## Configuración +## Configuration -La herramienta lee credenciales y parámetros desde variables de entorno o un archivo `.env`. +The tool reads credentials and parameters from environment variables or a `.env` file. -### Variables clave +### Key environment variables -| Variable | Descripción | +| Variable | Description | |----------|-------------| -| `SOURCE_DB_URL` | URL de conexión a la base de datos origen (o `SOURCE_DB_HOST`, `SOURCE_DB_NAME`, `SOURCE_DB_USER`, `SOURCE_DB_PWD`). | -| `TARGET_DB_URL` | URL de conexión a la base de datos destino (o `TARGET_DB_HOST`, `TARGET_DB_NAME`, `TARGET_DB_USER`, `TARGET_DB_PWD`). | -| `LOG_LEVEL` | Nivel de log: `DEBUG`, `INFO`, `WARN`, `ERROR` (por defecto: `INFO`). | +| `SOURCE_DB_URL` | Source database connection URL. Alternatively, set `SOURCE_DB_HOST`, `SOURCE_DB_NAME`, `SOURCE_DB_USER`, and `SOURCE_DB_PWD`. | +| `TARGET_DB_URL` | Target database connection URL. Alternatively, set `TARGET_DB_HOST`, `TARGET_DB_NAME`, `TARGET_DB_USER`, and `TARGET_DB_PWD`. | +| `LOG_LEVEL` | Log level: `DEBUG`, `INFO`, `WARN`, `ERROR` (default: `INFO`). | -Para migrar datos binarios a Azure Blob, también se requieren `AZ_STORAGE_ENABLED`, `AZ_ACCOUNT_NAME`, `AZ_CONTAINER`, `AZ_ACCOUNT_KEY`. +To migrate binary data to Azure Blob Storage, also set `AZ_STORAGE_ENABLED`, `AZ_ACCOUNT_NAME`, `AZ_CONTAINER`, and `AZ_ACCOUNT_KEY`. -### Archivo de migración (YAML) +### Migration config file (YAML) -Define los jobs de migración. Ejemplo mínimo: +Defines the migration jobs. Minimal example: ```yaml source_db_type: sqlserver @@ -72,21 +72,21 @@ defaults: max_delay_ms: 5000 jobs: - - name: migrar_usuarios + - name: demo_users enabled: true source: schema: dbo - table: Usuarios - primary_key: Id + table: users + primary_key: id target: schema: public - table: usuarios + table: users ``` -Consulta el archivo `config.yaml` de tu entorno para ver los jobs disponibles y sus parámetros específicos. +See the `config.yaml` in this repository for the full set of supported options (`from_json`, `to_storage`, partition slicing via `range`, per-job overrides, `pre_sql`/`post_sql`, etc.). -## Modos de ejecución +## Execution modes -- **Migración** (por defecto): extrae, transforma y carga datos en paralelo. -- **Validación** (`-validate`): cuenta y compara filas entre origen y destino. -- **Dry run** (`-dry-run`): verifica conexiones y muestra la cantidad de filas en origen. +- **Migrate** (default): extracts, transforms, and loads data in parallel. +- **Validate** (`-validate`): counts and compares rows between source and target. +- **Dry run** (`-dry-run`): validates connections and reports the source row count without migrating. diff --git a/benchmark-results.md b/benchmark-results.md index 054cca6..07f9765 100644 --- a/benchmark-results.md +++ b/benchmark-results.md @@ -1,6 +1,6 @@ # Benchmark go-migrate — 2,000,000 filas -**Tabla**: `demo.users` +**Tabla**: `public.records` **Fecha**: 2026-05-29 **Entorno**: Docker local (MSSQL 2022 Developer / PostgreSQL 16 + PostGIS) diff --git a/config.yaml b/config.yaml index 6e79613..218d6d7 100644 --- a/config.yaml +++ b/config.yaml @@ -39,15 +39,15 @@ jobs: # source: # schema: analytics # table: events - # primary_key: ID_events + # primary_key: id # from_json: - # - column: $node_id* + # - column: payload # field: id # target: # schema: analytics # table: events - # - name: analytics_audit_log + # - name: storage_attachments # source: # schema: storage # table: attachments @@ -75,3 +75,33 @@ jobs: # base_delay_ms: 1000 # max_delay_ms: 15000 # max_jitter_ms: 500 + + # - name: analytics_audit_log + # source: + # schema: analytics + # table: audit_log + # primary_key: id + # target: + # schema: analytics + # table: audit_log + # pre_sql: + # - "DROP INDEX IF EXISTS audit_log_created_at_idx" + # - "DROP INDEX IF EXISTS audit_log_user_id_idx" + # post_sql: + # - "CREATE INDEX audit_log_created_at_idx ON analytics.audit_log (created_at)" + # - "CREATE INDEX audit_log_user_id_idx ON analytics.audit_log (user_id)" + # - "ANALYZE analytics.audit_log" + # # Partition slicing: only migrate the slice [2024-01-01, 2024-12-31] + # # in this re-run. is_min_inclusive=false resumes AFTER any failed boundary. + # range: + # min: 1704067200000 # 2024-01-01 UTC, as epoch millis + # max: 1735689599999 # 2024-12-31 UTC, as epoch millis + # is_min_inclusive: false + # is_max_inclusive: true + # partition_calculation_strategy: ESTIMATION # faster than EXACT on large tables + # truncate_method: DELETE # use DELETE instead of TRUNCATE + # batches_per_partition: 8 + # retry: + # attempts: 5 + # max_failed_partitions: 3 + # max_failed_batches_load: 10