Separate business-logic from data-layer logic in core-database/postgres#2055
Separate business-logic from data-layer logic in core-database/postgres#2055faustbrian merged 22 commits intoArkEcosystem:2.2from paroxysm:feat/refactor-core-database
Conversation
…s instead. Use type-casts to mask compile errors due accessing of private/internal details publicy.
…Then use said typed repos in methods
…r-core-database # Conflicts: # packages/core-transaction-pool/__tests__/connection.test.ts
…r-core-database # Conflicts: # packages/core-database-postgres/src/spv.ts
fix: missing crucial line of code in 'DatabaseService.getForgedTransactionIds'
|
@paroxysm Thanks for submitting this pull request, a maintainer will get back to you shortly! |
|
@faustbrian @supaiku0 @air1one - please review this in the next few days. Be sure to explicitly select labels so I know what's going on. If no reviewer appears after a week, a reminder will be sent out. |
|
@paroxysm Your pull request doesn't follow our contribution guidelines. Please review and correct it. |
| const manager = new SnapshotManager(options); | ||
|
|
||
| return manager.make(container.resolvePlugin<PostgresConnection>("database")); | ||
| const connection = container.resolvePlugin<Database.IDatabaseService>("database").connection as any; |
There was a problem hiding this comment.
This causes some resolution issues. Try yarn dump:testnet --config ../core/src/config/testnet through the CLI to reproduce it.
TypeError: Cannot read property 'connection' of null
at Object.register (./packages/core-snapshots/dist/plugin.js:15:63)
|
I'll take a look after work 👍🏿 I've introduced a factory function for instantiating the By using the factory function, the extenders only need to know of an Also, the factory function allows us to break-up parts of the |
…ng up w/o a db connection) refactor: export a database-service factory for instantiating it. This prevents db flavor implementors from overriding the business repos which have expected implementations already.
|
@paroxysm The ci/circleci: test-node11-0 job is failing as of 0a091e13265aa380307cf1176da82322828ed654. Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
@paroxysm Your pull request has been merged and marked as tier 0. It needs a specialized, in-depth review before we can decide on its value. |
|
@paroxysm do you want to take care of extracting the repositories out of core-api/graphql? |
|
Yea, I'll handle that |
…peer-state * ArkEcosystem/core/develop: refactor(core-database): separate business-logic from data-layer logic (#2055)
Proposed changes
Resolves #2006
The PR introduces a hierarchical change to the core-database/postgres.
I've encapsulated the business logic, previously in
ConnectionInterfaceandPostgresConnection, into a new classDatabaseService, implementsIDatabaseService, which references a database specific implementation of theIDatabaseConnectioninterface via constructor injection.IDatabaseConnectionsupplies the repos thatDatabaseServiceuses in certain methods.The plugin providing a
IDatabaseConnectionconcrete class is responsible for instantiating aDatabaseServiceand supply aIDatabaseConnectionconcrete class, among with other dependencies such asIWalletManagerIn theory, the plugin can also provide its own implementation of
IWalletManagerand such..The implication is that we're now exposing an
IDatabaseServiceimplementation to be used by the other modules. Most of these modules don't care about the underlying data-layer and shouldn't.The exception would be core-api/core-graphql/core-snapshots which are(oddly) defining repositories that are accessing postgres specific internals(I use 'any' type-casting to get past compilation errors but this tech-debt that should be addressed sooner than later). These external repos need to be relocated into
IDatabaseConnectionrepos and w/e additional logic they were doing be merged.It shouldn't be too hard to convert the search/query code these external repositories are using into a generic implementation on the database specific repos.
I've tested that my relay runs and syncs as usual. I haven't tested some other affected modules such as core-graphql/snapshot outside their tests
The next step would be to start improving the
DatabaseServicetests, now that we can stub easier.Types of changes
Checklist