mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 15:02:04 +00:00
Merge branch 'fix/v1438-db' into release/v1.43.8
This commit is contained in:
commit
1d9758e3e8
91 files changed
+2107
-2058
No files matched your search
@@ -89,6 +89,56 @@ function violations(name: string, sql: string): string[] {
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* `CREATE INDEX CONCURRENTLY` / `DROP INDEX CONCURRENTLY` refuse to run in a
|
||||
* transaction block, and under `migrate deploy` they do so whenever the file
|
||||
* holds any other statement (SQLSTATE 25001, seen against Prisma 7 and
|
||||
* Postgres 16). Such a statement therefore stands alone in its file.
|
||||
*/
|
||||
function concurrentViolations(name: string, sql: string): string[] {
|
||||
const statements = topLevelStatements(sql);
|
||||
const concurrent = statements.filter((statement) =>
|
||||
/\bCONCURRENTLY\b/i.test(statement),
|
||||
);
|
||||
if (concurrent.length === 0 || statements.length === 1) return [];
|
||||
return [
|
||||
`${name}: a CONCURRENTLY statement must be the only statement in its file`,
|
||||
];
|
||||
}
|
||||
|
||||
describe("concurrent index statements", () => {
|
||||
it("stand alone in their migration file", () => {
|
||||
const found = migrations().flatMap(({ name, sql }) =>
|
||||
concurrentViolations(name, sql),
|
||||
);
|
||||
expect(found, found.join("\n")).toEqual([]);
|
||||
});
|
||||
|
||||
it("sees the concurrent migrations there are", () => {
|
||||
const concurrent = migrations()
|
||||
.filter(({ sql }) =>
|
||||
/\bCONCURRENTLY\b/i.test(topLevelStatements(sql).join(";")),
|
||||
)
|
||||
.map(({ name }) => name);
|
||||
expect(concurrent).toContain("0416_drop_measurements_type_prefix_index");
|
||||
});
|
||||
|
||||
it("refuses a concurrent statement beside another one", () => {
|
||||
expect(
|
||||
concurrentViolations(
|
||||
"a",
|
||||
'DROP INDEX CONCURRENTLY IF EXISTS "x";\nDROP INDEX CONCURRENTLY IF EXISTS "y";',
|
||||
),
|
||||
).toHaveLength(1);
|
||||
expect(
|
||||
concurrentViolations(
|
||||
"b",
|
||||
'-- CONCURRENTLY in a comment\nDROP INDEX CONCURRENTLY IF EXISTS "x";',
|
||||
),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("migration lock waits", () => {
|
||||
it("bounds lock waits where they take effect and marks only repeatable files", () => {
|
||||
const found = migrations().flatMap(({ name, sql }) =>
|
||||
@@ -97,11 +147,13 @@ describe("migration lock waits", () => {
|
||||
expect(found, found.join("\n")).toEqual([]);
|
||||
});
|
||||
|
||||
it("sees the one migration that bounds its wait today", () => {
|
||||
it("sees the migrations that bound their wait", () => {
|
||||
const marked = migrations()
|
||||
.filter(({ sql }) => RETRY_MARKER.test(sql))
|
||||
.map(({ name }) => name);
|
||||
expect(marked).toContain("0412_measurement_hot_updates");
|
||||
expect(marked).toContain("0414_drop_medication_compliance_rollups");
|
||||
expect(marked).toContain("0415_foreign_key_and_prefix_indexes");
|
||||
});
|
||||
|
||||
it("catches each shape it exists to refuse", () => {
|
||||
|
||||
@@ -30,10 +30,6 @@ const ALLOWED: Record<string, { hits: number; why: string }> = {
|
||||
hits: 1,
|
||||
why: "computed_at is timestamptz",
|
||||
},
|
||||
"src/lib/rollups/medication-compliance-rollups.ts": {
|
||||
hits: 1,
|
||||
why: "computed_at is timestamptz",
|
||||
},
|
||||
"src/lib/jobs/job-failures.ts": {
|
||||
hits: 2,
|
||||
why: "pg-boss tables are timestamptz",
|
||||
|
||||
@@ -85,7 +85,7 @@ import { __resetAllCachesForTests } from "@/lib/cache/server-cache";
|
||||
import { serialiseDocument } from "@/lib/documents/store";
|
||||
import { resolveIntakeActionability } from "@/lib/medications/intake-actionable";
|
||||
import { moodDateKey } from "@/lib/mood/date-key";
|
||||
import { dayKeyForScheduledFor } from "@/lib/rollups/medication-compliance-rollups";
|
||||
import { dayKeyForScheduledFor } from "@/lib/medications/dose-day-refresh";
|
||||
import {
|
||||
dateOnlyAtNoonUtc,
|
||||
dayKeyAsUtcMidnight,
|
||||
|
||||
Reference in new issue
Block a user