Skip to content

Commit 7e71582

Browse files
committed
Add support for manually syncing state channel models to the db
1 parent 507937e commit 7e71582

File tree

4 files changed

+264
-95
lines changed

4 files changed

+264
-95
lines changed

packages/common-ts/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"test:watch": "jest --watch --passWithNoTests --detectOpenHandles --verbose"
1616
},
1717
"dependencies": {
18-
"@connext/client": "^7.0.0-alpha.13",
19-
"@connext/store": "^7.0.0-alpha.13",
20-
"@connext/types": "^7.0.0-alpha.13",
18+
"@connext/client": "^7.0.0-alpha.18",
19+
"@connext/store": "^7.0.0-alpha.18",
20+
"@connext/types": "^7.0.0-alpha.18",
2121
"@graphprotocol/contracts": "^0.3.2-beta",
2222
"@urql/core": "^1.12.1",
2323
"cross-fetch": "^3.0.5",
@@ -29,7 +29,7 @@
2929
"pg-hstore": "^2.3.3",
3030
"pino": "^6.3.2",
3131
"prom-client": "^11.5.3",
32-
"sequelize": "5.21.13"
32+
"sequelize": "^6.3.1"
3333
},
3434
"devDependencies": {
3535
"@types/bs58": "^4.0.1",

packages/common-ts/src/state-channels/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as connext from '@connext/client'
2-
import { Sequelize } from 'sequelize'
2+
import { Sequelize, ModelCtor, Model } from 'sequelize'
33
import { ILogger, IConnextClient } from '@connext/types'
44
import { getPostgresStore } from '@connext/store'
5+
import { getSequelizeModelDefinitionData } from '@connext/store/dist/wrappers/sequelizeStorage'
6+
import { storeDefaults } from '@connext/store/dist/constants'
57

68
interface StateChannelOptions {
79
sequelize: Sequelize
@@ -14,6 +16,16 @@ interface StateChannelOptions {
1416
storePrefix?: string // for multiple channels to share a sequelize instance
1517
}
1618

19+
export const defineStateChannelStoreModels = async (
20+
sequelize: Sequelize,
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22+
): Promise<void> => {
23+
sequelize.define(
24+
storeDefaults.DATABASE_TABLE_NAME,
25+
getSequelizeModelDefinitionData(sequelize.getDialect() as 'postgres' | 'sqlite'),
26+
)
27+
}
28+
1729
export const createStateChannel = async (
1830
options: StateChannelOptions,
1931
): Promise<IConnextClient> => {
@@ -30,5 +42,6 @@ export const createStateChannel = async (
3042
signer: options.privateKey,
3143
logLevel: options.logLevel,
3244
logger: options.logger,
45+
skipInitStore: true,
3346
})
3447
}

packages/common-ts/src/state-channels/stateChannel.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22

33
import { connectDatabase } from '../database'
4-
import { createStateChannel } from '.'
4+
import { createStateChannel, defineStateChannelStoreModels } from '.'
55
import { Wallet } from 'ethers'
66

77
// Make global Jest variable available
@@ -11,6 +11,9 @@ declare const __INDRA__: any
1111
describe('State Channel', () => {
1212
test('creates a state channel', async () => {
1313
const sequelize = await connectDatabase(__DATABASE__)
14+
await defineStateChannelStoreModels(sequelize)
15+
await sequelize.sync()
16+
1417
if (
1518
!__INDRA__.ethereumProvider ||
1619
!__INDRA__.connextNode ||

0 commit comments

Comments
 (0)