feat: migracion SQL, template DB y generador para fn_operations
001_init.sql como espejo del schema, gentemplate para crear operations.db vacias con schema aplicado, y template lista para copiar con fn ops init.
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
ops "fn-registry/fn_operations"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
path := "fn_operations/project_template/operations.db"
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
path = os.Args[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove existing template
|
||||||
|
os.Remove(path)
|
||||||
|
|
||||||
|
db, err := ops.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
fmt.Printf("Template DB created at %s\n", path)
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
-- fn_operations schema v1.0.0
|
||||||
|
-- Espejo del schema en fn_operations/db.go para referencia y tooling externo.
|
||||||
|
|
||||||
|
PRAGMA journal_mode=WAL;
|
||||||
|
PRAGMA foreign_keys=ON;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS types_snapshot (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
version TEXT NOT NULL DEFAULT '1.0.0',
|
||||||
|
lang TEXT NOT NULL,
|
||||||
|
algebraic TEXT NOT NULL CHECK(algebraic IN ('product','sum')),
|
||||||
|
definition TEXT NOT NULL DEFAULT '',
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
snapped_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS entities (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
type_ref TEXT NOT NULL,
|
||||||
|
status TEXT NOT NULL DEFAULT 'active' CHECK(status IN ('active','stale','corrupted','archived')),
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
domain TEXT NOT NULL DEFAULT '',
|
||||||
|
tags TEXT NOT NULL DEFAULT '[]',
|
||||||
|
source TEXT NOT NULL,
|
||||||
|
metadata TEXT NOT NULL DEFAULT '{}',
|
||||||
|
notes TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS relations (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
from_entity TEXT NOT NULL DEFAULT '',
|
||||||
|
to_entity TEXT NOT NULL,
|
||||||
|
via TEXT NOT NULL DEFAULT '',
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
purity TEXT NOT NULL DEFAULT '' CHECK(purity IN ('','pure','impure')),
|
||||||
|
direction TEXT NOT NULL DEFAULT 'unidirectional' CHECK(direction IN ('unidirectional','bidirectional','inverse')),
|
||||||
|
weight REAL,
|
||||||
|
status TEXT NOT NULL DEFAULT 'designed' CHECK(status IN ('designed','implemented','tested','running','deprecated')),
|
||||||
|
started_at TEXT,
|
||||||
|
ended_at TEXT,
|
||||||
|
"order" INTEGER,
|
||||||
|
tags TEXT NOT NULL DEFAULT '[]',
|
||||||
|
notes TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS relation_inputs (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
relation_id TEXT NOT NULL REFERENCES relations(id) ON DELETE CASCADE,
|
||||||
|
entity_id TEXT NOT NULL REFERENCES entities(id),
|
||||||
|
role TEXT NOT NULL,
|
||||||
|
"order" INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE VIRTUAL TABLE IF NOT EXISTS entities_fts USING fts5(
|
||||||
|
id, name, description, tags, domain,
|
||||||
|
content='entities', content_rowid='rowid'
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TRIGGER IF NOT EXISTS entities_ai AFTER INSERT ON entities BEGIN
|
||||||
|
INSERT INTO entities_fts(rowid, id, name, description, tags, domain)
|
||||||
|
VALUES (new.rowid, new.id, new.name, new.description, new.tags, new.domain);
|
||||||
|
END;
|
||||||
|
|
||||||
|
CREATE TRIGGER IF NOT EXISTS entities_ad AFTER DELETE ON entities BEGIN
|
||||||
|
INSERT INTO entities_fts(entities_fts, rowid, id, name, description, tags, domain)
|
||||||
|
VALUES ('delete', old.rowid, old.id, old.name, old.description, old.tags, old.domain);
|
||||||
|
END;
|
||||||
|
|
||||||
|
CREATE TRIGGER IF NOT EXISTS entities_au AFTER UPDATE ON entities BEGIN
|
||||||
|
INSERT INTO entities_fts(entities_fts, rowid, id, name, description, tags, domain)
|
||||||
|
VALUES ('delete', old.rowid, old.id, old.name, old.description, old.tags, old.domain);
|
||||||
|
INSERT INTO entities_fts(rowid, id, name, description, tags, domain)
|
||||||
|
VALUES (new.rowid, new.id, new.name, new.description, new.tags, new.domain);
|
||||||
|
END;
|
||||||
Binary file not shown.
Reference in New Issue
Block a user