How to Generate a Database Table from Your Neighborhood Pipeline Output
The Neighborhood streams decoded onchain data directly to your database. Once you’ve tested your transformation, the next step is preparing the right table to receive incoming data.To get a real example of your pipeline’s output use the Test Transformation API to run a dry-run and view the event format.Here’s an example output from a tested transformation:
Alternatively, paste your transformation code into an large language model (LLM) like ChatGPT and ask it to generate a table based on this code. The model will make assumptions on the data, so ensure to check the generated table schema.
Paste the example output into an LLM or a tool like jsonschema2ddl, and ask it to generate a CREATE TABLE statement for your database of choice (e.g., PostgreSQL, MySQL, SQLite). The primary key has to be a unique combination.Example prompt:
Copy
Convert this JSON into a CREATE TABLE statement for [your database type].Use appropriate types (e.g., bigint, text, jsonb). Name the table [your table name].Add a compound primary key on (chain, transaction_hash, log_index).
Here’s an ideal result if you’re using PostgreSQL:
Copy
CREATE TABLE AavePool ( chain TEXT NOT NULL, block BIGINT NOT NULL, transaction_hash TEXT NOT NULL, log_index INTEGER NOT NULL, contract_address TEXT NOT NULL, event_name TEXT NOT NULL, decoded JSONB NOT NULL, created_at TIMESTAMPTZ DEFAULT now(), PRIMARY KEY (chain, transaction_hash, log_index));
This schema uses a compound key to ensure idempotency. Since pipelines provide at-least-once delivery, uniqueness matters to prevent duplicate rows and ensure data integrity.