Skip to content

Commit 708fba4

Browse files
authored
Merge pull request #49 from EOSIO/develop
Release 4.0.0
2 parents d6caa2b + 1143744 commit 708fba4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+12161
-3417
lines changed

.eslintrc.json

Lines changed: 0 additions & 49 deletions
This file was deleted.

.npmignore

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
src
2-
tsconfig.json
3-
tslint.json
41
dist/**/*.test.*
2+
dist/testHelpers/
3+
docs/
4+
examples/
5+
scripts/
6+
src/
7+
.eslintrc.json
8+
.gitignore
59
.idea
6-
yarn-error.log
10+
.npmignore
11+
.npmrc.template
12+
.nvmrc
713
.travis.yml
8-
.eslintrc.json
14+
CONTRIBUTING.md
915
README.md
10-
build-docs.sh
11-
.npmrc.template
12-
scripts/*
16+
tsconfig.json
17+
tslint.json
18+
yarn.lock
19+
yarn-error.log

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.9.4
1+
10.15.1

.travis.yml

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- '10.0.0'
4+
- '10.0.0'
55
before_install:
6-
- npm i -g [email protected]
7-
- npm install -g typescript
6+
7+
- npm install -g typescript
88
stages:
9-
- test
10-
- name: deploy
11-
if: (NOT type IN (pull_request)) AND (branch = develop)
9+
- test
10+
- name: publish-edge
11+
if: (NOT type IN (pull_request)) AND (branch = develop)
12+
- name: publish-latest
13+
# Travis assigns the tag to branch for some reason. This matches any valid semver version.
14+
if: branch =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$
1215
jobs:
1316
include:
14-
- stage: test
15-
name: "Lint and Test"
16-
script:
17-
- npm run lint
18-
- npm run test
19-
- stage: deploy
20-
name: "Deploy to NPM"
21-
script:
22-
- npm run build
23-
deploy:
24-
provider: script
25-
skip_cleanup: true
26-
script:
27-
- ./scripts/publish.sh
28-
on:
29-
branch: develop
17+
- stage: test
18+
name: "Lint and Test"
19+
script:
20+
- npm run lint
21+
- npm run test
22+
- stage: publish-edge
23+
name: "Publish @edge to NPM"
24+
script:
25+
- npm run build
26+
deploy:
27+
provider: script
28+
skip_cleanup: true
29+
script: ./scripts/publish-edge.sh
30+
on:
31+
branch: develop
32+
- stage: publish-latest
33+
name: "Publish @latest to NPM"
34+
script:
35+
- npm run build
36+
deploy:
37+
provider: script
38+
skip_cleanup: true
39+
script: ./scripts/publish-latest.sh
40+
on:
41+
all_branches: true
42+
condition: $TRAVIS_TAG =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$

README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,65 @@ npm install massive --save
1616

1717
### MassiveActionHandler
1818

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:
36+
37+
*create_todo_table.sql*
38+
```sql
39+
CREATE TABLE ${schema~}.todo (
40+
id int PRIMARY KEY,
41+
name text NOT NULL
42+
);
43+
```
44+
45+
*migrationSequences.js*
46+
```javascript
47+
import { Migration } from "demux-postgres"
48+
49+
const createTodoTable = new Migration(
50+
"createTodoTable", // name
51+
"myschema", // schema
52+
"create_todo_table.sql", // SQL file
53+
)
54+
55+
// MigrationSequence[]
56+
// See: https://github.com/EOSIO/demux-js-postgres/blob/develop/src/interfaces.ts
57+
module.exports = [{
58+
migrations: [createTodoTable],
59+
sequenceName: "init"
60+
}]
61+
```
62+
63+
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+
async function migrateDatabase(db, payload) {
71+
await db.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.
76+
77+
### Example
2078

2179
```javascript
2280
const { BaseActionWatcher } = require("demux")
@@ -28,6 +86,9 @@ const massive = require("massive")
2886
// See https://eosio.github.io/demux-js/ for info on Handler Versions, Updaters, and Effects
2987
const handlerVersions = require("./handlerVersions") // Import your handler versions
3088

89+
// See "Migrations" section above
90+
const migrationSequences = require("./migrationSequences")
91+
3192
// See https://dmfay.github.io/massive-js/connecting.html for info on massive configuration
3293
const dbConfig = { ... }
3394

@@ -36,7 +97,8 @@ massive(dbConfig).then((db) => {
3697
const actionHandler = new MassiveActionHandler(
3798
handlerVersions,
3899
db,
39-
dbConfig.schema
100+
dbConfig.schema,
101+
migrationSequences
40102
)
41103
const actionWatcher = new BaseActionWatcher(actionReader, actionHander, 500)
42104
actionWatcher.watch()

docs/assets/js/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)