feat: 支持托管中转主机和节点接入线路

This commit is contained in:
2026-09-30 17:36:17 +08:00
parent ac5fed695c
commit b6aa2bf30d
15 changed files with 1338 additions and 5 deletions
+31 -3
View File
@@ -29,6 +29,8 @@ function snapshot(db: Database.Database) {
"managed_certificates",
"node_installations",
"node_agent_counters",
"relay_hosts",
"relay_routes",
].includes(name),
)
.map(({ name }) => [name, db.prepare(`SELECT * FROM "${name}"`).all()]),
@@ -49,7 +51,7 @@ test("fresh database exactly matches the inspected remote v4 column definitions"
const fresh = new Database(":memory:");
const remote = remoteDb();
migrateDatabase(fresh);
assert.equal(fresh.pragma("user_version", { simple: true }), 6);
assert.equal(fresh.pragma("user_version", { simple: true }), 7);
for (const { name } of remote
.prepare("SELECT name FROM sqlite_master WHERE type='table'")
.all() as { name: string }[]) {
@@ -102,7 +104,7 @@ for (const existing of [
if (!existing.includes(field)) delete row[field];
}
assert.deepEqual(after, before);
assert.equal(db.pragma("user_version", { simple: true }), 6);
assert.equal(db.pragma("user_version", { simple: true }), 7);
db.close();
});
}
@@ -132,8 +134,34 @@ test("failed migrations roll back all statements and future schemas are not down
db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all(),
[{ name: "hy2_users" }],
);
db.pragma("user_version = 7");
db.pragma("user_version = 8");
assert.throws(() => migrateDatabase(db), /版本/);
assert.equal(db.pragma("user_version", { simple: true }), 8);
db.close();
});
test("v6 upgrade preserves AnyTLS installations, certificates and counters", () => {
const db = remoteDb();
seed(db);
migrateDatabase(db);
db.exec(
"DROP TABLE relay_routes; DROP TABLE relay_hosts; PRAGMA user_version=6;",
);
db.exec(`INSERT INTO managed_certificates VALUES(1,'wildcard','certificate','encrypted-key','2030-01-01','2026-01-01');
INSERT INTO node_installations(id,token_hash,token_encrypted,certificate_id,slug,name,server_host,sni,origin,expires_at,created_at,node_id,protocol) VALUES('install','hash','encrypted',1,'anytls','AnyTLS','jp2.example','jp2.example','https://panel.example','2030-01-01','2026-01-01',17,'anytls');
INSERT INTO node_agent_counters VALUES(17,'boot:1','original-auth',128,256);`);
const tables = [
"managed_certificates",
"node_installations",
"node_agent_counters",
];
const before = tables.map((t) => db.prepare(`SELECT * FROM ${t}`).all());
migrateDatabase(db);
migrateDatabase(db);
assert.deepEqual(
tables.map((t) => db.prepare(`SELECT * FROM ${t}`).all()),
before,
);
assert.equal(db.pragma("user_version", { simple: true }), 7);
db.close();
});