feat(api): implement secure portfolio history, daily FX and atomic backups

This commit is contained in:
陈煜 committed 2026-10-01 16:21:16 +08:00
1 parent 67220e38ed
commit 99174a3da5
25 files changed
+1750 -28

No files matched your search

+40 -3
View File
@@ -1,3 +1,40 @@
require('dotenv').config({quiet:true});
const mysql=require('mysql2/promise');
(async()=>{let db;try {const u=new URL(process.env.DATABASE_URL);const name=u.pathname.slice(1);if(!/^[a-zA-Z0-9_]+$/.test(name))throw Error();db=await mysql.createConnection({host:u.hostname,port:Number(u.port||3306),user:decodeURIComponent(u.username),password:decodeURIComponent(u.password)});const [existing]=await db.execute('SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME=?',[name]);if(existing.length){const [tables]=await db.execute('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=?',[name]);console.log('Database already exists; tables:',tables.map(t=>t.TABLE_NAME));}else {await db.query('CREATE DATABASE `'+name+'` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');console.log('Created new empty project database.');}}catch(e){console.error('Database preflight failed:',e.code||'configuration error');process.exitCode=1;}finally{if(db)await db.end();}})();
require('dotenv').config({ quiet: true });
const mysql = require('mysql2/promise');
(async () => {
let db;
try {
const u = new URL(process.env.DATABASE_URL);
const name = u.pathname.slice(1);
if (!/^[a-zA-Z0-9_]+$/.test(name)) throw Error();
db = await mysql.createConnection({
host: u.hostname,
port: Number(u.port || 3306),
user: decodeURIComponent(u.username),
password: decodeURIComponent(u.password),
});
const [existing] = await db.execute(
'SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME=?',
[name],
);
if (existing.length) {
const [tables] = await db.execute(
'SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=?',
[name],
);
console.log(
'Database already exists; tables:',
tables.map((t) => t.TABLE_NAME),
);
} else {
await db.query(
'CREATE DATABASE `' + name + '` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci',
);
console.log('Created new empty project database.');
}
} catch (e) {
console.error('Database preflight failed:', e.code || 'configuration error');
process.exitCode = 1;
} finally {
if (db) await db.end();
}
})();