mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-11-27 08:08:34 +03:00
fix #15650 fix #15530 fix #15534 fix #15506 #### PR Dependency Tree * **PR #15649** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary * **New Features** * Admin settings show configuration sources and secret status, conceal secret values, and allow database-level overrides to be cleared. * Self-hosted deployments can automatically upgrade existing configuration files. * **Improvements** * Configuration changes apply without restarting the server, and storage settings reload automatically. * Uploads support runtime-managed proxy settings and signed upload tokens. * Incomplete managed Copilot profiles are disabled during migration. * Saving an AI response as a document more reliably targets the matching editor. * **Documentation** * The CLI clarifies that imported configuration changes take effect after the next server start. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
103 lines
2.6 KiB
JavaScript
103 lines
2.6 KiB
JavaScript
import { execSync } from 'node:child_process';
|
|
import { generateKeyPairSync } from 'node:crypto';
|
|
import fs from 'node:fs';
|
|
import { homedir } from 'node:os';
|
|
import path from 'node:path';
|
|
|
|
import { upgradeConfig } from './upgrade-config.js';
|
|
|
|
const SELF_HOST_CONFIG_DIR = `${homedir()}/.affine/config`;
|
|
|
|
function generatePrivateKey() {
|
|
const key = generateKeyPairSync('ec', {
|
|
namedCurve: 'prime256v1',
|
|
}).privateKey.export({
|
|
type: 'sec1',
|
|
format: 'pem',
|
|
});
|
|
|
|
if (key instanceof Buffer) {
|
|
return key.toString('utf-8');
|
|
}
|
|
|
|
return key;
|
|
}
|
|
|
|
/**
|
|
* @type {Array<{ to: string; generator: () => string }>}
|
|
*/
|
|
const files = [{ to: 'private.key', generator: generatePrivateKey }];
|
|
|
|
function prepare() {
|
|
fs.mkdirSync(SELF_HOST_CONFIG_DIR, { recursive: true });
|
|
|
|
upgradeConfig();
|
|
|
|
for (const { to, generator } of files) {
|
|
const targetFilePath = path.join(SELF_HOST_CONFIG_DIR, to);
|
|
if (!fs.existsSync(targetFilePath)) {
|
|
console.log(`creating config file [${targetFilePath}].`);
|
|
fs.writeFileSync(targetFilePath, generator(), 'utf-8');
|
|
}
|
|
}
|
|
}
|
|
|
|
function runPrismaMigrations() {
|
|
console.log('running prisma migrations.');
|
|
execSync('yarn prisma migrate deploy', {
|
|
encoding: 'utf-8',
|
|
env: process.env,
|
|
stdio: 'inherit',
|
|
});
|
|
}
|
|
|
|
function runDataMigrations() {
|
|
console.log('running data migrations.');
|
|
execSync('yarn cli run', {
|
|
encoding: 'utf-8',
|
|
env: process.env,
|
|
stdio: 'inherit',
|
|
});
|
|
}
|
|
|
|
function fixFailedMigrations() {
|
|
console.log('fixing failed migrations.');
|
|
const maybeFailedMigrations = [
|
|
'20250521083048_fix_workspace_embedding_chunk_primary_key',
|
|
];
|
|
for (const migration of maybeFailedMigrations) {
|
|
try {
|
|
execSync(`yarn prisma migrate resolve --rolled-back ${migration}`, {
|
|
encoding: 'utf-8',
|
|
env: process.env,
|
|
stdio: 'pipe',
|
|
});
|
|
console.log(`migration [${migration}] has been rolled back.`);
|
|
} catch (err) {
|
|
if (
|
|
err.message.includes(
|
|
'cannot be rolled back because it is not in a failed state'
|
|
) ||
|
|
err.message.includes(
|
|
'cannot be rolled back because it was never applied'
|
|
) ||
|
|
err.message.includes(
|
|
'called markMigrationRolledBack on a database without migrations table'
|
|
)
|
|
) {
|
|
// migration has been rolled back, skip it
|
|
continue;
|
|
}
|
|
// ignore other errors
|
|
console.log(
|
|
`migration [${migration}] rolled back failed. ${err.message}`
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
prepare();
|
|
fixFailedMigrations();
|
|
runPrismaMigrations();
|
|
runDataMigrations();
|