@secondlayer/shared 15.3.2 → 15.3.4
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 +5 -0
- package/dist/src/archive/semantic-digest-builder.d.ts +5 -0
- package/dist/src/coverage/index.d.ts +13 -1
- package/dist/src/coverage/index.js +23 -2
- package/dist/src/coverage/index.js.map +3 -3
- package/dist/src/db/index.d.ts +5 -0
- package/dist/src/db/index.js.map +2 -2
- package/dist/src/db/queries/chain-reorgs.d.ts +5 -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 +23 -1
- package/dist/src/db/queries/contracts.js.map +4 -4
- package/dist/src/db/queries/instance.d.ts +5 -0
- package/dist/src/db/queries/integrity.d.ts +82 -1
- package/dist/src/db/queries/integrity.js +210 -2
- package/dist/src/db/queries/integrity.js.map +6 -5
- package/dist/src/db/queries/subgraph-gaps.d.ts +16 -6
- package/dist/src/db/queries/subgraph-gaps.js +81 -14
- package/dist/src/db/queries/subgraph-gaps.js.map +3 -3
- package/dist/src/db/queries/subgraph-operations.d.ts +8 -1
- package/dist/src/db/queries/subgraph-operations.js +9 -5
- package/dist/src/db/queries/subgraph-operations.js.map +3 -3
- package/dist/src/db/queries/subgraphs.d.ts +9 -4
- package/dist/src/db/queries/subgraphs.js +13 -6
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/sync-scope.d.ts +5 -0
- package/dist/src/db/queries/webhook-replays.d.ts +5 -0
- package/dist/src/db/queries/webhooks.d.ts +5 -0
- package/dist/src/db/schema.d.ts +5 -0
- package/dist/src/db/schema.js.map +2 -2
- package/dist/src/index.d.ts +15 -1
- package/dist/src/index.js +4 -2
- package/dist/src/index.js.map +5 -5
- package/dist/src/insights/index.d.ts +5 -0
- package/dist/src/node/local-client.d.ts +5 -0
- package/dist/src/queue/listener.js.map +2 -2
- package/dist/src/schemas/index.js +2 -2
- package/dist/src/schemas/index.js.map +3 -3
- package/dist/src/schemas/subgraphs.js +2 -2
- package/dist/src/schemas/subgraphs.js.map +3 -3
- package/dist/src/types.d.ts +3 -0
- package/migrations/0196_usage_ledger_checks.ts +85 -0
- package/migrations/0197_subgraph_last_block_hash.ts +67 -0
- package/migrations/0198_blocks_event_count.ts +24 -0
- package/migrations/0199_transactions_height_tx_index_uniq.ts +77 -0
- package/migrations/0200_subgraphs_schema_name_unique.ts +39 -0
- package/migrations/0201_subgraph_gaps_range_check.ts +47 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onControlPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A gap is a range of blocks, so it starts at or before it ends. Rows written
|
|
6
|
+
* backwards are swapped rather than dropped: the blocks they name are still
|
|
7
|
+
* missing. The CHECK is added `NOT VALID` then validated, and skipped when the
|
|
8
|
+
* table is absent (not every database carries it).
|
|
9
|
+
*/
|
|
10
|
+
async function tableExists(db: Kysely<unknown>, table: string) {
|
|
11
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
12
|
+
SELECT to_regclass(${`public.${table}`}) IS NOT NULL AS exists
|
|
13
|
+
`.execute(db);
|
|
14
|
+
return rows[0]?.exists === true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
18
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
19
|
+
await onControlPlane(async () => {
|
|
20
|
+
if (!(await tableExists(db, "subgraph_gaps"))) return;
|
|
21
|
+
await sql`
|
|
22
|
+
UPDATE subgraph_gaps
|
|
23
|
+
SET gap_start = gap_end, gap_end = gap_start
|
|
24
|
+
WHERE gap_start > gap_end
|
|
25
|
+
`.execute(db);
|
|
26
|
+
await sql`ALTER TABLE subgraph_gaps DROP CONSTRAINT IF EXISTS subgraph_gaps_range_check`.execute(
|
|
27
|
+
db,
|
|
28
|
+
);
|
|
29
|
+
await sql`
|
|
30
|
+
ALTER TABLE subgraph_gaps
|
|
31
|
+
ADD CONSTRAINT subgraph_gaps_range_check CHECK (gap_start <= gap_end) NOT VALID
|
|
32
|
+
`.execute(db);
|
|
33
|
+
await sql`ALTER TABLE subgraph_gaps VALIDATE CONSTRAINT subgraph_gaps_range_check`.execute(
|
|
34
|
+
db,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
40
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
41
|
+
await onControlPlane(async () => {
|
|
42
|
+
if (!(await tableExists(db, "subgraph_gaps"))) return;
|
|
43
|
+
await sql`ALTER TABLE subgraph_gaps DROP CONSTRAINT IF EXISTS subgraph_gaps_range_check`.execute(
|
|
44
|
+
db,
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
}
|