MCPcopy Create free account
hub / github.com/astercloud/aster / migrate

Method migrate

pkg/memory/logic/store_postgres.go:65–104  ·  view source on GitHub ↗

migrate 创建表结构

()

Source from the content-addressed store, hash-verified

63
64// migrate 创建表结构
65func (s *PostgreSQLStore) migrate() error {
66 query := fmt.Sprintf(`
67 CREATE TABLE IF NOT EXISTS %s (
68 id VARCHAR(64) PRIMARY KEY,
69 namespace VARCHAR(255) NOT NULL,
70 scope VARCHAR(20) NOT NULL,
71 type VARCHAR(100) NOT NULL,
72 category VARCHAR(100),
73 key VARCHAR(255) NOT NULL,
74 value JSONB NOT NULL DEFAULT '{}',
75 description TEXT,
76 source_type VARCHAR(50),
77 confidence DECIMAL(5,4) DEFAULT 0,
78 sources JSONB DEFAULT '[]',
79 provenance_created_at TIMESTAMP,
80 provenance_updated_at TIMESTAMP,
81 provenance_version INT DEFAULT 0,
82 access_count INT DEFAULT 0,
83 last_accessed TIMESTAMP,
84 metadata JSONB DEFAULT '{}',
85 created_at TIMESTAMP NOT NULL DEFAULT NOW(),
86 updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
87 UNIQUE(namespace, key)
88 );
89
90 CREATE INDEX IF NOT EXISTS idx_%s_namespace ON %s(namespace);
91 CREATE INDEX IF NOT EXISTS idx_%s_namespace_type ON %s(namespace, type);
92 CREATE INDEX IF NOT EXISTS idx_%s_scope ON %s(scope);
93 CREATE INDEX IF NOT EXISTS idx_%s_confidence ON %s(confidence);
94 CREATE INDEX IF NOT EXISTS idx_%s_last_accessed ON %s(last_accessed);
95 `, s.tableName,
96 s.tableName, s.tableName,
97 s.tableName, s.tableName,
98 s.tableName, s.tableName,
99 s.tableName, s.tableName,
100 s.tableName, s.tableName)
101
102 _, err := s.db.Exec(query)
103 return err
104}
105
106// Save 保存或更新 Memory
107func (s *PostgreSQLStore) Save(ctx context.Context, mem *LogicMemory) error {

Callers 1

NewPostgreSQLStoreFunction · 0.95

Calls 1

ExecMethod · 0.65

Tested by

no test coverage detected