Issue:
refactor(storage): Add a separate crate to represent store implementations

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement
- [x] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
- Adding a crate to split out implementation concerns for database

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless its an obvious bug or documentation fix
that will have little conversation).
-->
- Splitting out storage implementation concerns would lead to somewhat abstracted code
- Faster compilation/ analyzer since diesel dependencies are no longer needed each time
- Ability to rely on multiple storage implementations

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
- running it locally, Although it does not need much testing beyond compilation

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [ ] I formatted the code `cargo +nightly fmt --all`
- [ ] I addressed lints thrown by `cargo clippy`
- [ ] I reviewed submitted code
- [ ] I added unit tests for my changes where possible
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable


Resolution:
<think>
PR Context:
- Title: refactor(storage_impl): Integrate the composite store from external crate
- Merged: 2023-08-14T13:24:42Z
- Files changed: 30 files
- Commits: 30 commits

Implementation approach:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [x] Enhancement
- [x] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
- move `RedisConnInterface` to storage impl
- move 'PubSubInterface` to storage impl
- move 'KvStorePartition` impls to storage impl as the cases are gonna be used there as well
- use the above interfaces throughout router crate & add imple
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** refactor(storage_impl): Integrate the composite store from external crate (#1921)
Files to modify:


**crates/cards/src/lib.rs**
  Modify existing code

**crates/router/src/connection.rs**
  Modify existing code

**crates/router/src/connector/cashtocode.rs**
  Modify existing code

**crates/router/src/connector/tsys.rs**
  Modify existing code

**crates/router/src/core/cache.rs**
  Modify existing code

**crates/router/src/core/files/helpers.rs**
  Modify existing code

**crates/router/src/core/payment_methods/vault.rs**
  Modify existing code

**crates/router/src/core/payouts.rs**
  Modify existing code

**crates/router/src/core/payouts/validator.rs**
  Modify existing code

**crates/router/src/db.rs**
  Add:
    - impl: impl RedisConnInterface for MockDb

**crates/router/src/db/api_keys.rs**
  Modify existing code

**crates/router/src/db/cache.rs**
  Modify existing code

**crates/router/src/db/configs.rs**
  Modify existing code

**crates/router/src/db/ephemeral_key.rs**
  Modify existing code

**crates/router/src/db/merchant_account.rs**
  Modify existing code

**crates/router/src/db/merchant_connector_account.rs**
  Modify existing code

**crates/router/src/db/merchant_key_store.rs**
  Modify existing code

**crates/router/src/db/payment_attempt.rs**
  Modify existing code

**crates/router/src/db/payment_intent.rs**
  Modify existing code

**crates/router/src/db/queue.rs**
  Modify existing code

**crates/router/src/db/refund.rs**
  Modify existing code

**crates/router/src/lib.rs**
  Remove:
    - mod: pub::cache

**crates/router/src/routes/app.rs**
  Modify existing code

**crates/router/src/services.rs**
  Remove:
    - function: private::subscribe
    - function: private::publish
    - function: private::on_message
    - function: private::get_redis_conn
    - function: pub::new
    - function: pub::get_drainer_stream_name
    - function: pub::redis_conn
    - function: pub::push_to_drainer_stream
    - struct: pub::Store
    - struct: pub::StoreConfig
    - trait: pub::PubSubInterface
    - trait: pub::RedisConnInterface
    - impl: impl PubSubInterface for redis_interface::RedisConnectionPool
    - impl: impl RedisConnInterface for Store

**crates/router/src/types/storage/payment_attempt.rs**
  Remove:
    - impl: impl crate::utils::storage_partitioning::KvStorePartition for PaymentAttempt

**crates/router/src/types/storage/payment_intent.rs**
  Remove:
    - impl: impl crate::utils::storage_partitioning::KvStorePartition for PaymentIntent

**crates/router/src/types/storage/refund.rs**
  Remove:
    - impl: impl crate::utils::storage_partitioning::KvStorePartition for Refund

**crates/router/src/utils/storage_partitioning.rs**
  Remove:
    - function: private::partition_number
    - function: private::shard_key
    - function: private::fmt
    - enum: pub::PartitionKey
    - trait: pub::KvStorePartition
    - impl: impl std::fmt::Display for PartitionKey<'a>

**crates/router/tests/cache.rs**
  Modify existing code

**crates/router/tests/connectors/payeezy.rs**
  Modify existing code

**crates/router_derive/src/macros/diesel.rs**
  Modify existing code

**crates/storage_impl/src/lib.rs**
  Remove:
    - mod: pub::diesel
  Add:
    - function: private::new
    - function: private::get_master_pool
    - function: private::get_replica_pool
    - function: private::get_redis_conn
    - function: pub::from_config
    - function: private::new
    - function: private::get_master_pool
    - function: private::get_replica_pool
    - function: private::get_redis_conn
    - function: pub::master_key
    - impl: impl DatabaseStore for RouterStore<T>
    - impl: impl RedisConnInterface for RouterStore<T>
    - impl: impl DatabaseStore for KVRouterStore<T>
    - impl: impl RedisConnInterface for KVRouterStore<T>
    - mod: pub::database
    - mod: pub::payments
    - mod: pub::refund

**crates/storage_impl/src/payments.rs**
  Add:
    - impl: impl KvStorePartition for PaymentIntent
    - impl: impl KvStorePartition for PaymentAttempt

**crates/storage_impl/src/redis.rs**
  Add:
    - struct: pub::RedisStore
    - mod: pub::cache
    - mod: pub::pub_sub

**crates/storage_impl/src/redis/kv_store.rs**
  Add:
    - enum: pub::PartitionKey
    - trait: pub::KvStorePartition

**crates/storage_impl/src/redis/pub_sub.rs**
  Add:
    - function: private::subscribe
    - function: private::publish
    - function: private::on_message
    - trait: pub::PubSubInterface
    - impl: impl PubSubInterface for redis_interface::RedisConnectionPool

**crates/storage_impl/src/refund.rs**
  Add:
    - impl: impl KvStorePartition for Refund