You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+64-2Lines changed: 64 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,65 @@ npm install massive --save
16
16
17
17
### MassiveActionHandler
18
18
19
-
The MassiveActionHandler uses [massive-js](https://github.com/dmfay/massive-js) to interact with a Postgres database for storing internal demux state as well as the state calculated by updaters.
19
+
The `MassiveActionHandler` uses [massive-js](https://github.com/dmfay/massive-js) to interact with a Postgres database for storing internal demux state and state calculated by Updaters. Rollback of state due to forks is supported by committing all database writes to per-block databases transactions, and utilizing [Cyan Audit](https://bitbucket.org/neadwerx/cyanaudit/overview) to reverse those transactions in reverse order when needed.
20
+
21
+
#### Setup
22
+
23
+
In order to instantiate a `MassiveActionHandler`, four arguments are needed:
24
+
25
+
-`handlerVersions`: This is an array of `HandlerVersion`s. For more information, [see the `demux-js` documentation](https://eosio.github.io/demux-js/classes/abstractactionhandler.html#applyupdaters).
26
+
27
+
-`massiveInstance`: A connected massive database connection object. demux-js-postgress requires that you have a Postgres server running version 9.6 or greater. For more information on how to configure and instantiate this object, see the [massivejs documentation](https://github.com/dmfay/massive-js#connecting-to-a-database).
28
+
29
+
-`dbSchema`: The name of the schema we will operate in.
30
+
31
+
-`migrationSequences`: *(See next section below)*
32
+
33
+
#### Migrations
34
+
35
+
The `MassiveActionHandler` will manage all of the Postgres migrations relevant to demux operations. In addition to setting up all internal requirements (idempotently creating the specified `dbSchema` and required internal tables, installing/activating Cyan Audit), you may create additional migrations that run either at initial setup, or are triggered by an action at some point in the future. This is done by writing your migrations as SQL files, loading them via the `Migration` constructor, and collecting them into an array of `MigrationSequence`s:
You can then use this object for the `migrationSequences` argument of the `MassiveActionHandler` constructor.
64
+
65
+
Once you have instantiated the `MassiveActionHandler`, you can set up your database via the `setupDatabase()` method. If you have a `MigrationSequence` with the name `"init"`, then this migration sequence will run after all other internal database setup is finished.
66
+
67
+
It can be useful to trigger migrations from actions (for example, when a contract updates), much in the same way it is useful to [update HandlerVersions](https://eosio.github.io/demux-js/classes/abstractactionhandler.html#applyupdaters). You may do this from an Updater's `apply` function via `db.migrate(<MigrationSequence.sequenceName>)`:
68
+
69
+
```javascript
70
+
asyncfunctionmigrateDatabase(db, payload) {
71
+
awaitdb.migrate(payload.sequenceName) // Blockchain will determine when and what migrations will run
72
+
}
73
+
```
74
+
75
+
This is also important for maintaining determinism of data (e.g. during replays) if schema changes are needed.
0 commit comments