Skip to content

Commit 1e56df4

Browse files
committed
Create ENSNode Schema in ENSDb SDK
Define `metadata` table schema.
1 parent 7b42209 commit 1e56df4

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { pgSchema, primaryKey } from "drizzle-orm/pg-core";
2+
3+
/**
4+
* ENSNode Schema Name
5+
*
6+
* This is the name of the Postgres schema that will be present in the ENSDb.
7+
*/
8+
const ENSNODE_SCHEMA_NAME = "ensnode";
9+
10+
/**
11+
* ENSNode Schema
12+
*
13+
* Used to define database objects within the ENSNode Schema in ENSDb.
14+
*/
15+
const ENSNODE_SCHEMA = pgSchema(ENSNODE_SCHEMA_NAME);
16+
17+
/**
18+
* ENSNode Metadata
19+
*
20+
* Possible key value pairs are defined by 'EnsNodeMetadata' type:
21+
* - `EnsNodeMetadataEnsDbVersion`
22+
* - `EnsNodeMetadataEnsIndexerPublicConfig`
23+
* - `EnsNodeMetadataEnsIndexerIndexingStatus`
24+
*/
25+
export const metadata = ENSNODE_SCHEMA.table(
26+
"metadata",
27+
(t) => ({
28+
/**
29+
* ENSIndexer Schema Name
30+
*
31+
* References the name of the ENSIndexer Schema that the metadata record
32+
* belongs to. This allows multi-tenancy where multiple ENSIndexer
33+
* instances can write to the same ENSNode Metadata table.
34+
*/
35+
ensIndexerSchemaName: t.text().notNull(),
36+
37+
/**
38+
* Key
39+
*
40+
* Allowed keys:
41+
* - `EnsNodeMetadataEnsDbVersion['key']`
42+
* - `EnsNodeMetadataEnsIndexerPublicConfig['key']`
43+
* - `EnsNodeMetadataEnsIndexerIndexingStatus['key']`
44+
*/
45+
key: t.text().notNull(),
46+
47+
/**
48+
* Value
49+
*
50+
* Allowed values:
51+
* - `EnsNodeMetadataEnsDbVersion['value']`
52+
* - `EnsNodeMetadataEnsIndexerPublicConfig['value']`
53+
* - `EnsNodeMetadataEnsIndexerIndexingStatus['value']`
54+
*
55+
* Guaranteed to be a serialized representation of JSON object.
56+
*/
57+
value: t.jsonb().notNull(),
58+
}),
59+
(table) => [
60+
/**
61+
* Primary key constraint on 'ensIndexerSchemaName' and 'key' columns,
62+
* to ensure that there is only one record for each key per ENSIndexer instance.
63+
*/
64+
primaryKey({
65+
name: "metadata_pkey",
66+
columns: [table.ensIndexerSchemaName, table.key],
67+
}),
68+
],
69+
);

0 commit comments

Comments
 (0)