diff --git a/cypress/e2e/settings/prowlarr-responsive.cy.ts b/cypress/e2e/settings/prowlarr-responsive.cy.ts index df0b677fd2..b3c77e33fb 100644 --- a/cypress/e2e/settings/prowlarr-responsive.cy.ts +++ b/cypress/e2e/settings/prowlarr-responsive.cy.ts @@ -50,6 +50,7 @@ describe('Prowlarr settings on a short mobile screen', () => { }, }); } else if (pathname === '/api/v1/settings/prowlarr') { + request.alias = 'prowlarrSettings'; request.reply({ hostname: 'prowlarr.test', port: 9696, @@ -113,6 +114,8 @@ describe('Prowlarr settings on a short mobile screen', () => { it('keeps save reachable after scrolling the long indexer report', () => { cy.visit('/settings/services'); + cy.wait('@prowlarrSettings').its('response.statusCode').should('eq', 200); + cy.get('#prowlarr').should('be.visible'); cy.contains('#prowlarr h3', 'Prowlarr indexers').scrollIntoView(); cy.get('#prowlarr') .contains('button', 'Test connection and inspect coverage') diff --git a/docs/maintainers/postgres-startup-issue-164.md b/docs/maintainers/postgres-startup-issue-164.md new file mode 100644 index 0000000000..0ffc1019fb --- /dev/null +++ b/docs/maintainers/postgres-startup-issue-164.md @@ -0,0 +1,61 @@ +# PostgreSQL Startup Recovery — Issue #164 + +## Recovery identity + +- Base: `a9dd1b5a64cd9ccabe59da198b0524a7886bb708` (`origin/main`). +- Issue fix commit: `0980bc5d1db052f566cd97b46b98a89149a34952`. +- Supporting packaging-fixture test commit: `e87fef1e4374eadf0b3e15667eb57f44ccc5a6ff`. +- Upstream issue: https://github.com/snapetech/seerrng/issues/164. +- Pre-audit recovery archive: `/tmp/seerrng-issue164-preaudit-20261006.tar`. + +## Root cause and changes + +Three `@UpdateDateColumn` decorators passed SQLite's `datetime` type directly +to TypeORM. PostgreSQL rejects that type while building entity metadata, before +startup reaches the migration runner. The affected columns are +`ReaderDeliveryGrouping.updatedAt`, `GameLibraryAccount.updatedAt`, and +`GameLibraryEntry.updatedAt`. + +The fix resolves those types for the active database and adds a reversible +PostgreSQL migration to normalize nine private-library date columns, preserving +their wall-clock values under the session timezone. The issue commit includes a +metadata regression test, migration test, and release-note fragment. + +## Verification + +- Before rebasing, full Linux `pnpm test:ci`: 487 files passed, 1 skipped; 3,375 tests passed, + 4 skipped; 0 failures. The four skips were PostgreSQL-gated tests. +- Before rebasing, focused PostgreSQL 18 Node run: 5 passed, 0 failed, 0 skipped. This included + all four database-gated migration tests and the issue migration query test. +- Focused Linux Vitest metadata regression: 1 passed. +- Disposable PostgreSQL 18 migration round-trip (before rebase, same issue + commit contents): all nine columns converted up and down, preserving values + under an `America/Edmonton` session timezone. +- Before rebasing, Linux `pnpm build`: passed. Translation extraction, 569-file current-batch + contract, shared-style checks, 68 button/geometry tests, server compilation, + Next.js compilation, and all 113 static pages completed. +- Release-note preview rendered the PostgreSQL startup fix note. +- Before rebasing, `pnpm validate:development` on Linux ARM64 passed formatting, lint, types, + Vitest (100 files; 453 tests), native TypeScript (2,912 passed, 4 skipped), + and native JavaScript (485 tests). It failed one tooling test because its + archive fixture assumed x64. The corrected fixture now passes 7/7 locally; + the full gate was not rerun after that test-only correction. +- A full `pnpm test:node` attempt was stopped after 9m15s while compiling an + unrelated Jellyfin suite. No failure was reported; that full lane is not + counted as passed. Focused relevant Node tests passed separately. +- The reviewed combined validation engine was not run. Historical + `pnpm validate:development` attempts on the prior base had platform/tooling + failures. The complete gate has not been rerun on the rebased candidate. +- Initial PR Cypress CI ran 43 specs (185 tests): 152 passed, 1 failed, and + 32 were pending. The failure was the Prowlarr settings heading being absent + when the test queried it. The component renders after its settings response; + the Cypress test now aliases and waits for that mocked request, then checks + the section is visible before continuing its existing interaction checks. + The updated Cypress test has not been rerun; the next push will trigger CI. +- No live database, account, or provider was used. + +## Release + +Before publication, the latest published tag was `v3.52.1`. The repository's +`Create tag` workflow determines the next version from unreleased conventional +commits on `main`. diff --git a/release-notes/2026-10-06-postgres-reader-and-game-library-startup.md b/release-notes/2026-10-06-postgres-reader-and-game-library-startup.md new file mode 100644 index 0000000000..755f88eac7 --- /dev/null +++ b/release-notes/2026-10-06-postgres-reader-and-game-library-startup.md @@ -0,0 +1,9 @@ +--- +category: fixed +audience: users, operators +area: database +action: none +breaking: false +--- + +PostgreSQL startup now accepts the reader delivery and private game library date columns, so these features no longer prevent the application from starting. diff --git a/scripts/build-release-assets.test.mjs b/scripts/build-release-assets.test.mjs index c8c746d66a..88d0f813d6 100644 --- a/scripts/build-release-assets.test.mjs +++ b/scripts/build-release-assets.test.mjs @@ -82,6 +82,13 @@ const writeNodeArchitectureShim = (fixture) => { mode: 0o755 } ); +const writeUnameShim = (fixture, system, machine) => + fs.writeFile( + path.join(fixture.executableDirectory, 'uname'), + `#!/bin/sh\nif [ "$1" = "-s" ]; then printf '%s\\n' '${system}'; else printf '%s\\n' '${machine}'; fi\n`, + { mode: 0o755 } + ); + const run = (fixture, arguments_, environment = {}) => new Promise((resolve) => { const child = spawn(fixture.script, arguments_, { @@ -104,6 +111,35 @@ const run = (fixture, arguments_, environment = {}) => child.on('close', (code) => resolve({ code, output })); }); +const runForPlatformAndNodeArchitecture = async ( + fixture, + arguments_, + system, + machine, + architecture, + environment = {} +) => { + await Promise.all([ + writeNodeArchitectureShim(fixture), + writeUnameShim(fixture, system, machine), + ]); + return run(fixture, arguments_, { + ...environment, + TEST_NODE_ARCH: architecture, + TEST_NODE_BINARY: process.execPath, + }); +}; + +const runAsLinuxX64 = (fixture, arguments_, environment = {}) => + runForPlatformAndNodeArchitecture( + fixture, + arguments_, + 'Linux', + 'x86_64', + 'x64', + environment + ); + const extractArchive = (archive, destination) => new Promise((resolve, reject) => { const child = spawn('tar', ['-xzf', archive, '-C', destination]); @@ -133,7 +169,7 @@ describe('release asset construction', () => { await fs.writeFile(sentinel, 'unchanged'); await fs.symlink(sentinel, archive); - const result = await run(fixture, ['v1.2.3', distribution]); + const result = await runAsLinuxX64(fixture, ['v1.2.3', distribution]); assert.equal(result.code, 0, result.output); assert.match( @@ -222,7 +258,7 @@ describe('release asset construction', () => { path.join(fixture.root, 'public', 'escape') ); - const result = await run(fixture, ['v1.2.3', distribution]); + const result = await runAsLinuxX64(fixture, ['v1.2.3', distribution]); assert.notEqual(result.code, 0); assert.match(result.output, /Refusing absolute archive symlink/); @@ -238,7 +274,7 @@ describe('release asset construction', () => { const asset = 'seerrng-v1.2.3-linux-x64'; const archive = path.join(distribution, `${asset}.tar.gz`); await fs.mkdir(distribution); - const result = await run(fixture, ['v1.2.3', distribution]); + const result = await runAsLinuxX64(fixture, ['v1.2.3', distribution]); assert.equal(result.code, 0, result.output); const extracted = path.join(fixture.root, 'extracted'); @@ -255,20 +291,20 @@ describe('release asset construction', () => { const archive = path.join(distribution, 'seerrng-v1.2.3-windows-x64.zip'); const archiverLog = path.join(fixture.root, 'archiver.log'); await fs.mkdir(distribution); - await fs.writeFile( - path.join(fixture.executableDirectory, 'uname'), - '#!/bin/sh\nif [ "$1" = "-s" ]; then echo MINGW64_NT; else echo x86_64; fi\n', - { mode: 0o755 } - ); await fs.writeFile( path.join(fixture.executableDirectory, '7z'), '#!/bin/sh\nprintf \'%s\\n\' "$*" >"$ARCHIVER_LOG"\nprevious_argument=\'\'\nfor argument in "$@"; do\n archive_path="$previous_argument"\n stage_path="$argument"\n previous_argument="$argument"\ndone\nzip -qr "$archive_path" "$stage_path"\n', { mode: 0o755 } ); - const result = await run(fixture, ['v1.2.3', distribution], { - ARCHIVER_LOG: archiverLog, - }); + const result = await runForPlatformAndNodeArchitecture( + fixture, + ['v1.2.3', distribution], + 'MINGW64_NT', + 'x86_64', + 'x64', + { ARCHIVER_LOG: archiverLog } + ); assert.equal(result.code, 0, result.output); assert.match( @@ -306,12 +342,13 @@ describe('release asset construction', () => { it('rejects Linux ARMv7 without a supported Node.js 24 runtime', async () => { const fixture = await createFixture(); const distribution = path.join(fixture.root, 'dist-release'); - await writeNodeArchitectureShim(fixture); - - const result = await run(fixture, ['v1.2.3', distribution], { - TEST_NODE_ARCH: 'armv7l', - TEST_NODE_BINARY: process.execPath, - }); + const result = await runForPlatformAndNodeArchitecture( + fixture, + ['v1.2.3', distribution], + 'Linux', + 'armv7l', + 'armv7l' + ); assert.notEqual(result.code, 0); assert.match( @@ -327,12 +364,13 @@ describe('release asset construction', () => { it('rejects an architecture outside the published archive matrix', async () => { const fixture = await createFixture(); const distribution = path.join(fixture.root, 'dist-release'); - await writeNodeArchitectureShim(fixture); - - const result = await run(fixture, ['v1.2.3', distribution], { - TEST_NODE_ARCH: 'riscv64', - TEST_NODE_BINARY: process.execPath, - }); + const result = await runForPlatformAndNodeArchitecture( + fixture, + ['v1.2.3', distribution], + 'Linux', + 'riscv64', + 'riscv64' + ); assert.notEqual(result.code, 0); assert.match( diff --git a/server/entity/GameLibraryAccount.ts b/server/entity/GameLibraryAccount.ts index ccc6c4b761..ab517731bf 100644 --- a/server/entity/GameLibraryAccount.ts +++ b/server/entity/GameLibraryAccount.ts @@ -1,4 +1,4 @@ -import { DbAwareColumn } from '@server/utils/DbColumnHelper'; +import { DbAwareColumn, resolveDbType } from '@server/utils/DbColumnHelper'; import { Column, Entity, @@ -43,6 +43,8 @@ export default class GameLibraryAccount { @DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) public linkedAt: Date; - @UpdateDateColumn({ type: 'datetime' }) + @UpdateDateColumn({ + type: resolveDbType('datetime'), + }) public updatedAt: Date; } diff --git a/server/entity/GameLibraryEntry.ts b/server/entity/GameLibraryEntry.ts index 043bd373d7..05ea94401b 100644 --- a/server/entity/GameLibraryEntry.ts +++ b/server/entity/GameLibraryEntry.ts @@ -1,4 +1,4 @@ -import { DbAwareColumn } from '@server/utils/DbColumnHelper'; +import { DbAwareColumn, resolveDbType } from '@server/utils/DbColumnHelper'; import { Column, Entity, @@ -98,6 +98,8 @@ export default class GameLibraryEntry { @DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) public createdAt: Date; - @UpdateDateColumn({ type: 'datetime' }) + @UpdateDateColumn({ + type: resolveDbType('datetime'), + }) public updatedAt: Date; } diff --git a/server/entity/ReaderDeliveryGrouping.ts b/server/entity/ReaderDeliveryGrouping.ts index 5e8823b300..dacc6f637a 100644 --- a/server/entity/ReaderDeliveryGrouping.ts +++ b/server/entity/ReaderDeliveryGrouping.ts @@ -1,4 +1,4 @@ -import { DbAwareColumn } from '@server/utils/DbColumnHelper'; +import { DbAwareColumn, resolveDbType } from '@server/utils/DbColumnHelper'; import { Column, Entity, @@ -68,6 +68,8 @@ export default class ReaderDeliveryGrouping { @DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) public createdAt: Date; - @UpdateDateColumn({ type: 'datetime' }) + @UpdateDateColumn({ + type: resolveDbType('datetime'), + }) public updatedAt: Date; } diff --git a/server/entity/postgresDateMetadata.vitest.test.ts b/server/entity/postgresDateMetadata.vitest.test.ts new file mode 100644 index 0000000000..ace516e374 --- /dev/null +++ b/server/entity/postgresDateMetadata.vitest.test.ts @@ -0,0 +1,47 @@ +import { afterEach, describe, expect, it, vi } from 'vitest'; + +describe('PostgreSQL entity date metadata', () => { + afterEach(() => { + vi.doUnmock('@server/utils/dbType'); + vi.resetModules(); + }); + + it('builds metadata for date columns on entities added in SeerrNG 3.52', async () => { + vi.resetModules(); + vi.doMock('@server/utils/dbType', () => ({ isPgsql: true })); + + const { DataSource, getMetadataArgsStorage } = await import('typeorm'); + const [ + { default: ReaderDeliveryGrouping }, + { default: GameLibraryAccount }, + { default: GameLibraryEntry }, + ] = await Promise.all([ + import('./ReaderDeliveryGrouping'), + import('./GameLibraryAccount'), + import('./GameLibraryEntry'), + ]); + + const source = new DataSource({ + type: 'postgres', + database: 'metadata-test', + entities: [ReaderDeliveryGrouping], + }); + await ( + source as unknown as { buildMetadatas: () => Promise } + ).buildMetadatas(); + + const metadata = getMetadataArgsStorage(); + for (const target of [ + ReaderDeliveryGrouping, + GameLibraryAccount, + GameLibraryEntry, + ]) { + const updatedAt = metadata.columns.find( + (column) => + column.target === target && column.propertyName === 'updatedAt' + ); + + expect(updatedAt?.options.type).toBe('timestamp with time zone'); + } + }); +}); diff --git a/server/migration/postgres/1791040000000-NormalizePrivateLibraryTimestamps.test.ts b/server/migration/postgres/1791040000000-NormalizePrivateLibraryTimestamps.test.ts new file mode 100644 index 0000000000..944edbaa62 --- /dev/null +++ b/server/migration/postgres/1791040000000-NormalizePrivateLibraryTimestamps.test.ts @@ -0,0 +1,47 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import type { QueryRunner } from 'typeorm'; +import { NormalizePrivateLibraryTimestamps1791040000000 } from './1791040000000-NormalizePrivateLibraryTimestamps'; + +const timestampColumns = [ + ['game_library_entry', 'lastSyncedAt'], + ['game_library_entry', 'createdAt'], + ['game_library_entry', 'updatedAt'], + ['game_library_account', 'lastSyncedAt'], + ['game_library_account', 'linkedAt'], + ['game_library_account', 'updatedAt'], + ['reader_delivery_grouping', 'lastSyncedAt'], + ['reader_delivery_grouping', 'createdAt'], + ['reader_delivery_grouping', 'updatedAt'], +] as const; + +test('normalizes private-library PostgreSQL timestamp types using the configured timezone', async () => { + const statements: string[] = []; + const queryRunner = { + query: async (statement: string) => { + statements.push(statement.replace(/\s+/g, ' ').trim()); + }, + } as unknown as QueryRunner; + const migration = new NormalizePrivateLibraryTimestamps1791040000000(); + + await migration.up(queryRunner); + assert.equal(statements.length, timestampColumns.length); + for (const [table, column] of timestampColumns) { + assert.ok( + statements.includes( + `ALTER TABLE "${table}" ALTER COLUMN "${column}" TYPE TIMESTAMP WITH TIME ZONE USING "${column}" AT TIME ZONE current_setting('TimeZone')` + ) + ); + } + + statements.length = 0; + await migration.down(queryRunner); + assert.equal(statements.length, timestampColumns.length); + for (const [table, column] of [...timestampColumns].reverse()) { + assert.ok( + statements.includes( + `ALTER TABLE "${table}" ALTER COLUMN "${column}" TYPE TIMESTAMP WITHOUT TIME ZONE USING "${column}" AT TIME ZONE current_setting('TimeZone')` + ) + ); + } +}); diff --git a/server/migration/postgres/1791040000000-NormalizePrivateLibraryTimestamps.ts b/server/migration/postgres/1791040000000-NormalizePrivateLibraryTimestamps.ts new file mode 100644 index 0000000000..e5c84c7452 --- /dev/null +++ b/server/migration/postgres/1791040000000-NormalizePrivateLibraryTimestamps.ts @@ -0,0 +1,37 @@ +import type { MigrationInterface, QueryRunner } from 'typeorm'; + +const timestampColumns = [ + ['game_library_entry', 'lastSyncedAt'], + ['game_library_entry', 'createdAt'], + ['game_library_entry', 'updatedAt'], + ['game_library_account', 'lastSyncedAt'], + ['game_library_account', 'linkedAt'], + ['game_library_account', 'updatedAt'], + ['reader_delivery_grouping', 'lastSyncedAt'], + ['reader_delivery_grouping', 'createdAt'], + ['reader_delivery_grouping', 'updatedAt'], +] as const; + +export class NormalizePrivateLibraryTimestamps1791040000000 implements MigrationInterface { + name = 'NormalizePrivateLibraryTimestamps1791040000000'; + + public async up(queryRunner: QueryRunner): Promise { + for (const [table, column] of timestampColumns) { + await queryRunner.query(` + ALTER TABLE "${table}" + ALTER COLUMN "${column}" TYPE TIMESTAMP WITH TIME ZONE + USING "${column}" AT TIME ZONE current_setting('TimeZone') + `); + } + } + + public async down(queryRunner: QueryRunner): Promise { + for (const [table, column] of [...timestampColumns].reverse()) { + await queryRunner.query(` + ALTER TABLE "${table}" + ALTER COLUMN "${column}" TYPE TIMESTAMP WITHOUT TIME ZONE + USING "${column}" AT TIME ZONE current_setting('TimeZone') + `); + } + } +}