@secondlayer/shared 4.3.0 → 4.3.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.
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { type Kysely, sql } from "kysely";
|
|
2
2
|
|
|
3
|
+
async function tableExists(db: Kysely<unknown>, tableName: string) {
|
|
4
|
+
const { rows } = await sql<{ exists: boolean }>`
|
|
5
|
+
SELECT to_regclass(${`public.${tableName}`}) IS NOT NULL AS exists
|
|
6
|
+
`.execute(db);
|
|
7
|
+
return rows[0]?.exists === true;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
11
|
+
if (!(await tableExists(db, "subgraphs"))) {
|
|
12
|
+
console.log("Skipping subgraph_operations; subgraphs table is absent");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
await sql`
|
|
5
17
|
CREATE TABLE IF NOT EXISTS subgraph_operations (
|
|
6
18
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
@@ -75,6 +87,10 @@ export async function up(db: Kysely<unknown>): Promise<void> {
|
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
90
|
+
if (!(await tableExists(db, "subgraph_operations"))) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
78
94
|
await sql`
|
|
79
95
|
DROP TRIGGER IF EXISTS subgraph_operations_cancel_notify ON subgraph_operations
|
|
80
96
|
`.execute(db);
|