Skip to content

Commit

Permalink
feat: store ipfs data in db
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Sep 6, 2024
1 parent 3807d4c commit 33de6de
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 41 deletions.
8 changes: 6 additions & 2 deletions docs/reindexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ When deploying changes to the indexer, it's important to clarify the results you
- The indexer will create a new schema in Postgres named `chain_data_${version}`. If this schema does not exist, it will be created, all necessary tables will be set up, and indexing will start from scratch.
- If the schema already exists, the indexer will resume indexing from the last indexed block unless the `--drop-db` flag is specified via the CLI. This will drop the existing database and start fresh.

### Using `--drop-db` in Development
### Using `--drop-db` | `--drop-chain-db` | `--drop-ipfs-db` in Development

- During development, you can use the `--drop-db` flag to ensure the indexer always deletes the existing schema and migrates from scratch. This can be useful for testing schema changes and event handler modifications without retaining old data.
- During development, you can use the `--drop-db` flag to ensure the indexer always deletes all existing schema and migrates from scratch. This can be useful for testing schema changes and event handler modifications without retaining old data.

- During development, you can use the `--drop-chain-db` flag to ensure the indexer always deletes chain schema and migrates from scratch.

- During development, you can use the `--drop-ipfs-db` flag to ensure the indexer always deletes ipfs schema and migrates from scratch.

### Important Notes

Expand Down
20 changes: 20 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type CoingeckoSupportedChainId =
| 1088;

const CHAIN_DATA_VERSION = "81";
const IPFS_DATA_VERSION = "1";

export type Token = {
code: string;
Expand Down Expand Up @@ -1829,11 +1830,15 @@ export type Config = {
readOnlyDatabaseUrl: string;
dataVersion: string;
databaseSchemaName: string;
ipfsDataVersion: string;
ipfsDatabaseSchemaName: string;
hostname: string;
pinoPretty: boolean;
deploymentEnvironment: "local" | "development" | "staging" | "production";
enableResourceMonitor: boolean;
dropDb: boolean;
dropChainDb: boolean;
dropIpfsDb: boolean;
removeCache: boolean;
estimatesLinearQfWorkerPoolSize: number | null;
};
Expand Down Expand Up @@ -1901,6 +1906,12 @@ export function getConfig(): Config {
"drop-db": {
type: "boolean",
},
"drop-chain-db": {
type: "boolean",
},
"drop-ipfs-db": {
type: "boolean",
},
"rm-cache": {
type: "boolean",
},
Expand Down Expand Up @@ -1989,7 +2000,12 @@ export function getConfig(): Config {
const dataVersion = CHAIN_DATA_VERSION;
const databaseSchemaName = `chain_data_${dataVersion}`;

const ipfsDataVersion = IPFS_DATA_VERSION;
const ipfsDatabaseSchemaName = `ipfs_data_${ipfsDataVersion}`;

const dropDb = z.boolean().default(false).parse(args["drop-db"]);
const dropChainDb = z.boolean().default(false).parse(args["drop-chain-db"]);
const dropIpfsDb = z.boolean().default(false).parse(args["drop-ipfs-db"]);

const removeCache = z.boolean().default(false).parse(args["rm-cache"]);

Expand Down Expand Up @@ -2038,9 +2054,13 @@ export function getConfig(): Config {
databaseUrl,
readOnlyDatabaseUrl,
dropDb,
dropChainDb,
dropIpfsDb,
removeCache,
dataVersion,
databaseSchemaName,
ipfsDataVersion,
ipfsDatabaseSchemaName,
httpServerWaitForSync,
httpServerEnabled,
indexerEnabled,
Expand Down
5 changes: 5 additions & 0 deletions src/database/changeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
NewPrice,
NewLegacyProject,
NewApplicationPayout,
NewIpfsData,
} from "./schema.js";

export type DataChange =
Expand Down Expand Up @@ -140,4 +141,8 @@ export type DataChange =
| {
type: "InsertApplicationPayout";
payout: NewApplicationPayout;
}
| {
type: "InsertIpfsData";
ipfs: NewIpfsData;
};
Loading

0 comments on commit 33de6de

Please sign in to comment.