This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
|
||||
/** Replace the old opt-in default while preserving an existing nonempty selection. */
|
||||
export function migrateDiscordPublicationDefaults(handle: Database.Database): void {
|
||||
const row = handle.prepare('SELECT value FROM discord_configuration WHERE id=1').get() as
|
||||
{ value: string } | undefined;
|
||||
if (!row) return;
|
||||
const settings = JSON.parse(row.value) as Record<string, unknown>;
|
||||
if ('excludedServers' in settings) return;
|
||||
const published = new Set(settings.publishedServers as string[]);
|
||||
settings.excludedServers = published.size
|
||||
? (
|
||||
handle
|
||||
.prepare('SELECT name FROM servers WHERE destroyed_at IS NULL ORDER BY name')
|
||||
.all() as { name: string }[]
|
||||
)
|
||||
.map((server) => server.name)
|
||||
.filter((name) => !published.has(name))
|
||||
: [];
|
||||
delete settings.publishedServers;
|
||||
handle
|
||||
.prepare('UPDATE discord_configuration SET value=? WHERE id=1')
|
||||
.run(JSON.stringify(settings));
|
||||
}
|
||||
Reference in New Issue
Block a user