Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep music video media-mode file migration independent of PostgreSQL (#10941)

Adam Eivy508dde2e61da
diff --git a/scripts/migrations/421-music-video-media-modes.js b/scripts/migrations/421-music-video-media-modes.js
index a66463bccd..91cc600102 100644
--- a/scripts/migrations/421-music-video-media-modes.js
+++ b/scripts/migrations/421-music-video-media-modes.js
@@ -15,15 +15,7 @@ export default {
if (!Array.isArray(records)) throw new Error('Music Video project file must contain an array');
await writeJsonAtomic(file, records.map(migrateMediaMode));
}
- const { query } = await import('../../server/lib/db.js');
- const table = await query("SELECT to_regclass('public.music_video_projects') AS name");
- if (table.rows[0]?.name) {
- const { rows } = await query("SELECT id, data FROM music_video_projects WHERE NOT data ? 'mediaMode'");
- for (const { id, data } of rows) {
- await query(`UPDATE music_video_projects SET data = jsonb_set(data, '{mediaMode}', to_jsonb($2::text))
- WHERE id = $1 AND NOT data ? 'mediaMode'`, [id, migrateMediaMode(data).mediaMode]);
- }
- }
+ // Postgres rows are pinned by db-migration 015, which runs under the DB runner.
return { success: true };
},
};
diff --git a/scripts/migrations/421-music-video-media-modes.test.js b/scripts/migrations/421-music-video-media-modes.test.js
new file mode 100644
index 0000000000..8588ba9cd3
--- /dev/null
+++ b/scripts/migrations/421-music-video-media-modes.test.js
@@ -0,0 +1,24 @@
+import { describe, it, expect, vi } from 'vitest';
+import { mkdtemp, mkdir, writeFile, readFile, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+// A DB import would fail loudly if the migration touched Postgres.
+vi.mock('../../server/lib/db.js', () => { throw new Error('ECONNREFUSED'); });
+
+import migration from './421-music-video-media-modes.js';
+
+describe('migration 421 - music video media modes', () => {
+ it('migrates the project file without touching PostgreSQL', async () => {
+ const rootDir = await mkdtemp(join(tmpdir(), 'm421-'));
+ try {
+ await mkdir(join(rootDir, 'data'));
+ const file = join(rootDir, 'data', 'music-video-projects.json');
+ await writeFile(file, JSON.stringify([{ id: 'a', scenes: [] }]));
+ await expect(migration.up({ rootDir })).resolves.toEqual({ success: true });
+ expect(JSON.parse(await readFile(file, 'utf8'))[0].mediaMode).toBe('code-images-video');
+ } finally {
+ await rm(rootDir, { recursive: true, force: true });
+ }
+ });
+});
diff --git a/server/scripts/db-migrations/015-music-video-media-modes.js b/server/scripts/db-migrations/015-music-video-media-modes.js
new file mode 100644
index 0000000000..646a5baff6
--- /dev/null
+++ b/server/scripts/db-migrations/015-music-video-media-modes.js
@@ -0,0 +1,17 @@
+/**
+ * Pin legacy Music Video intent in Postgres (#10941). Moved out of file
+ * migration 421, which opened its own pool and aborted the whole file-migration
+ * run when PostgreSQL was offline. Idempotent: rows that already carry
+ * `mediaMode` are untouched.
+ */
+import { migrateMediaMode } from '../../../scripts/migrations/421-music-video-media-modes.js';
+
+export async function up(client) {
+ const table = await client.query("SELECT to_regclass('public.music_video_projects') AS name");
+ if (!table.rows[0]?.name) return;
+ const { rows } = await client.query("SELECT id, data FROM music_video_projects WHERE NOT data ? 'mediaMode'");
+ for (const { id, data } of rows) {
+ await client.query(`UPDATE music_video_projects SET data = jsonb_set(data, '{mediaMode}', to_jsonb($2::text))
+ WHERE id = $1 AND NOT data ? 'mediaMode'`, [id, migrateMediaMode(data).mediaMode]);
+ }
+}
diff --git a/server/scripts/db-migrations/015-music-video-media-modes.test.js b/server/scripts/db-migrations/015-music-video-media-modes.test.js
new file mode 100644
index 0000000000..f99a40a2a9
--- /dev/null
+++ b/server/scripts/db-migrations/015-music-video-media-modes.test.js
@@ -0,0 +1,27 @@
+import { describe, it, expect, vi } from 'vitest';
+import { up } from './015-music-video-media-modes.js';
+
+const makeClient = ({ table = 'music_video_projects', rows = [] } = {}) => {
+ const updates = [];
+ const query = vi.fn(async (sql, params) => {
+ if (sql.includes('to_regclass')) return { rows: [{ name: table }] };
+ if (sql.startsWith('SELECT')) return { rows };
+ updates.push(params);
+ return { rows: [] };
+ });
+ return { client: { query }, updates };
+};
+
+describe('db-migration 015 - music video media modes', () => {
+ it('pins mediaMode on rows lacking it', async () => {
+ const { client, updates } = makeClient({ rows: [{ id: 'p1', data: { scenes: [] } }] });
+ await up(client);
+ expect(updates).toEqual([['p1', 'code-images-video']]);
+ });
+
+ it('does nothing when the table is absent', async () => {
+ const { client, updates } = makeClient({ table: null });
+ await up(client);
+ expect(updates).toHaveLength(0);
+ });
+});