Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add database setup #74

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile.test_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM postgres
ENV POSTGRES_PASSWORD=postgres
ENV POSTGRES_DB=mainnet
COPY ./database/01_table_creation.sql /docker-entrypoint-initdb.d/
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DOCKER_IMAGE_NAME=test_db_image
DOCKER_CONTAINER_NAME=test_db_container
DB_PORT=5432

install:
pip install -r requirements.txt

imbalances:
python -m src.imbalances_script

daemon:
python -m src.daemon

test_db:
docker build -t $(DOCKER_IMAGE_NAME) -f Dockerfile.test_db .
docker run -d --name $(DOCKER_CONTAINER_NAME) -p $(DB_PORT):$(DB_PORT) $(DOCKER_IMAGE_NAME)

stop_test_db:
docker stop $(DOCKER_CONTAINER_NAME) || true
docker rm $(DOCKER_CONTAINER_NAME) || true
docker rmi $(DOCKER_IMAGE_NAME) || true

.PHONY: install imbalances daemon test_db run_test_db stop_test_db clean
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ python -m src.imbalances_script
python -m src.daemon
```

**To run the basic test in the `tests/` folder:**
using pytest, simply run the command: `pytest`
## Tests

To build and start a local database for testing use the command
```sh
docker build -t test_db_image -f Dockerfile.test_db .
docker run -d --name test_db_container -p 5432:5432 test_db_image
```
27 changes: 27 additions & 0 deletions database/01_table_creation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE transaction_timestamps (
tx_hash bytea PRIMARY KEY,
time timestamp NOT NULL
);

CREATE TABLE transaction_tokens (
tx_hash bytea NOT NULL,
token_address bytea NOT NULL,

PRIMARY KEY (tx_hash, token_address)
);

CREATE TYPE PriceSource AS ENUM ('coingecko', 'moralis', 'dune', 'native');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fhenneke Do you know if this is easy to change, in case we end up using some other price feeds as well?


CREATE TABLE prices (
token_address bytea NOT NULL,
time timestamp NOT NULL,
price numeric(60, 18) NOT NULL,
source PriceSource NOT NULL,

PRIMARY KEY (token_address, time, source)
);

CREATE TABLE token_decimals (
token_address bytea PRIMARY KEY,
decimals int NOT NULL
);
Loading