212ff3ff80
Introduce UMS ingest/snapshot pipeline, Context Planner with multi-source recall, runtime context injection, canonical user mapping, and session snapshot loading on auth/me. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Create RDS database memind_user_model (if missing) and run UMS schema migrate.
|
|
*
|
|
* Env (pick one):
|
|
* UMS_DATABASE_URL=mysql://user:pass@host:3306/memind_user_model
|
|
* DATABASE_URL / MEINPUT_DATABASE_URL (derives sibling DB on same host)
|
|
*/
|
|
import { spawnSync } from 'node:child_process';
|
|
import mysql from 'mysql2/promise';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
|
|
function deriveUmsUrl() {
|
|
if (process.env.UMS_DATABASE_URL) return process.env.UMS_DATABASE_URL;
|
|
const base = process.env.DATABASE_URL ?? process.env.MEINPUT_DATABASE_URL ?? '';
|
|
if (!base) return null;
|
|
const u = new URL(base);
|
|
u.pathname = '/memind_user_model';
|
|
return u.toString();
|
|
}
|
|
|
|
function adminUrl(dbUrl) {
|
|
const u = new URL(dbUrl);
|
|
u.pathname = '/';
|
|
return u.toString();
|
|
}
|
|
|
|
async function main() {
|
|
const umsUrl = deriveUmsUrl();
|
|
if (!umsUrl) {
|
|
console.error('Set UMS_DATABASE_URL or DATABASE_URL');
|
|
process.exit(1);
|
|
}
|
|
|
|
const admin = await mysql.createConnection({ uri: adminUrl(umsUrl) });
|
|
try {
|
|
await admin.query(
|
|
'CREATE DATABASE IF NOT EXISTS memind_user_model CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci',
|
|
);
|
|
console.log('Database memind_user_model ready.');
|
|
} finally {
|
|
await admin.end();
|
|
}
|
|
|
|
const child = spawnSync('node', ['user-model-service/migrate.mjs'], {
|
|
cwd: root,
|
|
stdio: 'inherit',
|
|
env: { ...process.env, UMS_DATABASE_URL: umsUrl },
|
|
});
|
|
process.exit(child.status ?? 1);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|