chore: auto-commit (57 archivos)
- frontend/functions/core/format_datetime_short.md - frontend/functions/core/format_datetime_short.test.ts - frontend/functions/core/format_datetime_short.ts - frontend/functions/core/format_duration.md - frontend/functions/core/format_duration.test.ts - frontend/functions/core/format_duration.ts - frontend/functions/core/month_grid.md - frontend/functions/core/month_grid.test.ts - frontend/functions/core/month_grid.ts - frontend/functions/core/string_hash_palette.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
---
|
||||
name: sqlite_column_exists
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func ColumnExists(conn *sql.DB, table, name string) (bool, error)"
|
||||
description: "Comprueba si una columna existe en una tabla SQLite consultando PRAGMA table_info. Retorna false sin error si la tabla no existe."
|
||||
tags: [database, sqlite, schema, pragma, column, migration]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: ["database/sql", "fmt"]
|
||||
params:
|
||||
- name: conn
|
||||
desc: "conexion SQLite abierta"
|
||||
- name: table
|
||||
desc: "nombre de la tabla a inspeccionar"
|
||||
- name: name
|
||||
desc: "nombre de la columna a buscar"
|
||||
output: "true si la columna existe, false si no existe o la tabla no existe; error si la query falla"
|
||||
tested: true
|
||||
tests:
|
||||
- "columna existente retorna true"
|
||||
- "columna inexistente retorna false"
|
||||
- "tabla inexistente retorna false sin error"
|
||||
test_file_path: "functions/infra/sqlite_column_exists_test.go"
|
||||
file_path: "functions/infra/sqlite_column_exists.go"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
exists, err := ColumnExists(db, "cards", "assignee_id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists {
|
||||
_, err = db.Exec(`ALTER TABLE cards ADD COLUMN assignee_id TEXT`)
|
||||
}
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Extraido de apps/kanban/backend/db.go. Util como comprobacion previa a ALTER TABLE ADD COLUMN en scripts de migracion que necesitan ser idempotentes. PRAGMA table_info retorna cero filas si la tabla no existe, por lo que la funcion retorna false sin error en ese caso.
|
||||
Reference in New Issue
Block a user