@secondlayer/shared 0.7.1 → 0.8.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/crypto/hmac.js +2 -2
- package/dist/src/crypto/hmac.js.map +3 -3
- package/dist/src/db/index.d.ts +15 -1
- package/dist/src/db/index.js +5 -3
- package/dist/src/db/index.js.map +4 -4
- package/dist/src/db/jsonb.js.map +2 -2
- package/dist/src/db/queries/accounts.d.ts +12 -0
- package/dist/src/db/queries/accounts.js.map +2 -2
- package/dist/src/db/queries/integrity.d.ts +12 -0
- package/dist/src/db/queries/integrity.js.map +2 -2
- package/dist/src/db/queries/metrics.d.ts +12 -0
- package/dist/src/db/queries/metrics.js.map +2 -2
- package/dist/src/db/queries/subgraph-gaps.d.ts +305 -0
- package/dist/src/db/queries/subgraph-gaps.js +103 -0
- package/dist/src/db/queries/subgraph-gaps.js.map +10 -0
- package/dist/src/db/queries/subgraphs.d.ts +13 -0
- package/dist/src/db/queries/subgraphs.js +4 -2
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/usage.d.ts +12 -0
- package/dist/src/db/queries/usage.js +13 -3
- package/dist/src/db/queries/usage.js.map +4 -4
- package/dist/src/db/schema.d.ts +15 -1
- package/dist/src/env.js.map +2 -2
- package/dist/src/errors.js.map +2 -2
- package/dist/src/index.d.ts +59 -1
- package/dist/src/index.js +12 -8
- package/dist/src/index.js.map +12 -12
- package/dist/src/lib/plans.js.map +2 -2
- package/dist/src/logger.js.map +3 -3
- package/dist/src/node/archive-client.js +22 -6
- package/dist/src/node/archive-client.js.map +5 -5
- package/dist/src/node/client.js.map +2 -2
- package/dist/src/node/hiro-client.js +47 -11
- package/dist/src/node/hiro-client.js.map +5 -5
- package/dist/src/node/hiro-pg-client.js +131 -26
- package/dist/src/node/hiro-pg-client.js.map +3 -3
- package/dist/src/node/local-client.d.ts +12 -0
- package/dist/src/node/local-client.js.map +2 -2
- package/dist/src/queue/index.js +7 -5
- package/dist/src/queue/index.js.map +5 -5
- package/dist/src/queue/listener.js.map +2 -2
- package/dist/src/queue/recovery.js +5 -3
- package/dist/src/queue/recovery.js.map +5 -5
- package/dist/src/schemas/filters.js +2 -2
- package/dist/src/schemas/filters.js.map +3 -3
- package/dist/src/schemas/index.d.ts +45 -1
- package/dist/src/schemas/index.js +5 -3
- package/dist/src/schemas/index.js.map +5 -5
- package/dist/src/schemas/subgraphs.d.ts +45 -1
- package/dist/src/schemas/subgraphs.js.map +2 -2
- package/migrations/0001_initial.ts +295 -159
- package/migrations/0002_api_keys.ts +44 -28
- package/migrations/0003_tenant_isolation.ts +116 -107
- package/migrations/0004_accounts_and_usage.ts +81 -75
- package/migrations/0005_sessions.ts +33 -33
- package/migrations/0006_tx_index.ts +6 -2
- package/migrations/0007_contracts.ts +38 -24
- package/migrations/0008_drop_contracts.ts +33 -19
- package/migrations/0009_waitlist.ts +12 -12
- package/migrations/0010_waitlist_status.ts +5 -5
- package/migrations/0011_account_insights.ts +52 -52
- package/migrations/0012_view_health_snapshots.ts +21 -21
- package/migrations/0013_view_processing_stats.ts +32 -32
- package/migrations/0014_view_table_snapshots.ts +24 -24
- package/migrations/0015_rename_views_to_subgraphs.ts +137 -75
- package/migrations/0016_rename_webhook_to_endpoint.ts +12 -4
- package/migrations/0017_security_hardening.ts +23 -11
- package/migrations/0018_subgraph_gaps.ts +39 -0
- package/package.json +147 -143
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
2
|
|
|
3
3
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
await db.schema
|
|
5
|
+
.createTable("waitlist")
|
|
6
|
+
.addColumn("id", "uuid", (col) =>
|
|
7
|
+
col.primaryKey().defaultTo(db.fn("gen_random_uuid")),
|
|
8
|
+
)
|
|
9
|
+
.addColumn("email", "text", (col) => col.notNull().unique())
|
|
10
|
+
.addColumn("source", "text", (col) => col.defaultTo("website"))
|
|
11
|
+
.addColumn("created_at", "timestamptz", (col) =>
|
|
12
|
+
col.notNull().defaultTo(db.fn("now")),
|
|
13
|
+
)
|
|
14
|
+
.execute();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
18
|
-
|
|
18
|
+
await db.schema.dropTable("waitlist").execute();
|
|
19
19
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
2
|
|
|
3
3
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
await db.schema
|
|
5
|
+
.alterTable("waitlist")
|
|
6
|
+
.addColumn("status", "text", (col) => col.notNull().defaultTo("pending"))
|
|
7
|
+
.execute();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
11
|
-
|
|
11
|
+
await db.schema.alterTable("waitlist").dropColumn("status").execute();
|
|
12
12
|
}
|
|
@@ -2,62 +2,62 @@ import type { Kysely } from "kysely";
|
|
|
2
2
|
import { sql } from "kysely";
|
|
3
3
|
|
|
4
4
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
await db.schema
|
|
6
|
+
.createTable("account_insights")
|
|
7
|
+
.addColumn("id", "uuid", (col) =>
|
|
8
|
+
col.primaryKey().defaultTo(db.fn("gen_random_uuid")),
|
|
9
|
+
)
|
|
10
|
+
.addColumn("account_id", "uuid", (col) =>
|
|
11
|
+
col.notNull().references("accounts.id"),
|
|
12
|
+
)
|
|
13
|
+
.addColumn("category", "text", (col) => col.notNull())
|
|
14
|
+
.addColumn("insight_type", "text", (col) => col.notNull())
|
|
15
|
+
.addColumn("resource_id", "text")
|
|
16
|
+
.addColumn("severity", "text", (col) => col.notNull())
|
|
17
|
+
.addColumn("title", "text", (col) => col.notNull())
|
|
18
|
+
.addColumn("body", "text", (col) => col.notNull())
|
|
19
|
+
.addColumn("data", "jsonb")
|
|
20
|
+
.addColumn("dismissed_at", "timestamptz")
|
|
21
|
+
.addColumn("expires_at", "timestamptz")
|
|
22
|
+
.addColumn("created_at", "timestamptz", (col) =>
|
|
23
|
+
col.notNull().defaultTo(db.fn("now")),
|
|
24
|
+
)
|
|
25
|
+
.execute();
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
await db.schema
|
|
28
|
+
.createIndex("idx_account_insights_account")
|
|
29
|
+
.on("account_insights")
|
|
30
|
+
.column("account_id")
|
|
31
|
+
.execute();
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
await db.schema
|
|
34
|
+
.createTable("account_agent_runs")
|
|
35
|
+
.addColumn("id", "uuid", (col) =>
|
|
36
|
+
col.primaryKey().defaultTo(db.fn("gen_random_uuid")),
|
|
37
|
+
)
|
|
38
|
+
.addColumn("account_id", "uuid", (col) =>
|
|
39
|
+
col.notNull().references("accounts.id"),
|
|
40
|
+
)
|
|
41
|
+
.addColumn("started_at", "timestamptz", (col) =>
|
|
42
|
+
col.notNull().defaultTo(db.fn("now")),
|
|
43
|
+
)
|
|
44
|
+
.addColumn("completed_at", "timestamptz")
|
|
45
|
+
.addColumn("status", "text", (col) => col.notNull().defaultTo("running"))
|
|
46
|
+
.addColumn("input_tokens", "integer", (col) => col.defaultTo(0))
|
|
47
|
+
.addColumn("output_tokens", "integer", (col) => col.defaultTo(0))
|
|
48
|
+
.addColumn("cost_usd", sql`numeric(10,6)`, (col) => col.defaultTo(0))
|
|
49
|
+
.addColumn("insights_created", "integer", (col) => col.defaultTo(0))
|
|
50
|
+
.addColumn("error", "text")
|
|
51
|
+
.execute();
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
await db.schema
|
|
54
|
+
.createIndex("idx_account_agent_runs_account")
|
|
55
|
+
.on("account_agent_runs")
|
|
56
|
+
.column("account_id")
|
|
57
|
+
.execute();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
await db.schema.dropTable("account_agent_runs").execute();
|
|
62
|
+
await db.schema.dropTable("account_insights").execute();
|
|
63
63
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
2
|
|
|
3
3
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
await db.schema
|
|
5
|
+
.createTable("view_health_snapshots")
|
|
6
|
+
.addColumn("id", "uuid", (col) =>
|
|
7
|
+
col.primaryKey().defaultTo(db.fn("gen_random_uuid")),
|
|
8
|
+
)
|
|
9
|
+
.addColumn("view_id", "uuid", (col) =>
|
|
10
|
+
col.notNull().references("views.id").onDelete("cascade"),
|
|
11
|
+
)
|
|
12
|
+
.addColumn("total_processed", "bigint", (col) => col.notNull())
|
|
13
|
+
.addColumn("total_errors", "bigint", (col) => col.notNull())
|
|
14
|
+
.addColumn("last_processed_block", "integer")
|
|
15
|
+
.addColumn("captured_at", "timestamptz", (col) =>
|
|
16
|
+
col.notNull().defaultTo(db.fn("now")),
|
|
17
|
+
)
|
|
18
|
+
.execute();
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
await db.schema
|
|
21
|
+
.createIndex("idx_view_health_snapshots_view_captured")
|
|
22
|
+
.on("view_health_snapshots")
|
|
23
|
+
.columns(["view_id", "captured_at"])
|
|
24
|
+
.execute();
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
28
|
-
|
|
28
|
+
await db.schema.dropTable("view_health_snapshots").execute();
|
|
29
29
|
}
|
|
@@ -2,41 +2,41 @@ import type { Kysely } from "kysely";
|
|
|
2
2
|
import { sql } from "kysely";
|
|
3
3
|
|
|
4
4
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
await db.schema
|
|
6
|
+
.createTable("view_processing_stats")
|
|
7
|
+
.addColumn("id", "uuid", (col) =>
|
|
8
|
+
col.primaryKey().defaultTo(db.fn("gen_random_uuid")),
|
|
9
|
+
)
|
|
10
|
+
.addColumn("view_name", "text", (col) => col.notNull())
|
|
11
|
+
.addColumn("api_key_id", "text")
|
|
12
|
+
.addColumn("bucket_start", "timestamptz")
|
|
13
|
+
.addColumn("bucket_end", "timestamptz")
|
|
14
|
+
.addColumn("blocks_processed", "integer")
|
|
15
|
+
.addColumn("total_time_ms", "integer")
|
|
16
|
+
.addColumn("handler_time_ms", "integer")
|
|
17
|
+
.addColumn("flush_time_ms", "integer")
|
|
18
|
+
.addColumn("max_block_time_ms", "integer")
|
|
19
|
+
.addColumn("max_handler_time_ms", "integer")
|
|
20
|
+
.addColumn("avg_ops_per_block", sql`real`)
|
|
21
|
+
.addColumn("is_catchup", "boolean", (col) => col.defaultTo(false))
|
|
22
|
+
.addColumn("created_at", "timestamptz", (col) =>
|
|
23
|
+
col.notNull().defaultTo(db.fn("now")),
|
|
24
|
+
)
|
|
25
|
+
.execute();
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
await db.schema
|
|
28
|
+
.createIndex("idx_view_processing_stats_view_bucket")
|
|
29
|
+
.on("view_processing_stats")
|
|
30
|
+
.columns(["view_name", "bucket_start"])
|
|
31
|
+
.execute();
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
await db.schema
|
|
34
|
+
.createIndex("idx_view_processing_stats_api_key")
|
|
35
|
+
.on("view_processing_stats")
|
|
36
|
+
.column("api_key_id")
|
|
37
|
+
.execute();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
41
|
-
|
|
41
|
+
await db.schema.dropTable("view_processing_stats").execute();
|
|
42
42
|
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
2
|
|
|
3
3
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
await db.schema
|
|
5
|
+
.createTable("view_table_snapshots")
|
|
6
|
+
.addColumn("id", "uuid", (col) =>
|
|
7
|
+
col.primaryKey().defaultTo(db.fn("gen_random_uuid")),
|
|
8
|
+
)
|
|
9
|
+
.addColumn("view_name", "text", (col) => col.notNull())
|
|
10
|
+
.addColumn("api_key_id", "text")
|
|
11
|
+
.addColumn("table_name", "text", (col) => col.notNull())
|
|
12
|
+
.addColumn("row_count", "bigint")
|
|
13
|
+
.addColumn("created_at", "timestamptz", (col) =>
|
|
14
|
+
col.notNull().defaultTo(db.fn("now")),
|
|
15
|
+
)
|
|
16
|
+
.execute();
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
await db.schema
|
|
19
|
+
.createIndex("idx_view_table_snapshots_view_table_created")
|
|
20
|
+
.on("view_table_snapshots")
|
|
21
|
+
.columns(["view_name", "table_name", "created_at"])
|
|
22
|
+
.execute();
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
await db.schema
|
|
25
|
+
.createIndex("idx_view_table_snapshots_api_key")
|
|
26
|
+
.on("view_table_snapshots")
|
|
27
|
+
.column("api_key_id")
|
|
28
|
+
.execute();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
32
|
-
|
|
32
|
+
await db.schema.dropTable("view_table_snapshots").execute();
|
|
33
33
|
}
|
|
@@ -2,43 +2,71 @@ import type { Kysely } from "kysely";
|
|
|
2
2
|
import { sql } from "kysely";
|
|
3
3
|
|
|
4
4
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
5
|
+
// Drop old trigger + function
|
|
6
|
+
await sql`DROP TRIGGER IF EXISTS views_notify_trigger ON "views"`.execute(db);
|
|
7
|
+
await sql`DROP FUNCTION IF EXISTS notify_view_changes()`.execute(db);
|
|
8
|
+
|
|
9
|
+
// Rename tables
|
|
10
|
+
await sql`ALTER TABLE "views" RENAME TO "subgraphs"`.execute(db);
|
|
11
|
+
await sql`ALTER TABLE "view_health_snapshots" RENAME TO "subgraph_health_snapshots"`.execute(
|
|
12
|
+
db,
|
|
13
|
+
);
|
|
14
|
+
await sql`ALTER TABLE "view_processing_stats" RENAME TO "subgraph_processing_stats"`.execute(
|
|
15
|
+
db,
|
|
16
|
+
);
|
|
17
|
+
await sql`ALTER TABLE "view_table_snapshots" RENAME TO "subgraph_table_snapshots"`.execute(
|
|
18
|
+
db,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// Rename indexes on subgraphs (formerly views)
|
|
22
|
+
await sql`ALTER INDEX "views_name_idx" RENAME TO "subgraphs_name_idx"`.execute(
|
|
23
|
+
db,
|
|
24
|
+
);
|
|
25
|
+
await sql`ALTER INDEX "views_status_idx" RENAME TO "subgraphs_status_idx"`.execute(
|
|
26
|
+
db,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Rename indexes on subgraph_health_snapshots
|
|
30
|
+
await sql`ALTER INDEX "idx_view_health_snapshots_view_captured" RENAME TO "idx_subgraph_health_snapshots_subgraph_captured"`.execute(
|
|
31
|
+
db,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// Rename indexes on subgraph_processing_stats
|
|
35
|
+
await sql`ALTER INDEX "idx_view_processing_stats_view_bucket" RENAME TO "idx_subgraph_processing_stats_subgraph_bucket"`.execute(
|
|
36
|
+
db,
|
|
37
|
+
);
|
|
38
|
+
await sql`ALTER INDEX "idx_view_processing_stats_api_key" RENAME TO "idx_subgraph_processing_stats_api_key"`.execute(
|
|
39
|
+
db,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Rename indexes on subgraph_table_snapshots
|
|
43
|
+
await sql`ALTER INDEX "idx_view_table_snapshots_view_table_created" RENAME TO "idx_subgraph_table_snapshots_subgraph_table_created"`.execute(
|
|
44
|
+
db,
|
|
45
|
+
);
|
|
46
|
+
await sql`ALTER INDEX "idx_view_table_snapshots_api_key" RENAME TO "idx_subgraph_table_snapshots_api_key"`.execute(
|
|
47
|
+
db,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Rename column view_id → subgraph_id in health snapshots
|
|
51
|
+
await sql`ALTER TABLE "subgraph_health_snapshots" RENAME COLUMN "view_id" TO "subgraph_id"`.execute(
|
|
52
|
+
db,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// Rename column view_name → subgraph_name in processing stats and table snapshots
|
|
56
|
+
await sql`ALTER TABLE "subgraph_processing_stats" RENAME COLUMN "view_name" TO "subgraph_name"`.execute(
|
|
57
|
+
db,
|
|
58
|
+
);
|
|
59
|
+
await sql`ALTER TABLE "subgraph_table_snapshots" RENAME COLUMN "view_name" TO "subgraph_name"`.execute(
|
|
60
|
+
db,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Rename FK constraint (Postgres auto-names it based on original table/column)
|
|
64
|
+
await sql`ALTER TABLE "subgraph_health_snapshots" RENAME CONSTRAINT "view_health_snapshots_view_id_fkey" TO "subgraph_health_snapshots_subgraph_id_fkey"`.execute(
|
|
65
|
+
db,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Recreate notify trigger with new names
|
|
69
|
+
await sql`
|
|
42
70
|
CREATE OR REPLACE FUNCTION notify_subgraph_changes() RETURNS trigger AS $$
|
|
43
71
|
BEGIN
|
|
44
72
|
PERFORM pg_notify('subgraph_changes', json_build_object(
|
|
@@ -50,14 +78,14 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|
|
50
78
|
$$ LANGUAGE plpgsql
|
|
51
79
|
`.execute(db);
|
|
52
80
|
|
|
53
|
-
|
|
81
|
+
await sql`
|
|
54
82
|
CREATE TRIGGER subgraphs_notify_trigger
|
|
55
83
|
AFTER INSERT OR UPDATE OR DELETE ON "subgraphs"
|
|
56
84
|
FOR EACH ROW EXECUTE FUNCTION notify_subgraph_changes()
|
|
57
85
|
`.execute(db);
|
|
58
86
|
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
// Rename any existing tenant schemas from view_* to subgraph_*
|
|
88
|
+
await sql`
|
|
61
89
|
DO $$
|
|
62
90
|
DECLARE
|
|
63
91
|
s record;
|
|
@@ -69,20 +97,26 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|
|
69
97
|
END $$
|
|
70
98
|
`.execute(db);
|
|
71
99
|
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
// Update schema_name column in subgraphs table to match new prefix
|
|
101
|
+
await sql`UPDATE "subgraphs" SET schema_name = 'subgraph_' || substring(schema_name from 6) WHERE schema_name LIKE 'view_%'`.execute(
|
|
102
|
+
db,
|
|
103
|
+
);
|
|
74
104
|
}
|
|
75
105
|
|
|
76
106
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
// Drop new trigger + function
|
|
108
|
+
await sql`DROP TRIGGER IF EXISTS subgraphs_notify_trigger ON "subgraphs"`.execute(
|
|
109
|
+
db,
|
|
110
|
+
);
|
|
111
|
+
await sql`DROP FUNCTION IF EXISTS notify_subgraph_changes()`.execute(db);
|
|
112
|
+
|
|
113
|
+
// Revert schema_name column
|
|
114
|
+
await sql`UPDATE "subgraphs" SET schema_name = 'view_' || substring(schema_name from 10) WHERE schema_name LIKE 'subgraph_%'`.execute(
|
|
115
|
+
db,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// Revert tenant schemas
|
|
119
|
+
await sql`
|
|
86
120
|
DO $$
|
|
87
121
|
DECLARE
|
|
88
122
|
s record;
|
|
@@ -94,29 +128,57 @@ export async function down(db: Kysely<any>): Promise<void> {
|
|
|
94
128
|
END $$
|
|
95
129
|
`.execute(db);
|
|
96
130
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
// Rename columns back
|
|
132
|
+
await sql`ALTER TABLE "subgraph_health_snapshots" RENAME CONSTRAINT "subgraph_health_snapshots_subgraph_id_fkey" TO "view_health_snapshots_view_id_fkey"`.execute(
|
|
133
|
+
db,
|
|
134
|
+
);
|
|
135
|
+
await sql`ALTER TABLE "subgraph_table_snapshots" RENAME COLUMN "subgraph_name" TO "view_name"`.execute(
|
|
136
|
+
db,
|
|
137
|
+
);
|
|
138
|
+
await sql`ALTER TABLE "subgraph_processing_stats" RENAME COLUMN "subgraph_name" TO "view_name"`.execute(
|
|
139
|
+
db,
|
|
140
|
+
);
|
|
141
|
+
await sql`ALTER TABLE "subgraph_health_snapshots" RENAME COLUMN "subgraph_id" TO "view_id"`.execute(
|
|
142
|
+
db,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Rename indexes back
|
|
146
|
+
await sql`ALTER INDEX "idx_subgraph_table_snapshots_api_key" RENAME TO "idx_view_table_snapshots_api_key"`.execute(
|
|
147
|
+
db,
|
|
148
|
+
);
|
|
149
|
+
await sql`ALTER INDEX "idx_subgraph_table_snapshots_subgraph_table_created" RENAME TO "idx_view_table_snapshots_view_table_created"`.execute(
|
|
150
|
+
db,
|
|
151
|
+
);
|
|
152
|
+
await sql`ALTER INDEX "idx_subgraph_processing_stats_api_key" RENAME TO "idx_view_processing_stats_api_key"`.execute(
|
|
153
|
+
db,
|
|
154
|
+
);
|
|
155
|
+
await sql`ALTER INDEX "idx_subgraph_processing_stats_subgraph_bucket" RENAME TO "idx_view_processing_stats_view_bucket"`.execute(
|
|
156
|
+
db,
|
|
157
|
+
);
|
|
158
|
+
await sql`ALTER INDEX "idx_subgraph_health_snapshots_subgraph_captured" RENAME TO "idx_view_health_snapshots_view_captured"`.execute(
|
|
159
|
+
db,
|
|
160
|
+
);
|
|
161
|
+
await sql`ALTER INDEX "subgraphs_status_idx" RENAME TO "views_status_idx"`.execute(
|
|
162
|
+
db,
|
|
163
|
+
);
|
|
164
|
+
await sql`ALTER INDEX "subgraphs_name_idx" RENAME TO "views_name_idx"`.execute(
|
|
165
|
+
db,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// Rename tables back
|
|
169
|
+
await sql`ALTER TABLE "subgraph_table_snapshots" RENAME TO "view_table_snapshots"`.execute(
|
|
170
|
+
db,
|
|
171
|
+
);
|
|
172
|
+
await sql`ALTER TABLE "subgraph_processing_stats" RENAME TO "view_processing_stats"`.execute(
|
|
173
|
+
db,
|
|
174
|
+
);
|
|
175
|
+
await sql`ALTER TABLE "subgraph_health_snapshots" RENAME TO "view_health_snapshots"`.execute(
|
|
176
|
+
db,
|
|
177
|
+
);
|
|
178
|
+
await sql`ALTER TABLE "subgraphs" RENAME TO "views"`.execute(db);
|
|
179
|
+
|
|
180
|
+
// Recreate old trigger
|
|
181
|
+
await sql`
|
|
120
182
|
CREATE OR REPLACE FUNCTION notify_view_changes() RETURNS trigger AS $$
|
|
121
183
|
BEGIN
|
|
122
184
|
PERFORM pg_notify('view_changes', json_build_object(
|
|
@@ -128,7 +190,7 @@ export async function down(db: Kysely<any>): Promise<void> {
|
|
|
128
190
|
$$ LANGUAGE plpgsql
|
|
129
191
|
`.execute(db);
|
|
130
192
|
|
|
131
|
-
|
|
193
|
+
await sql`
|
|
132
194
|
CREATE TRIGGER views_notify_trigger
|
|
133
195
|
AFTER INSERT OR UPDATE OR DELETE ON "views"
|
|
134
196
|
FOR EACH ROW EXECUTE FUNCTION notify_view_changes()
|
|
@@ -2,11 +2,19 @@ import type { Kysely } from "kysely";
|
|
|
2
2
|
import { sql } from "kysely";
|
|
3
3
|
|
|
4
4
|
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
await sql`ALTER TABLE "streams" RENAME COLUMN "webhook_url" TO "endpoint_url"`.execute(
|
|
6
|
+
db,
|
|
7
|
+
);
|
|
8
|
+
await sql`ALTER TABLE "streams" RENAME COLUMN "webhook_secret" TO "signing_secret"`.execute(
|
|
9
|
+
db,
|
|
10
|
+
);
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
await sql`ALTER TABLE "streams" RENAME COLUMN "endpoint_url" TO "webhook_url"`.execute(
|
|
15
|
+
db,
|
|
16
|
+
);
|
|
17
|
+
await sql`ALTER TABLE "streams" RENAME COLUMN "signing_secret" TO "webhook_secret"`.execute(
|
|
18
|
+
db,
|
|
19
|
+
);
|
|
12
20
|
}
|