memory-lucia 2.5.1 ā 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SKILL.md +1 -1
- package/database/schema.sql +142 -61
- package/migrations/README.md +1 -0
- package/package.json +1 -1
- package/check-db.js +0 -13
- package/migrations/v1-to-v2.js +0 -213
package/README.md
CHANGED
package/SKILL.md
CHANGED
package/database/schema.sql
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
-- Memory V2.
|
|
2
|
-
-- SQLite database schema for
|
|
1
|
+
-- Memory V2.5 Database Schema
|
|
2
|
+
-- SQLite database schema for Memory Lucia V2.5
|
|
3
3
|
|
|
4
4
|
-- Priority Analysis Table
|
|
5
5
|
CREATE TABLE IF NOT EXISTS memory_priorities (
|
|
6
6
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
priority_level
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
message_id TEXT NOT NULL,
|
|
8
|
+
conversation_id INTEGER,
|
|
9
|
+
priority_level INTEGER CHECK(priority_level BETWEEN 1 AND 4),
|
|
10
|
+
importance_score REAL DEFAULT 0,
|
|
11
|
+
keywords TEXT,
|
|
12
|
+
context_summary TEXT,
|
|
13
|
+
auto_detected BOOLEAN DEFAULT 0,
|
|
14
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
15
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
13
16
|
);
|
|
14
17
|
|
|
15
18
|
-- Learning Tracking Table
|
|
16
19
|
CREATE TABLE IF NOT EXISTS memory_learning (
|
|
17
20
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
message_id TEXT NOT NULL,
|
|
22
|
+
conversation_id INTEGER,
|
|
23
|
+
learning_topic TEXT NOT NULL,
|
|
24
|
+
topic_category TEXT,
|
|
25
|
+
progress_status TEXT CHECK(progress_status IN ('not_started', 'started', 'in_progress', 'completed', 'on_hold')),
|
|
26
|
+
progress_percentage INTEGER DEFAULT 0 CHECK(progress_percentage BETWEEN 0 AND 100),
|
|
27
|
+
estimated_completion_date DATETIME,
|
|
28
|
+
actual_completion_date DATETIME,
|
|
29
|
+
milestone_count INTEGER DEFAULT 0,
|
|
30
|
+
completed_milestones INTEGER DEFAULT 0,
|
|
31
|
+
resources TEXT,
|
|
32
|
+
notes TEXT,
|
|
33
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
34
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
27
35
|
);
|
|
28
36
|
|
|
29
37
|
-- Learning Milestones Table
|
|
@@ -32,54 +40,101 @@ CREATE TABLE IF NOT EXISTS memory_learning_milestones (
|
|
|
32
40
|
learning_id INTEGER NOT NULL,
|
|
33
41
|
title TEXT NOT NULL,
|
|
34
42
|
description TEXT,
|
|
35
|
-
|
|
43
|
+
status TEXT DEFAULT 'pending',
|
|
44
|
+
target_date DATETIME,
|
|
45
|
+
completed_at DATETIME,
|
|
46
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
36
47
|
FOREIGN KEY (learning_id) REFERENCES memory_learning(id) ON DELETE CASCADE
|
|
37
48
|
);
|
|
38
49
|
|
|
39
50
|
-- Decision Records Table
|
|
40
51
|
CREATE TABLE IF NOT EXISTS memory_decisions (
|
|
41
52
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
message_id TEXT NOT NULL,
|
|
54
|
+
conversation_id INTEGER,
|
|
55
|
+
decision_type TEXT,
|
|
56
|
+
decision_question TEXT NOT NULL,
|
|
57
|
+
decision_context TEXT,
|
|
58
|
+
options_considered TEXT,
|
|
59
|
+
chosen_option TEXT,
|
|
60
|
+
rationale TEXT,
|
|
61
|
+
confidence_level INTEGER CHECK(confidence_level BETWEEN 1 AND 5),
|
|
46
62
|
expected_outcome TEXT,
|
|
47
63
|
actual_outcome TEXT,
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
outcome_status TEXT CHECK(outcome_status IN ('pending', 'implemented', 'validated', 'rejected')),
|
|
65
|
+
review_date DATETIME,
|
|
50
66
|
reviewed_at DATETIME,
|
|
51
|
-
|
|
67
|
+
review_notes TEXT,
|
|
68
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
69
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
52
70
|
);
|
|
53
71
|
|
|
54
72
|
-- Skill Evolution Table
|
|
55
73
|
CREATE TABLE IF NOT EXISTS memory_evolution (
|
|
56
74
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
57
75
|
skill_name TEXT NOT NULL,
|
|
58
|
-
|
|
76
|
+
skill_category TEXT,
|
|
77
|
+
proficiency_level INTEGER DEFAULT 1 CHECK(proficiency_level BETWEEN 1 AND 10),
|
|
78
|
+
experience_points INTEGER DEFAULT 0,
|
|
59
79
|
usage_count INTEGER DEFAULT 0,
|
|
60
80
|
success_count INTEGER DEFAULT 0,
|
|
81
|
+
failure_count INTEGER DEFAULT 0,
|
|
61
82
|
last_used_at DATETIME,
|
|
62
|
-
first_used_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
83
|
+
first_used_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
84
|
+
performance_metrics TEXT,
|
|
85
|
+
improvement_areas TEXT,
|
|
86
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
87
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
63
88
|
);
|
|
64
89
|
|
|
65
|
-
--
|
|
66
|
-
CREATE TABLE IF NOT EXISTS
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
-- Skill Evolution History Table
|
|
91
|
+
CREATE TABLE IF NOT EXISTS memory_evolution_history (
|
|
92
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
93
|
+
skill_id INTEGER NOT NULL,
|
|
94
|
+
event_type TEXT NOT NULL,
|
|
95
|
+
event_data TEXT,
|
|
96
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
97
|
+
FOREIGN KEY (skill_id) REFERENCES memory_evolution(id) ON DELETE CASCADE
|
|
69
98
|
);
|
|
70
99
|
|
|
71
|
-
--
|
|
72
|
-
|
|
100
|
+
-- Version Management Table
|
|
101
|
+
CREATE TABLE IF NOT EXISTS memory_versions (
|
|
102
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
103
|
+
version_name TEXT NOT NULL,
|
|
104
|
+
version_type TEXT,
|
|
105
|
+
description TEXT,
|
|
106
|
+
backup_path TEXT,
|
|
107
|
+
backup_size INTEGER,
|
|
108
|
+
checksum TEXT,
|
|
109
|
+
is_active BOOLEAN DEFAULT 0,
|
|
110
|
+
migration_script TEXT,
|
|
111
|
+
rollback_script TEXT,
|
|
112
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
113
|
+
activated_at DATETIME
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
-- Version Statistics Table
|
|
117
|
+
CREATE TABLE IF NOT EXISTS memory_version_stats (
|
|
118
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
119
|
+
version_id INTEGER,
|
|
120
|
+
stat_name TEXT,
|
|
121
|
+
stat_value INTEGER,
|
|
122
|
+
recorded_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
123
|
+
);
|
|
73
124
|
|
|
74
125
|
-- Create indexes for performance
|
|
75
126
|
CREATE INDEX IF NOT EXISTS idx_priorities_level ON memory_priorities(priority_level);
|
|
76
127
|
CREATE INDEX IF NOT EXISTS idx_priorities_created ON memory_priorities(created_at);
|
|
77
|
-
CREATE INDEX IF NOT EXISTS idx_learning_status ON memory_learning(
|
|
78
|
-
CREATE INDEX IF NOT EXISTS idx_learning_topic ON memory_learning(
|
|
79
|
-
CREATE INDEX IF NOT EXISTS idx_decisions_status ON memory_decisions(
|
|
80
|
-
CREATE INDEX IF NOT EXISTS idx_decisions_review ON memory_decisions(
|
|
128
|
+
CREATE INDEX IF NOT EXISTS idx_learning_status ON memory_learning(progress_status);
|
|
129
|
+
CREATE INDEX IF NOT EXISTS idx_learning_topic ON memory_learning(learning_topic);
|
|
130
|
+
CREATE INDEX IF NOT EXISTS idx_decisions_status ON memory_decisions(outcome_status);
|
|
131
|
+
CREATE INDEX IF NOT EXISTS idx_decisions_review ON memory_decisions(review_date);
|
|
81
132
|
CREATE INDEX IF NOT EXISTS idx_evolution_skill ON memory_evolution(skill_name);
|
|
82
|
-
CREATE INDEX IF NOT EXISTS idx_evolution_category ON memory_evolution(
|
|
133
|
+
CREATE INDEX IF NOT EXISTS idx_evolution_category ON memory_evolution(skill_category);
|
|
134
|
+
|
|
135
|
+
-- Insert initial version
|
|
136
|
+
INSERT OR IGNORE INTO memory_versions (version_name, version_type, description, is_active)
|
|
137
|
+
VALUES ('2.5.0', 'initial', 'Memory V2.5 Initial Version', 1);
|
|
83
138
|
|
|
84
139
|
-- Views for common queries
|
|
85
140
|
|
|
@@ -88,65 +143,91 @@ CREATE VIEW IF NOT EXISTS v_pending_decisions AS
|
|
|
88
143
|
SELECT
|
|
89
144
|
d.*,
|
|
90
145
|
CASE
|
|
91
|
-
WHEN
|
|
92
|
-
WHEN
|
|
146
|
+
WHEN review_date < datetime('now') THEN 'overdue'
|
|
147
|
+
WHEN review_date <= datetime('now', '+7 days') THEN 'due_soon'
|
|
93
148
|
ELSE 'scheduled'
|
|
94
149
|
END as review_status
|
|
95
150
|
FROM memory_decisions d
|
|
96
|
-
WHERE
|
|
97
|
-
AND (
|
|
98
|
-
ORDER BY
|
|
151
|
+
WHERE outcome_status IN ('pending', 'implemented')
|
|
152
|
+
AND (review_date IS NULL OR review_date <= datetime('now', '+7 days'))
|
|
153
|
+
ORDER BY review_date ASC;
|
|
99
154
|
|
|
100
155
|
-- View: Skill Summary
|
|
101
156
|
CREATE VIEW IF NOT EXISTS v_skill_summary AS
|
|
102
157
|
SELECT
|
|
103
158
|
skill_name,
|
|
104
|
-
|
|
159
|
+
skill_category,
|
|
105
160
|
usage_count,
|
|
106
161
|
success_count,
|
|
107
162
|
CASE
|
|
108
163
|
WHEN usage_count > 0 THEN ROUND(100.0 * success_count / usage_count, 2)
|
|
109
164
|
ELSE 0
|
|
110
165
|
END as success_rate,
|
|
166
|
+
proficiency_level,
|
|
167
|
+
experience_points,
|
|
111
168
|
last_used_at,
|
|
112
169
|
first_used_at
|
|
113
170
|
FROM memory_evolution
|
|
114
171
|
ORDER BY usage_count DESC;
|
|
115
172
|
|
|
173
|
+
-- View: Active Learning
|
|
174
|
+
CREATE VIEW IF NOT EXISTS v_active_learning AS
|
|
175
|
+
SELECT
|
|
176
|
+
l.*,
|
|
177
|
+
CASE
|
|
178
|
+
WHEN progress_percentage = 0 THEN 'not_started'
|
|
179
|
+
WHEN progress_percentage < 50 THEN 'early_stage'
|
|
180
|
+
WHEN progress_percentage < 100 THEN 'in_progress'
|
|
181
|
+
ELSE 'completed'
|
|
182
|
+
END as stage
|
|
183
|
+
FROM memory_learning l
|
|
184
|
+
WHERE progress_status IN ('started', 'in_progress')
|
|
185
|
+
ORDER BY updated_at DESC;
|
|
186
|
+
|
|
116
187
|
-- View: Weekly Learning Report
|
|
117
188
|
CREATE VIEW IF NOT EXISTS v_weekly_learning_report AS
|
|
118
189
|
SELECT
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
190
|
+
learning_topic,
|
|
191
|
+
topic_category,
|
|
192
|
+
progress_status,
|
|
193
|
+
progress_percentage,
|
|
194
|
+
milestone_count,
|
|
195
|
+
completed_milestones,
|
|
196
|
+
updated_at,
|
|
197
|
+
CASE
|
|
198
|
+
WHEN progress_percentage = 100 THEN 'completed'
|
|
199
|
+
WHEN progress_percentage > 0 THEN 'in_progress'
|
|
200
|
+
ELSE 'not_started'
|
|
201
|
+
END as status_label
|
|
124
202
|
FROM memory_learning
|
|
125
203
|
WHERE updated_at >= datetime('now', '-7 days')
|
|
126
|
-
|
|
127
|
-
ORDER BY last_activity DESC;
|
|
204
|
+
ORDER BY updated_at DESC;
|
|
128
205
|
|
|
129
206
|
-- View: High Priority Items
|
|
130
|
-
CREATE VIEW IF NOT EXISTS
|
|
207
|
+
CREATE VIEW IF NOT EXISTS v_high_priority_messages AS
|
|
131
208
|
SELECT
|
|
132
209
|
'priority' as type,
|
|
133
210
|
id,
|
|
134
|
-
|
|
211
|
+
message_id,
|
|
135
212
|
priority_level as level,
|
|
136
|
-
|
|
137
|
-
|
|
213
|
+
importance_score,
|
|
214
|
+
context_summary as details,
|
|
138
215
|
created_at
|
|
139
216
|
FROM memory_priorities
|
|
140
|
-
WHERE priority_level
|
|
217
|
+
WHERE priority_level <= 2
|
|
141
218
|
UNION ALL
|
|
142
219
|
SELECT
|
|
143
220
|
'decision' as type,
|
|
144
221
|
id,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
222
|
+
message_id,
|
|
223
|
+
CASE outcome_status
|
|
224
|
+
WHEN 'pending' THEN 1
|
|
225
|
+
WHEN 'implemented' THEN 2
|
|
226
|
+
ELSE 3
|
|
227
|
+
END as level,
|
|
228
|
+
confidence_level as importance_score,
|
|
229
|
+
decision_question as details,
|
|
149
230
|
created_at
|
|
150
231
|
FROM memory_decisions
|
|
151
|
-
WHERE
|
|
232
|
+
WHERE outcome_status = 'pending' AND review_date <= datetime('now', '+7 days')
|
|
152
233
|
ORDER BY created_at DESC;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
V2.5 uses a new schema. No migration from V1/V2 is supported. Use init-demo.js for fresh setup.
|
package/package.json
CHANGED
package/check-db.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const sqlite3 = require('sqlite3').verbose();
|
|
2
|
-
const db = new sqlite3.Database('../memory-v2/memory-v2.5.db');
|
|
3
|
-
|
|
4
|
-
// Check memory_decisions table structure
|
|
5
|
-
db.all("PRAGMA table_info(memory_decisions)", (err, rows) => {
|
|
6
|
-
if (err) {
|
|
7
|
-
console.error('Error:', err);
|
|
8
|
-
} else {
|
|
9
|
-
console.log('memory_decisions columns:');
|
|
10
|
-
rows.forEach(r => console.log('- ' + r.name + ' (' + r.type + ')'));
|
|
11
|
-
}
|
|
12
|
-
db.close();
|
|
13
|
-
});
|
package/migrations/v1-to-v2.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Memory V1 to V2 Migration Script
|
|
4
|
-
* Migrates data from old memory format to V2 schema
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const sqlite3 = require('sqlite3').verbose();
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
|
|
11
|
-
class MemoryMigration {
|
|
12
|
-
constructor(sourceDbPath, targetDbPath = './memory-v2.db') {
|
|
13
|
-
this.sourceDbPath = sourceDbPath;
|
|
14
|
-
this.targetDbPath = targetDbPath;
|
|
15
|
-
this.sourceDb = null;
|
|
16
|
-
this.targetDb = null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async init() {
|
|
20
|
-
// Check if source exists
|
|
21
|
-
if (!fs.existsSync(this.sourceDbPath)) {
|
|
22
|
-
throw new Error(`Source database not found: ${this.sourceDbPath}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Open source database
|
|
26
|
-
this.sourceDb = new sqlite3.Database(this.sourceDbPath, sqlite3.OPEN_READONLY);
|
|
27
|
-
|
|
28
|
-
// Open/create target database
|
|
29
|
-
this.targetDb = new sqlite3.Database(this.targetDbPath);
|
|
30
|
-
|
|
31
|
-
console.log('ā
Connected to source and target databases');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async runSchema() {
|
|
35
|
-
const schemaPath = path.join(__dirname, '..', 'database', 'schema.sql');
|
|
36
|
-
|
|
37
|
-
if (!fs.existsSync(schemaPath)) {
|
|
38
|
-
throw new Error(`Schema file not found: ${schemaPath}`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const schema = fs.readFileSync(schemaPath, 'utf8');
|
|
42
|
-
const statements = schema
|
|
43
|
-
.split(';')
|
|
44
|
-
.map(s => s.trim())
|
|
45
|
-
.filter(s => s.length > 0);
|
|
46
|
-
|
|
47
|
-
for (const statement of statements) {
|
|
48
|
-
await this.runTarget(statement);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log('ā
Target database schema initialized');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async migratePriorities() {
|
|
55
|
-
console.log('š Migrating priorities...');
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
const rows = await this.allSource(
|
|
59
|
-
"SELECT * FROM memory_priorities WHERE created_at >= datetime('now', '-90 days')"
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
for (const row of rows) {
|
|
63
|
-
await this.runTarget(
|
|
64
|
-
`INSERT INTO memory_priorities
|
|
65
|
-
(msg_id, conv_id, priority_level, reasoning, category, created_at)
|
|
66
|
-
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
67
|
-
[row.msg_id, row.conv_id, row.priority_level, row.reasoning, row.category, row.created_at]
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
console.log(`ā
Migrated ${rows.length} priority records`);
|
|
72
|
-
} catch (err) {
|
|
73
|
-
console.log('ā¹ļø No priorities to migrate or table does not exist');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async migrateLearning() {
|
|
78
|
-
console.log('š Migrating learning records...');
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const rows = await this.allSource(
|
|
82
|
-
"SELECT * FROM memory_learning WHERE status != 'abandoned'"
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
for (const row of rows) {
|
|
86
|
-
await this.runTarget(
|
|
87
|
-
`INSERT INTO memory_learning
|
|
88
|
-
(msg_id, conv_id, topic, description, status, progress, started_at, updated_at, completed_at)
|
|
89
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
90
|
-
[row.msg_id, row.conv_id, row.topic, row.description, row.status,
|
|
91
|
-
row.progress, row.started_at, row.updated_at, row.completed_at]
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
console.log(`ā
Migrated ${rows.length} learning records`);
|
|
96
|
-
} catch (err) {
|
|
97
|
-
console.log('ā¹ļø No learning records to migrate or table does not exist');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async migrateDecisions() {
|
|
102
|
-
console.log('š Migrating decisions...');
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
const rows = await this.allSource(
|
|
106
|
-
"SELECT * FROM memory_decisions WHERE status IN ('pending', 'implemented')"
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
for (const row of rows) {
|
|
110
|
-
await this.runTarget(
|
|
111
|
-
`INSERT INTO memory_decisions
|
|
112
|
-
(msg_id, conv_id, summary, context, expected_outcome, actual_outcome,
|
|
113
|
-
status, review_scheduled_at, reviewed_at, created_at)
|
|
114
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
115
|
-
[row.msg_id, row.conv_id, row.summary, row.context, row.expected_outcome,
|
|
116
|
-
row.actual_outcome, row.status, row.review_scheduled_at, row.reviewed_at, row.created_at]
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
console.log(`ā
Migrated ${rows.length} decision records`);
|
|
121
|
-
} catch (err) {
|
|
122
|
-
console.log('ā¹ļø No decisions to migrate or table does not exist');
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async migrateEvolution() {
|
|
127
|
-
console.log('š Migrating skill evolution...');
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
const rows = await this.allSource(
|
|
131
|
-
"SELECT * FROM memory_evolution WHERE usage_count > 0"
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
for (const row of rows) {
|
|
135
|
-
await this.runTarget(
|
|
136
|
-
`INSERT INTO memory_evolution
|
|
137
|
-
(skill_name, category, usage_count, success_count, last_used_at, first_used_at)
|
|
138
|
-
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
139
|
-
[row.skill_name, row.category, row.usage_count, row.success_count,
|
|
140
|
-
row.last_used_at, row.first_used_at]
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
console.log(`ā
Migrated ${rows.length} skill evolution records`);
|
|
145
|
-
} catch (err) {
|
|
146
|
-
console.log('ā¹ļø No evolution records to migrate or table does not exist');
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async runTarget(sql, params = []) {
|
|
151
|
-
return new Promise((resolve, reject) => {
|
|
152
|
-
this.targetDb.run(sql, params, function(err) {
|
|
153
|
-
if (err) reject(err);
|
|
154
|
-
else resolve({ id: this.lastID, changes: this.changes });
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async allSource(sql, params = []) {
|
|
160
|
-
return new Promise((resolve, reject) => {
|
|
161
|
-
this.sourceDb.all(sql, params, (err, rows) => {
|
|
162
|
-
if (err) reject(err);
|
|
163
|
-
else resolve(rows);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async close() {
|
|
169
|
-
if (this.sourceDb) {
|
|
170
|
-
await new Promise((resolve) => this.sourceDb.close(resolve));
|
|
171
|
-
}
|
|
172
|
-
if (this.targetDb) {
|
|
173
|
-
await new Promise((resolve) => this.targetDb.close(resolve));
|
|
174
|
-
}
|
|
175
|
-
console.log('ā
Database connections closed');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async migrate() {
|
|
179
|
-
try {
|
|
180
|
-
await this.init();
|
|
181
|
-
await this.runSchema();
|
|
182
|
-
await this.migratePriorities();
|
|
183
|
-
await this.migrateLearning();
|
|
184
|
-
await this.migrateDecisions();
|
|
185
|
-
await this.migrateEvolution();
|
|
186
|
-
|
|
187
|
-
console.log('\nš Migration completed successfully!');
|
|
188
|
-
console.log(`š New database: ${path.resolve(this.targetDbPath)}`);
|
|
189
|
-
} catch (err) {
|
|
190
|
-
console.error('\nā Migration failed:', err.message);
|
|
191
|
-
process.exit(1);
|
|
192
|
-
} finally {
|
|
193
|
-
await this.close();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// CLI usage
|
|
199
|
-
if (require.main === module) {
|
|
200
|
-
const sourceDb = process.argv[2];
|
|
201
|
-
const targetDb = process.argv[3] || './memory-v2.db';
|
|
202
|
-
|
|
203
|
-
if (!sourceDb) {
|
|
204
|
-
console.log('Usage: node migrations/v1-to-v2.js <source-v1.db> [target-v2.db]');
|
|
205
|
-
console.log('Example: node migrations/v1-to-v2.js ./memory-v1.db ./memory-v2.db');
|
|
206
|
-
process.exit(1);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const migration = new MemoryMigration(sourceDb, targetDb);
|
|
210
|
-
migration.migrate();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
module.exports = MemoryMigration;
|