feat: per-profile separate SQLite logbook file (config never swapped)
Design flaw: the SQLite backend conflated the app/config database (opslog.db — settings + profiles) with the QSO logbook. connectLogbook returned a.db for any non-MySQL profile, so the ONLY way to get a separate SQLite logbook was the whole-app "change database location" pointer — which swapped config + profiles too, wiping the operator's setup (reported: creating Jerem.db lost all configs). profile.ProfileDB gains a Path field: a non-empty path routes that profile's logbook to its own SQLite file (db.Open creates + migrates it on first use), while opslog.db keeps settings/profiles. connectLogbook opens the file; empty path = shared db (unchanged default, backward compatible). MySQLSettings carries sqlite_path; Get/Save wire it through. UI: the Database panel gains a third backend option "SQLite — separate file" with a file picker, and now clearly labels the shared application database (settings + profiles) vs this profile's logbook, so the two are never confused.
This commit is contained in:
@@ -1299,7 +1299,7 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
||||
|
||||
const [dbSettings, setDbSettings] = useState<{ path: string; default_path: string; is_custom: boolean }>({ path: '', default_path: '', is_custom: false });
|
||||
const [dbMsg, setDbMsg] = useState('');
|
||||
type MySQLCfg = { enabled: boolean; host: string; port: number; user: string; password: string; database: string };
|
||||
type MySQLCfg = { enabled: boolean; host: string; port: number; user: string; password: string; database: string; sqlite_path?: string };
|
||||
const [mysqlCfg, setMysqlCfg] = useState<MySQLCfg>({ enabled: false, host: '', port: 3306, user: '', password: '', database: '' });
|
||||
const setMysqlField = (patch: Partial<MySQLCfg>) => setMysqlCfg((s) => ({ ...s, ...patch }));
|
||||
const [mysqlMsg, setMysqlMsg] = useState('');
|
||||
@@ -4310,10 +4310,22 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
||||
// Switching the logbook backend applies immediately (no restart): the local
|
||||
// SQLite file always stays the config store; only the QSO logbook moves.
|
||||
function useLocalLogbook() {
|
||||
SaveMySQLSettings({ ...mysqlCfg, enabled: false } as any)
|
||||
.then(async () => { setMysqlField({ enabled: false }); setRestartMsg(t('db.switchedSqlite')); await refreshBackend(); })
|
||||
SaveMySQLSettings({ ...mysqlCfg, enabled: false, sqlite_path: '' } as any)
|
||||
.then(async () => { setMysqlField({ enabled: false, sqlite_path: '' }); setRestartMsg(t('db.switchedSqlite')); await refreshBackend(); })
|
||||
.catch((e: any) => setErr(String(e?.message ?? e)));
|
||||
}
|
||||
// Route THIS profile's logbook to its own SQLite file (config stays in
|
||||
// opslog.db). db.Open creates+migrates the file if it's new. Pick a name/place.
|
||||
async function pickSeparateSqlite() {
|
||||
try {
|
||||
const p = await PickSaveDatabase();
|
||||
if (!p) return;
|
||||
await SaveMySQLSettings({ ...mysqlCfg, enabled: false, sqlite_path: p } as any);
|
||||
setMysqlField({ enabled: false, sqlite_path: p });
|
||||
setRestartMsg(t('db.switchedSqliteFile'));
|
||||
await refreshBackend();
|
||||
} catch (e: any) { setErr(String(e?.message ?? e)); }
|
||||
}
|
||||
function connectMysql() {
|
||||
SaveMySQLSettings(mysqlCfg as any)
|
||||
.then(async () => { setRestartMsg(t('db.switchedMysql')); await refreshBackend(); })
|
||||
@@ -4329,17 +4341,20 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
||||
<div className="grid grid-cols-[130px_1fr] gap-2 items-center max-w-2xl mb-1">
|
||||
<Label className="text-sm">{t('db.backend')}</Label>
|
||||
<Select
|
||||
value={mysqlCfg.enabled ? 'mysql' : 'sqlite'}
|
||||
value={mysqlCfg.enabled ? 'mysql' : (mysqlCfg.sqlite_path ? 'sqlite_file' : 'sqlite')}
|
||||
onValueChange={(v) => {
|
||||
const enabled = v === 'mysql';
|
||||
setMysqlField({ enabled });
|
||||
setRestartMsg('');
|
||||
if (!enabled) useLocalLogbook(); // switching to local applies at once
|
||||
if (v === 'mysql') { setMysqlField({ enabled: true }); return; }
|
||||
if (v === 'sqlite') { useLocalLogbook(); return; } // shared app db
|
||||
// sqlite_file: keep any existing path; if none, prompt to pick one.
|
||||
setMysqlField({ enabled: false });
|
||||
if (!mysqlCfg.sqlite_path) pickSeparateSqlite();
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="h-8 w-72"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="sqlite">{t('db.optSqlite')}</SelectItem>
|
||||
<SelectItem value="sqlite_file">{t('db.optSqliteFile')}</SelectItem>
|
||||
<SelectItem value="mysql">{t('db.optMysql')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
@@ -4362,10 +4377,27 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
||||
)}
|
||||
|
||||
{/* SQLite: local logbook file management */}
|
||||
{!mysqlCfg.enabled && (
|
||||
{/* Separate per-profile SQLite logbook FILE (config stays in opslog.db) */}
|
||||
{!mysqlCfg.enabled && mysqlCfg.sqlite_path && (
|
||||
<div className="space-y-3 max-w-2xl">
|
||||
<div className="space-y-1">
|
||||
<Label>{t('db.logbookFile')}</Label>
|
||||
<div className="font-mono text-xs bg-muted/40 border border-border rounded-md px-3 py-2 break-all">{mysqlCfg.sqlite_path}</div>
|
||||
<p className="text-[11px] text-muted-foreground">{t('db.logbookFileHint')}</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button variant="outline" size="sm" onClick={pickSeparateSqlite}><FolderOpen className="size-3.5" /> {t('db.chooseFile')}</Button>
|
||||
</div>
|
||||
{restartMsg && <div className="text-xs text-success-muted-foreground">{restartMsg}</div>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Shared application/config database (opslog.db) = settings + profiles +
|
||||
this profile's QSOs when it uses the default logbook. */}
|
||||
{!mysqlCfg.enabled && !mysqlCfg.sqlite_path && (
|
||||
<div className="space-y-4 max-w-2xl">
|
||||
<div className="space-y-1">
|
||||
<Label>{t('db.current')}</Label>
|
||||
<Label>{t('db.appDb')}</Label>
|
||||
<div className="font-mono text-xs bg-muted/40 border border-border rounded-md px-3 py-2 break-all">
|
||||
{dbSettings.path || '—'}
|
||||
{dbSettings.is_custom
|
||||
@@ -4373,6 +4405,7 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
||||
: <span className="ml-2 text-[10px] text-muted-foreground">{t('db.default')}</span>}
|
||||
</div>
|
||||
<div className="text-[10px] text-muted-foreground">{t('db.defaultLabel')} <span className="font-mono">{dbSettings.default_path}</span></div>
|
||||
<p className="text-[11px] text-muted-foreground">{t('db.appDbHint')}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
|
||||
@@ -286,7 +286,9 @@ const en: Dict = {
|
||||
'prof.hint': 'Switch between operating identities (home / portable / SOTA / contest). Pick a profile here, then edit its fields in the other sections (Station Information, etc.) — changes are saved against the selected profile.', 'prof.active': 'ACTIVE', 'prof.duplicate': 'Duplicate', 'prof.delete': 'Delete', 'prof.profileName': 'Profile name',
|
||||
'prof.configId': 'Configuration ID', 'prof.description': 'Description', 'prof.new': 'New', 'prof.newTitle': 'Create a new empty profile', 'prof.dupTitle': 'Clone the selected profile (keeps all its fields)', 'prof.setActive': 'Set active', 'prof.setActiveTitle': 'Activate the selected profile — new QSOs will use its MY_* fields', 'prof.deleteTitle': 'Delete the selected profile', 'prof.cantDeleteLast': 'Cannot delete the last profile', 'prof.activeSuffix': ' (active)', 'prof.viewingNote': "You're viewing {name}. The active profile is {active} — its values are stamped on new QSOs. Click Set active to switch.",
|
||||
// Database panel
|
||||
'db.optSqlite': 'SQLite — local file (solo)', 'db.optMysql': 'MySQL — shared server (multi-operator)', 'db.profileHint': 'This is the logbook for the active profile. Different profiles can point at different databases — switching profile switches the logbook.',
|
||||
'db.optSqlite': 'SQLite — shared local database (default)', 'db.optSqliteFile': 'SQLite — separate file (this profile only)', 'db.optMysql': 'MySQL — shared server (multi-operator)', 'db.profileHint': 'This is the logbook for the active profile. Different profiles can point at different databases — switching profile switches the logbook.',
|
||||
'db.logbookFile': "This profile's logbook file", 'db.logbookFileHint': "Only this profile's QSOs live here. Your settings and profiles stay in the shared app database, so switching this never affects your other profiles — ideal for a visiting operator. A new name is created automatically.", 'db.chooseFile': 'Choose file…', 'db.switchedSqliteFile': 'Logbook now uses a separate SQLite file.',
|
||||
'db.appDb': 'Shared application database', 'db.appDbHint': 'Holds your settings, profiles and (for this profile) the QSOs. Changing its location moves the WHOLE install — settings and profiles included.',
|
||||
'db.saveSwitch': 'Save & switch logbook', 'db.switchedMysql': 'Logbook switched to MySQL ✓', 'db.switchedSqlite': 'Logbook switched to local SQLite ✓',
|
||||
'db.backend': 'Backend', 'db.configLocal': 'settings stay in the local SQLite file', 'db.connectUse': 'Connect & use',
|
||||
'db.savedRestart': 'Saved. Restart OpsLog to open this logbook:', 'db.restartNow': 'Restart OpsLog', 'db.restartHint': '(reopens automatically)',
|
||||
@@ -641,7 +643,9 @@ const fr: Dict = {
|
||||
'prof.deleteConfirm': 'Supprimer le profil « {name} » ? Tous ses réglages seront perdus.', 'prof.dupPrompt': 'Nom du nouveau profil (copie de « {name} ») :', 'prof.dupSuffix': '{name} Copie', 'prof.newPrompt': 'Nom du nouveau profil :', 'prof.newDefault': 'Nouveau profil',
|
||||
'prof.hint': "Bascule entre tes identités d'opération (maison / portable / SOTA / contest). Choisis un profil ici, puis édite ses champs dans les autres sections (Informations station, etc.) — les changements sont enregistrés sur le profil sélectionné.", 'prof.active': 'ACTIF', 'prof.duplicate': 'Dupliquer', 'prof.delete': 'Supprimer', 'prof.profileName': 'Nom du profil',
|
||||
'prof.configId': 'ID de configuration', 'prof.description': 'Description', 'prof.new': 'Nouveau', 'prof.newTitle': 'Créer un nouveau profil vierge', 'prof.dupTitle': 'Cloner le profil sélectionné (garde tous ses champs)', 'prof.setActive': 'Activer', 'prof.setActiveTitle': 'Activer le profil sélectionné — les nouveaux QSO utiliseront ses champs MY_*', 'prof.deleteTitle': 'Supprimer le profil sélectionné', 'prof.cantDeleteLast': 'Impossible de supprimer le dernier profil', 'prof.activeSuffix': ' (actif)', 'prof.viewingNote': 'Tu consultes {name}. Le profil actif est {active} — ses valeurs sont inscrites sur les nouveaux QSO. Clique « Activer » pour basculer.',
|
||||
'db.optSqlite': 'SQLite — fichier local (solo)', 'db.optMysql': 'MySQL — serveur partagé (multi-opérateur)', 'db.profileHint': 'Ceci est le journal du profil actif. Des profils différents peuvent pointer vers des bases différentes — changer de profil change le journal.',
|
||||
'db.optSqlite': 'SQLite — base locale partagée (défaut)', 'db.optSqliteFile': 'SQLite — fichier séparé (ce profil seulement)', 'db.optMysql': 'MySQL — serveur partagé (multi-opérateur)', 'db.profileHint': 'Ceci est le journal du profil actif. Des profils différents peuvent pointer vers des bases différentes — changer de profil change le journal.',
|
||||
'db.logbookFile': 'Fichier journal de ce profil', 'db.logbookFileHint': "Seuls les QSO de ce profil y sont stockés. Tes réglages et profils restent dans la base applicative partagée, donc changer ceci n'affecte jamais tes autres profils — idéal pour un opérateur de passage. Un nouveau nom est créé automatiquement.", 'db.chooseFile': 'Choisir le fichier…', 'db.switchedSqliteFile': 'Le journal utilise désormais un fichier SQLite séparé.',
|
||||
'db.appDb': 'Base applicative partagée', 'db.appDbHint': "Contient tes réglages, tes profils et (pour ce profil) les QSO. Changer son emplacement déplace TOUTE l'installation — réglages et profils compris.",
|
||||
'db.saveSwitch': 'Enregistrer & basculer le journal', 'db.switchedMysql': 'Journal basculé vers MySQL ✓', 'db.switchedSqlite': 'Journal basculé vers SQLite local ✓',
|
||||
'db.backend': 'Base de données', 'db.configLocal': 'les réglages restent dans le fichier SQLite local', 'db.connectUse': 'Connecter et utiliser',
|
||||
'db.savedRestart': 'Enregistré. Redémarrez OpsLog pour ouvrir cette base :', 'db.restartNow': 'Redémarrer OpsLog', 'db.restartHint': '(réouverture automatique)',
|
||||
|
||||
@@ -2315,6 +2315,7 @@ export namespace main {
|
||||
user: string;
|
||||
password: string;
|
||||
database: string;
|
||||
sqlite_path?: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new MySQLSettings(source);
|
||||
@@ -2328,6 +2329,7 @@ export namespace main {
|
||||
this.user = source["user"];
|
||||
this.password = source["password"];
|
||||
this.database = source["database"];
|
||||
this.sqlite_path = source["sqlite_path"];
|
||||
}
|
||||
}
|
||||
export class OfflineStatus {
|
||||
@@ -3365,6 +3367,7 @@ export namespace profile {
|
||||
user: string;
|
||||
password: string;
|
||||
database: string;
|
||||
path?: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ProfileDB(source);
|
||||
@@ -3378,6 +3381,7 @@ export namespace profile {
|
||||
this.user = source["user"];
|
||||
this.password = source["password"];
|
||||
this.database = source["database"];
|
||||
this.path = source["path"];
|
||||
}
|
||||
}
|
||||
export class Profile {
|
||||
|
||||
Reference in New Issue
Block a user