@secondlayer/shared 10.0.0 → 10.0.1
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 +15 -0
- package/dist/src/archive/semantic-digest-builder.d.ts +15 -0
- package/dist/src/coverage/index.d.ts +15 -0
- package/dist/src/crypto/secrets.js.map +2 -2
- package/dist/src/db/index.d.ts +20 -1
- package/dist/src/db/index.js +2 -1
- package/dist/src/db/index.js.map +4 -4
- package/dist/src/db/queries/chain-reorgs.d.ts +15 -0
- package/dist/src/db/queries/chain-reorgs.js +2 -1
- package/dist/src/db/queries/chain-reorgs.js.map +4 -4
- package/dist/src/db/queries/contracts.d.ts +15 -0
- package/dist/src/db/queries/instance.d.ts +15 -0
- package/dist/src/db/queries/integrity.d.ts +15 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +15 -0
- package/dist/src/db/queries/subgraph-operations.d.ts +15 -0
- package/dist/src/db/queries/subgraphs.d.ts +15 -0
- package/dist/src/db/queries/subgraphs.js.map +2 -2
- package/dist/src/db/queries/subscriptions.d.ts +15 -0
- package/dist/src/db/queries/subscriptions.js.map +2 -2
- package/dist/src/db/queries/sync-scope.d.ts +15 -0
- package/dist/src/db/schema.d.ts +19 -1
- package/dist/src/index.d.ts +20 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +4 -4
- package/dist/src/mode.d.ts +4 -3
- package/dist/src/mode.js.map +2 -2
- package/dist/src/node/local-client.d.ts +15 -0
- package/migrations/0121_archive_fetches.ts +49 -0
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
import { onControlPlane } from "../src/db/migration-role.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `archive_fetches` — the charge log for the metered archive fetch gate
|
|
6
|
+
* (design-f089). One row per priced attempt to fetch a partition object,
|
|
7
|
+
* successful or free (24h re-issue / monthly repair allowance). Never
|
|
8
|
+
* updated after insert — it is an append-only log, read for two things:
|
|
9
|
+
*
|
|
10
|
+
* - the 24h re-issue window: has this account already paid for this exact
|
|
11
|
+
* path recently, so a resumed/retried fetch re-presigns for free.
|
|
12
|
+
* - the monthly repair allowance: how many partitions this account has
|
|
13
|
+
* pulled via the free allowance this calendar month.
|
|
14
|
+
*
|
|
15
|
+
* `usd_micros` is 0 for allowance/re-issue rows, so summing it per account
|
|
16
|
+
* is real revenue, not fetch volume. Lives on the control plane next to
|
|
17
|
+
* `account_credits`, the balance it debits from.
|
|
18
|
+
*/
|
|
19
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
20
|
+
await onControlPlane(async () => {
|
|
21
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
22
|
+
|
|
23
|
+
await sql`
|
|
24
|
+
CREATE TABLE archive_fetches (
|
|
25
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
26
|
+
account_id uuid NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
|
|
27
|
+
path text NOT NULL,
|
|
28
|
+
dataset text NOT NULL,
|
|
29
|
+
usd_micros bigint NOT NULL,
|
|
30
|
+
via_allowance boolean NOT NULL DEFAULT false,
|
|
31
|
+
charged_at timestamptz NOT NULL DEFAULT now(),
|
|
32
|
+
UNIQUE (account_id, path, charged_at)
|
|
33
|
+
)
|
|
34
|
+
`.execute(db);
|
|
35
|
+
|
|
36
|
+
// Serves both the 24h re-issue lookup (account_id, path, charged_at)
|
|
37
|
+
// and the monthly allowance count (account_id, via_allowance, charged_at).
|
|
38
|
+
await sql`
|
|
39
|
+
CREATE INDEX archive_fetches_account_charged_at_idx
|
|
40
|
+
ON archive_fetches (account_id, charged_at)
|
|
41
|
+
`.execute(db);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
46
|
+
await onControlPlane(async () => {
|
|
47
|
+
await sql`DROP TABLE IF EXISTS archive_fetches`.execute(db);
|
|
48
|
+
});
|
|
49
|
+
}
|