@secondlayer/shared 15.4.1 → 15.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/archive/range-digest.d.ts +3 -0
- package/dist/src/archive/semantic-digest-builder.d.ts +3 -0
- package/dist/src/coverage/index.d.ts +3 -0
- package/dist/src/db/index.d.ts +3 -0
- package/dist/src/db/index.js.map +2 -2
- package/dist/src/db/queries/chain-reorgs.d.ts +3 -0
- package/dist/src/db/queries/chain-reorgs.js.map +2 -2
- package/dist/src/db/queries/contracts.d.ts +19 -1
- package/dist/src/db/queries/contracts.js +35 -1
- package/dist/src/db/queries/contracts.js.map +4 -4
- package/dist/src/db/queries/instance.d.ts +3 -0
- package/dist/src/db/queries/integrity.d.ts +3 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +6 -3
- package/dist/src/db/queries/subgraph-gaps.js +11 -11
- package/dist/src/db/queries/subgraph-gaps.js.map +3 -3
- package/dist/src/db/queries/subgraph-operations.d.ts +3 -0
- package/dist/src/db/queries/subgraphs.d.ts +11 -8
- package/dist/src/db/queries/subgraphs.js +25 -19
- package/dist/src/db/queries/subgraphs.js.map +3 -3
- package/dist/src/db/queries/sync-scope.d.ts +3 -0
- package/dist/src/db/queries/webhook-replays.d.ts +3 -0
- package/dist/src/db/queries/webhooks.d.ts +3 -0
- package/dist/src/db/schema.d.ts +3 -0
- package/dist/src/db/schema.js.map +2 -2
- package/dist/src/index-http.d.ts +14 -0
- package/dist/src/index-http.js +4 -1
- package/dist/src/index-http.js.map +3 -3
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js.map +2 -2
- package/dist/src/insights/index.d.ts +3 -0
- package/dist/src/insights/index.js +3 -3
- package/dist/src/insights/index.js.map +3 -3
- package/dist/src/leader.js.map +2 -2
- package/dist/src/node/local-client.d.ts +3 -0
- package/dist/src/queue/listener.js.map +2 -2
- package/migrations/0203_subgraph_side_tables_subgraph_id.ts +109 -0
- package/package.json +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onControlPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Print-validate violations, handler error groups and processing stats were
|
|
6
|
+
* keyed by subgraph name alone. A subgraph deleted and registered again under
|
|
7
|
+
* the same name got a new id but inherited every row of the old one. Each row
|
|
8
|
+
* now belongs to a `subgraphs.id` and goes with it on delete; `subgraph_name`
|
|
9
|
+
* stays for display.
|
|
10
|
+
*
|
|
11
|
+
* Existing rows take the id of the one subgraph carrying their name. A name no
|
|
12
|
+
* subgraph carries (a deleted one) or more than one does (several accounts on
|
|
13
|
+
* one database) cannot be attributed, so those rows are deleted: they are
|
|
14
|
+
* bounded diagnostics, not records. Safe on empty tables and to run again.
|
|
15
|
+
* Skipped where the tables are absent (not every database carries them).
|
|
16
|
+
*
|
|
17
|
+
* The backfill is one statement per table: fine for the bounded tables these
|
|
18
|
+
* are, to be batched if one ever holds millions of rows.
|
|
19
|
+
*/
|
|
20
|
+
const TABLES = [
|
|
21
|
+
"subgraph_violations",
|
|
22
|
+
"subgraph_error_groups",
|
|
23
|
+
"subgraph_processing_stats",
|
|
24
|
+
] as const;
|
|
25
|
+
|
|
26
|
+
async function tableExists(db: Kysely<unknown>, table: string) {
|
|
27
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
28
|
+
SELECT to_regclass(${table}) IS NOT NULL AS exists
|
|
29
|
+
`.execute(db);
|
|
30
|
+
return rows[0]?.exists === true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
34
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
35
|
+
await onControlPlane(async () => {
|
|
36
|
+
if (!(await tableExists(db, "subgraphs"))) return;
|
|
37
|
+
for (const table of TABLES) {
|
|
38
|
+
if (!(await tableExists(db, table))) continue;
|
|
39
|
+
const t = sql.table(table);
|
|
40
|
+
await sql`
|
|
41
|
+
ALTER TABLE ${t}
|
|
42
|
+
ADD COLUMN IF NOT EXISTS subgraph_id uuid
|
|
43
|
+
REFERENCES subgraphs (id) ON DELETE CASCADE
|
|
44
|
+
`.execute(db);
|
|
45
|
+
await sql`
|
|
46
|
+
UPDATE ${t} AS r
|
|
47
|
+
SET subgraph_id = s.id
|
|
48
|
+
FROM (
|
|
49
|
+
SELECT name, (array_agg(id))[1] AS id
|
|
50
|
+
FROM subgraphs
|
|
51
|
+
GROUP BY name
|
|
52
|
+
HAVING count(*) = 1
|
|
53
|
+
) AS s
|
|
54
|
+
WHERE r.subgraph_id IS NULL AND s.name = r.subgraph_name
|
|
55
|
+
`.execute(db);
|
|
56
|
+
await sql`DELETE FROM ${t} WHERE subgraph_id IS NULL`.execute(db);
|
|
57
|
+
await sql`ALTER TABLE ${t} ALTER COLUMN subgraph_id SET NOT NULL`.execute(
|
|
58
|
+
db,
|
|
59
|
+
);
|
|
60
|
+
// The error groups' unique key below leads with the id already.
|
|
61
|
+
if (table !== "subgraph_error_groups") {
|
|
62
|
+
await sql`
|
|
63
|
+
CREATE INDEX IF NOT EXISTS ${sql.id(`${table}_subgraph_id_idx`)}
|
|
64
|
+
ON ${t} (subgraph_id)
|
|
65
|
+
`.execute(db);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (await tableExists(db, "subgraph_error_groups")) {
|
|
69
|
+
await sql`
|
|
70
|
+
ALTER TABLE subgraph_error_groups
|
|
71
|
+
DROP CONSTRAINT IF EXISTS subgraph_error_groups_subgraph_name_fingerprint_key
|
|
72
|
+
`.execute(db);
|
|
73
|
+
await sql`
|
|
74
|
+
CREATE UNIQUE INDEX IF NOT EXISTS subgraph_error_groups_subgraph_id_fingerprint_key
|
|
75
|
+
ON subgraph_error_groups (subgraph_id, fingerprint)
|
|
76
|
+
`.execute(db);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
82
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
83
|
+
await onControlPlane(async () => {
|
|
84
|
+
if (await tableExists(db, "subgraph_error_groups")) {
|
|
85
|
+
await sql`DROP INDEX IF EXISTS subgraph_error_groups_subgraph_id_fingerprint_key`.execute(
|
|
86
|
+
db,
|
|
87
|
+
);
|
|
88
|
+
await sql`
|
|
89
|
+
DO $$ BEGIN
|
|
90
|
+
IF NOT EXISTS (
|
|
91
|
+
SELECT 1 FROM pg_constraint
|
|
92
|
+
WHERE conrelid = to_regclass('subgraph_error_groups')
|
|
93
|
+
AND conname = 'subgraph_error_groups_subgraph_name_fingerprint_key'
|
|
94
|
+
) THEN
|
|
95
|
+
ALTER TABLE subgraph_error_groups
|
|
96
|
+
ADD CONSTRAINT subgraph_error_groups_subgraph_name_fingerprint_key
|
|
97
|
+
UNIQUE (subgraph_name, fingerprint);
|
|
98
|
+
END IF;
|
|
99
|
+
END $$
|
|
100
|
+
`.execute(db);
|
|
101
|
+
}
|
|
102
|
+
for (const table of TABLES) {
|
|
103
|
+
if (!(await tableExists(db, table))) continue;
|
|
104
|
+
await sql`ALTER TABLE ${sql.table(table)} DROP COLUMN IF EXISTS subgraph_id`.execute(
|
|
105
|
+
db,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|