[READ-ONLY] Mirror of https://github.com/FoxxMD/multi-scrobbler. Scrobble plays from multiple sources to multiple clients docs.multi-scrobbler.app
deezer docker jellyfin koito lastfm listenbrainz maloja mopidy mpris music music-assistant plex scrobble self-hosted spotify subsonic tautulli youtube-music
0

Configure Feed

Select the types of activity you want to include in your feed.

feat(database): Simplify loading db for tests

FoxxMD (May 11, 2026, 4:36 PM UTC) 57f89228 97a01b6b

+15 -8
+9 -3
src/backend/common/database/drizzle/drizzleUtils.ts
··· 88 88 } 89 89 } 90 90 91 - export const getDb = async (dbVal: string | PGlite, opts: { logger?: Logger, backupPath?: string } = {}) => { 91 + export const getDb = async (dbVal: string | PGlite, opts: { logger?: Logger, backupPath?: string, loadDataDir?: Promise<Blob> } = {}) => { 92 92 const { 93 93 logger = loggerNoop, 94 94 backupPath, 95 + loadDataDir 95 96 } = opts; 96 97 let client: PGlite; 97 98 ··· 103 104 opts.loadDataDir = new Blob([fsSync.readFileSync(backupPath)]); 104 105 } 105 106 } 107 + // only load one 108 + // but this could be for a memory db so don't put it in above if 109 + if(loadDataDir !== undefined && backupDb === undefined) { 110 + opts.loadDataDir = await loadDataDir 111 + } 106 112 client = await PGlite.create(opts); 107 113 } else { 108 114 client = dbVal; ··· 144 150 } 145 151 } 146 152 147 - export const getMigratedDb = async (dbPath: string, opts: { logger?: Logger, workingDirectory?: string, migrationsFolder?: string } = {}): Promise<[DbConcrete, boolean]> => { 153 + export const getMigratedDb = async (dbPath: string, opts: { logger?: Logger, workingDirectory?: string, migrationsFolder?: string, backupPath?: string, loadDataDir?: Promise<Blob> } = {}): Promise<[DbConcrete, boolean]> => { 148 154 const { 149 155 logger = loggerNoop 150 156 } = opts; ··· 175 181 await fs.rename(backupPath, usedBackedPath); 176 182 } else { 177 183 logger.info('Detected no database, creating a new one...'); 178 - db = await getDb(dbPath); 184 + db = await getDb(dbPath, opts); 179 185 isNew = true; 180 186 } 181 187 } else {
+6 -5
src/backend/tests/database/drizzle.test.ts
··· 20 20 import { PlaySelect } from '../../common/database/drizzle/drizzleTypes.js'; 21 21 import { loggerDebug } from '@foxxmd/logging'; 22 22 import { transientDb } from '../utils/TransientTestUtils.js'; 23 + import { dataDir } from '@electric-sql/pglite-prepopulatedfs' 23 24 24 25 // would be great to push migrations directly from schema but doesn't seem supported in newest beta 25 26 // https://github.com/drizzle-team/drizzle-orm/discussions/4373 ··· 29 30 it('Detects non-existent db', async function () { 30 31 31 32 await withLocalTmpDir(async () => { 32 - const [db, isNew] = await getMigratedDb(getDbPath('notreal', process.cwd())); 33 + const [db, isNew] = await getMigratedDb(getDbPath('notreal', process.cwd()), { loadDataDir: dataDir() }); 33 34 expect(isNew).is.true; 34 35 }, {postfix: 'noDb'}); 35 36 ··· 37 38 38 39 it('Detects abnormal db', async function () { 39 40 // database exists but there is no __drizzle_migrations table 40 - const db = await getDb((await getPrepopulatedMemoryPGlite())); 41 + const db = await getDb(':memory:', { loadDataDir: dataDir() }); 41 42 const [shouldBackup, pending] = await shouldBackupDb(db); 42 43 expect(shouldBackup).is.true; 43 44 expect(pending).length(0); ··· 57 58 try { 58 59 await fs.cp(path.resolve(projectDir, `src/backend/common/database/drizzle/migrations/${migrationFiles[0]}`), path.resolve('./migrations/', migrationFiles[0]), { recursive: true }); 59 60 const mf = path.resolve('./migrations'); 60 - const db = await getDb((await getPrepopulatedFSPGlite(getDbPath('msDb', process.cwd())))); 61 + const db = await getDb(':memory:', {loadDataDir: dataDir()}); 61 62 await migrateDb(db, { migrationsFolder: mf }); 62 63 const res = await x('drizzle-kit', [ 63 64 'generate', ··· 95 96 try { 96 97 await fs.cp(path.resolve(projectDir, `src/backend/common/database/drizzle/migrations/${migrationFiles[0]}`), path.resolve('./migrations/', migrationFiles[0]), { recursive: true }); 97 98 const mf = path.resolve('./migrations'); 98 - const db = await getDb((await getPrepopulatedFSPGlite(getDbPath('msDb', process.cwd())))); 99 + const db = await getDb(':memory:', {loadDataDir: dataDir()}); 99 100 await migrateDb(db, { migrationsFolder: mf }); 100 101 const [shouldBackup, pending] = await shouldBackupDb(db, { migrationsFolder: mf }); 101 102 expect(shouldBackup).is.false; ··· 121 122 try { 122 123 await fs.cp(path.resolve(projectDir, `src/backend/common/database/drizzle/migrations/${migrationFiles[0]}`), path.resolve('./migrations/', migrationFiles[0]), { recursive: true }); 123 124 const mf = path.resolve('./migrations'); 124 - const db = await getDb((await getPrepopulatedFSPGlite(dbPath))); 125 + const db = await getDb(dbPath, {loadDataDir: dataDir()}); 125 126 await migrateDb(db, { migrationsFolder: mf }); 126 127 const res = await x('drizzle-kit', [ 127 128 'generate',