Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-pigs-shine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ensnode/ensdb-sdk": minor
---

Introduced toolkit for managing ENSDb migrations for ENSNode Schema.
Comment thread
tk-o marked this conversation as resolved.
28 changes: 28 additions & 0 deletions packages/ensdb-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# ENSDb SDK

This package is a utility library for interacting with ENSDb.

## Database schema definitions

### ENSIndexer Schema

This schema consist of database object definitions exported from `src/ensindexer` module.
Comment thread
tk-o marked this conversation as resolved.
Outdated
Defining database objects is done by using functionality from `ponder` package.
Comment thread
tk-o marked this conversation as resolved.
Outdated
Comment thread
tk-o marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence isn't clear. Why are we saying this here? What is the goal? Exactly which functionality from the ponder package?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to show distinction between ENSIndexer Schema and ENSNode Schema when it comes to defining database objects like tables and enums.

ENSIndexer Schema must remain compatible with ponder.schema.ts file requirements: https://ponder.sh/docs/api-reference/ponder/schema

On the other hand, ENSNode Schema should use schema builder API directly from drizzle-orm, and should not use any APIs from ponder package.


#### Applying schema definition updates

Updating database object definitions in ENSIndexer Schema _does not_ require any extra steps. ENSIndexer app is built on top of Ponder app. The Ponder app runtime takes care of generating migrations and having them executed during application runtime. In other words, ENSIndexer Schema in ENSDb gets auto-updated when ENSIndexer app starts.
Comment thread
tk-o marked this conversation as resolved.
Outdated

### ENSNode Schema

This schema consist of database object definitions exported from `src/ensnode` module.
Defining database objects is done by using functionality from `drizzle-orm` package.
Comment thread
tk-o marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my related question above. What is written here currently is not clear.


#### Applying schema definition updates

Updating database object definitions in ENSNode Schema _does_ require an extra step: generating SQL queries to be executed for ENSNode Schema in ENSDb.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be precise. See related comment above for how to improve how you communicate.


Generating SQL queries can be done with the following CLI command:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Generating SQL queries"?

That suggests these are just random SQL queries being generated? Be precise.

```
Comment thread
tk-o marked this conversation as resolved.
Outdated
pnpm -F @ensnode/ensdb-sdk drizzle-kit:generate
```
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

This command will update files inside the `migrations` directory, including SQL files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be more precise. Improve the writing.

The `migrations` directory can be later reference by application runtime (i.e. ENSIndexer app) in order to execute pending SQL migrations for ENSNode Schema in ENSDb.
Comment thread
tk-o marked this conversation as resolved.
Outdated
Comment thread
tk-o marked this conversation as resolved.
Outdated
10 changes: 10 additions & 0 deletions packages/ensdb-sdk/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "drizzle-kit";

const ensNodeSchemaPath = "./src/ensnode/index.ts";

export default defineConfig({
casing: "snake_case",
dialect: "postgresql",
out: "migrations",
schema: ensNodeSchemaPath,
Comment thread
tk-o marked this conversation as resolved.
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE SCHEMA IF NOT EXISTS ensnode;

CREATE TABLE "ensnode"."metadata" (
"ens_indexer_schema_name" text NOT NULL,
"key" text NOT NULL,
"value" jsonb NOT NULL,
CONSTRAINT "metadata_pkey" PRIMARY KEY("ens_indexer_schema_name","key")
);
55 changes: 55 additions & 0 deletions packages/ensdb-sdk/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"id": "d661dcae-f64d-4ecd-a4da-3d5783e17e2c",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"ensnode.metadata": {
"name": "metadata",
"schema": "ensnode",
"columns": {
"ens_indexer_schema_name": {
"name": "ens_indexer_schema_name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"key": {
"name": "key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"value": {
"name": "value",
"type": "jsonb",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"metadata_pkey": {
"name": "metadata_pkey",
"columns": ["ens_indexer_schema_name", "key"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
13 changes: 13 additions & 0 deletions packages/ensdb-sdk/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1773743108514,
"tag": "0000_cultured_captain_cross",
"breakpoints": true
}
]
}
4 changes: 3 additions & 1 deletion packages/ensdb-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"scripts": {
"prepublish": "tsup",
"lint": "biome check --write .",
"lint:ci": "biome ci"
"lint:ci": "biome ci",
"drizzle-kit:generate": "drizzle-kit generate"
},
Comment thread
tk-o marked this conversation as resolved.
"peerDependencies": {
"drizzle-orm": "catalog:",
Expand All @@ -62,6 +63,7 @@
"devDependencies": {
"@ensnode/ensnode-sdk": "workspace:",
"@ensnode/shared-configs": "workspace:*",
"drizzle-kit": "0.31.10",
Comment thread
tk-o marked this conversation as resolved.
Comment thread
tk-o marked this conversation as resolved.
Comment thread
tk-o marked this conversation as resolved.
"drizzle-orm": "catalog:",
"ponder": "catalog:",
"tsup": "catalog:",
Expand Down
Loading
Loading