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

Update F.A.Q page #1079

Merged
merged 6 commits into from
Jul 31, 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
4 changes: 0 additions & 4 deletions docs/1.getting-started/4.package.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ DipDup uses contract type information to generate [Pydantic](https://docs.pydant

This approach allows working with complex contract types with nested structures and polymorphic variants.

::banner{type="note"}
Currently, we use Pydantic v1, but plan to migrate to v2 one day.
::

## Nested packages

Callbacks can be grouped into packages to organize the project structure. Add one or multiple dots to the callback name to define nested packages:
Expand Down
64 changes: 52 additions & 12 deletions docs/12.faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ nested: Resources

This page contains answers to the most frequently asked questions about DipDup.

## General

### What hardware do I need to run DipDup?

DipDup can run on any amd64/arm64 machine starting from 1 CPU core and 256M of RAM. Aim for a good single-threaded and disk I/O performance.

Actual RAM requirements depend on multiple factors: the number and complexity of indexes, the size of internal queues and caches, and the usage of `CachedModel`. For the average project, 1GB is usually enough. If you're running DipDup on some ultra-low-end instance and getting OOMs, try the `DIPDUP_LOW_MEMORY=1` environment variable.

## Indexing

### How to index similar but not identical contracts as a single entity?
Expand Down Expand Up @@ -48,38 +56,44 @@ Instead, save raw data in handlers and process it later with hooks when all cond

### How to perform database migrations?

DipDup does not provide any tooling for database migrations. The reason is that in context of indexing, schema changes are rare and usually require reindexing. However, you can perform migrations yourself using any tool you like. First, disable schema hash check in config:
At the moment DipDup does not have a built-in migration system. Framework architecture implies that schema changes are rare and usually require reindexing. However, you can perform migrations yourself using third-party tools or write your own scripts and keep them in `sql` project directory.

You may want to disable the schema hash check in config. Alternatively, call the `schema approve` command after every schema change.

```yaml [dipdup.yaml]
advanced:
reindex:
schema_modified: ignore
```

You can also use the `schema approve` command for a single schema change.

To determine changes you need to apply after modifying classes in the `models` module, you can compare raw SQL schema before and after the change.
Now, let's prepare a migration script. To determine the changes you need to make, you can compare the SQL schema dump before and after modifying the models. Say you need to add a new field to one of the models.

```diff
- timestamp = fields.DatetimeField()
+ timestamp = fields.DatetimeField(auto_now=True)
class Event(Model):
...
+ timestamp = fields.DatetimeField()
```

```shell
dipdup schema export > old-schema.sql
# ...after modifying `models` module...
# [make some changes]
dipdup schema export > new-schema.sql
diff old-schema.sql new-schema.sql
```

And here's SQL for the new column:

```diff
76c76
< "timestamp" TIMESTAMP NOT NULL,
---
> "timestamp" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "timestamp" TIMESTAMP NOT NULL,
```

Now you can prepare and execute an `ALTER TABLE` query manually or using SQL hooks.
Now prepare the idempotent migration script and put it in the `sql/on_restart` directory.

```sql [sql/on_restart/00-add-timestamp.sql]
ALTER TABLE "event" ADD COLUMN IF NOT EXISTS "timestamp" TIMESTAMP NOT NULL;

SELECT dipdup_approve('public');
```

### I get `schema_modified` error, but I didn't change anything

Expand Down Expand Up @@ -133,3 +147,29 @@ Don't forget to reindex after this change. When decimal context precision is adj
```text
WARNING dipdup.database Decimal context precision has been updated: 28 -> 128
```

## Package

### What is the symlink in the project root for?

DipDup project must be a valid discoverable Python package. Python searches for packages in `site-packages` and the current working directory. This symlink is a hack that allows project root to serve as a working directory without requiring a subdirectory. It's created only when `dipdup init` is executed from the project root. While this symlink trick _should_ be harmless, if it interferes with any of your tools, use `DIPDUP_NO_SYMLINK=1` environment variable to disable this behavior.

## Maintenance

### pipx, Poetry, PDM... What's the difference?

For historical reasons, Python package management is a mess. There are multiple tools and approaches to manage Python dependencies. Here's a brief comparison:

- **pip** is a general-purpose package manager. It's simple and robust, but you need to manage venvs and lock files manually.
- **pipx** is meant for applications. It installs packages into separate environments in `~/.local/pipx/venvs` and makes their CLI commands available from any path. pipx is a recommended way to install DipDup CLI.
- **Poetry** and **PDM** are full-fledged project management tools. They handle venvs, lock files, dependency resolution, publishing, etc.

Using PDM/Poetry is not required to run DipDup, but strongly recommended. Choosing one over the other is a matter of personal preference. _As of writing_, Poetry is [faster](https://lincolnloop.github.io/python-package-manager-shootout/), more popular, and has a nicer CLI, while PDM is more PEP-compatible and allows dependency overrides.

You can choose the preferred tool (or none) when initializing a project with `dipdup new` command. If you change your mind later, modify the `replay.yaml` file and run `dipdup init --base --force`.

## Miscellaneous

### Why it's called DipDup?

DipDup (/dɪp dʌp/) was initially developed as a grant project for the [Tezos Foundation](https://tezos.foundation/). Tezos is one of the few blockchains with its own contract language, completely different from Solidity. This low-level, stack-based language is called [Michelson](https://tezos.gitlab.io/active/michelson.html). The name "DipDup" comes from `DIP {DUP}`, a small Michelson program that duplicates the second element on the stack. While today we support dozens of blockchains, Tezos holds a special place in our project's history.
Loading