4ef5c6e5b8
Los IDs de tipos Go usan PascalCase: Migration_go_infra, MigrationStatus_go_infra. Actualizar los .md de todas las funciones migration para referenciar los IDs correctos. Re-indexar: 681 funciones, 109 tipos, 0 errores de validacion. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
56 lines
2.1 KiB
Markdown
56 lines
2.1 KiB
Markdown
---
|
|
name: migration_validate
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: pure
|
|
signature: "func MigrationValidate(migrations []Migration) []string"
|
|
description: "Verifica que una secuencia de migraciones sea valida: versiones secuenciales sin huecos comenzando en 1, sin duplicados, con up_sql y nombre no vacios. Retorna lista de errores (vacia si todo OK)."
|
|
tags: [migration, database, sql, schema, sqlite, validate]
|
|
uses_functions: []
|
|
uses_types: [Migration_go_infra]
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: ""
|
|
imports: ["fmt", "sort"]
|
|
params:
|
|
- name: migrations
|
|
desc: "slice de Migration a validar, puede estar desordenado"
|
|
output: "slice de strings con mensajes de error; slice vacio si todas las migraciones son validas"
|
|
tested: true
|
|
tests:
|
|
- "secuencia valida retorna sin errores"
|
|
- "secuencia vacia retorna sin errores"
|
|
- "version duplicada reporta error"
|
|
- "hueco en versiones reporta version faltante"
|
|
- "up_sql vacio reporta error"
|
|
- "nombre vacio reporta error"
|
|
- "versiones que no empiezan en 1 reportan error"
|
|
- "multiple errores se reportan todos"
|
|
test_file_path: "functions/infra/migration_validate_test.go"
|
|
file_path: "functions/infra/migration_validate.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
migrations := []Migration{
|
|
{Version: 1, Name: "create_users", UpSQL: "CREATE TABLE users (...);", DownSQL: "DROP TABLE users;"},
|
|
{Version: 3, Name: "add_roles", UpSQL: "CREATE TABLE roles (...);", DownSQL: "DROP TABLE roles;"},
|
|
}
|
|
errs := MigrationValidate(migrations)
|
|
// errs = ["gap in versions: missing 2 (have 1 then 3)"]
|
|
|
|
valid := []Migration{
|
|
{Version: 1, Name: "create_users", UpSQL: "CREATE TABLE users (id TEXT PRIMARY KEY);"},
|
|
{Version: 2, Name: "add_email", UpSQL: "ALTER TABLE users ADD COLUMN email TEXT;"},
|
|
}
|
|
errs = MigrationValidate(valid)
|
|
// errs = [] (empty — no errors)
|
|
```
|
|
|
|
## Notas
|
|
|
|
Funcion pura — no hace I/O, no modifica el slice de entrada. Ordena internamente una copia para detectar huecos. Todos los errores encontrados se acumulan y retornan juntos (no falla al primer error). Util antes de llamar a `MigrationUp` para detectar problemas de forma anticipada.
|