Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📖 readme #205

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -91,7 +91,7 @@ sqd migration:generate
sqd migration:apply
```

### Dev hacks
## Misc

1. fast generate event handlers

Expand Down
13 changes: 13 additions & 0 deletions db/migrations/1706015961189-Data.js
Original file line number Diff line number Diff line change
@@ -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"`)
}
}
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ migrate:
update-db:
npx squid-typeorm-migration generate

revert-db:
npx squid-typeorm-migration revert

db: update-db migrate

test:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down