From e0cc6c8e48e114192fe68cd7f63a62c88634c789 Mon Sep 17 00:00:00 2001 From: roiLeo Date: Tue, 23 Jan 2024 14:25:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=96=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 56 ++++++++++++++--------------- db/migrations/1706015961189-Data.js | 13 +++++++ justfile | 3 ++ package.json | 4 +-- 4 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 db/migrations/1706015961189-Data.js diff --git a/README.md b/README.md index 1189dbda..5051b40e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,22 @@ ![](https://media.tenor.com/eK1dyB3TOLsAAAAC/anime-stick.gif) -KodaDot's [Squid](https://docs.subsquid.io) based data processor for [KodaDot](https://kodadot.xyz) NFT Marketplace. +[Squid](https://docs.subsquid.io) based data used to index, process and query on top of AssetHub for [KodaDot](https://kodadot.xyz) NFT Marketplace. + +## Hosted Squids + +* Kusama AssetHub Processor (Statemine -> KSM): https://squid.subsquid.io/stick/graphql +* Polkadot AssetHub Processor (Statemint -> DOT): https://squid.subsquid.io/speck/graphql +* Rococo Testnet Processor: 🚧 WIP 🚧 + +## Project structure + +* `src/generated` - model/server definitions created by `codegen`. Do not alter the contents of this directory manually. +* `src/server-extension` - module with custom `type-graphql` based resolvers. +* `src/types` - data type definitions for chain events and extrinsics created by `typegen`. +* `src/mappings` - mapping module. +* `lib` - compiled js files. The structure of this directory must reflect `src`. +* `.env` - environment variables defined here or supplied by a shell. ## Prerequisites @@ -26,26 +41,12 @@ just upd # 4. Start the processor just process -# 5. The command above will block the terminal -# being busy with fetching the chain data, -# transforming and storing it in the target database. -# -# To start the graphql server open a separate terminal -# and run +# 5. Open a separate terminal and launch the graphql server to query the processed data just serve # 6. Visit localhost:4350/graphql to see result ``` -## Project structure - -* `src/generated` - model/server definitions created by `codegen`. Do not alter the contents of this directory manually. -* `src/server-extension` - module with custom `type-graphql` based resolvers -* `src/types` - data type definitions for chain events and extrinsics created by `typegen`. -* `src/mappings` - mapping module. -* `lib` - compiled js files. The structure of this directory must reflect `src`. -* `.env` - hydra tools are heavily driven by environment variables defined here or supplied by a shell. - ## Dev flow ### 1. Define database schema @@ -56,33 +57,32 @@ Full description of `schema.graphql` dialect is available [here](https://docs.su ### 2. Generate TypeORM classes -Mapping developers use [TypeORM](https://typeorm.io) entities -to interact with the target database during data processing. All necessary entity classes are -generated by the squid framework from `schema.graphql`. This is done by running `npx squid-typeorm-codegen` -or (equivalently) `sqd codegen` command. +Mapping developers use [TypeORM](https://typeorm.io) entities to interact with the target database during data processing. All necessary entity classes are generated by the squid framework from `schema.graphql`. This is done by running `just codegen` command. ### 3. Generate database migration All database changes are applied through migration files located at `db/migrations`. -`squid-typeorm-migration(1)` tool provides several commands to drive the process. +`squid-typeorm-migration` tool provides several commands to drive the process. It is all [TypeORM](https://typeorm.io/#/migrations) under the hood. ```bash # Connect to database, analyze its state and generate migration to match the target schema. +# Launch Docker instance of database +just upd + # The target schema is derived from entity classes generated earlier. # Don't forget to compile your entity classes beforehand! -npx squid-typeorm-migration generate - -# Create template file for custom database changes -npx squid-typeorm-migration create +just update-db # Apply database migrations from `db/migrations` -npx squid-typeorm-migration apply +just migrate # Revert the last performed migration -npx squid-typeorm-migration revert +just revert-db ``` + Available `sqd` shortcuts: + ```bash # Build the project, remove any old migrations, then run `npx squid-typeorm-migration generate` sqd migration:generate @@ -91,7 +91,7 @@ sqd migration:generate sqd migration:apply ``` -### Dev hacks +## Misc 1. fast generate event handlers diff --git a/db/migrations/1706015961189-Data.js b/db/migrations/1706015961189-Data.js new file mode 100644 index 00000000..1da79ce6 --- /dev/null +++ b/db/migrations/1706015961189-Data.js @@ -0,0 +1,13 @@ +module.exports = class Data1706015961189 { + name = 'Data1706015961189' + + async up(db) { + await db.query(`ALTER TABLE "collection_entity" ADD "type" character varying(8)`) + await db.query(`ALTER TABLE "collection_entity" ADD "settings" jsonb`) + } + + async down(db) { + await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "type"`) + await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "settings"`) + } +} diff --git a/justfile b/justfile index ac5524d3..0ffb4d90 100644 --- a/justfile +++ b/justfile @@ -62,6 +62,9 @@ migrate: update-db: npx squid-typeorm-migration generate +revert-db: + npx squid-typeorm-migration revert + db: update-db migrate test: diff --git a/package.json b/package.json index e278e62b..1ce532aa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@kodadot1/stick", - "version": "0.1.0", - "description": "GraphQL service for Uniques and Assets on Statemine", + "version": "0.2.0", + "description": "AssetHub block indexer and graphql server", "private": true, "engines": { "node": ">=16"