Skip to content

Commit 05adb56

Browse files
authored
PostreSQL backend support (#62)
[GH-53] Changes: - Add the implementation of the Storage trait for a PostgreSQL DB backend using SQLx. - Add a script to start a development container with a PosgreSQL DB. - Add prepared SQL statements for the offline checks. - Add initial DB schema as a migration - Updated deps * Add unit tests for the PostgreSQL Storage implementation [GH-53] - Add a reusable module that generates Logs fixtures - Adds unit tests for all the methods of the trait Storage * Extend CI script to support the new DB backend (#53) * Otimised PosgreSQL backend to use batched inserts (#53) * Run tests for all features in the CI (#53) * Insert db version into the meta table (#53) * Make all DB backends available at runtime (#53) * Fix for test latest_block (#53) * Use BYTEA for all the addresses stored in the DB (#53) * Add docs for the new DB backend (#53) * Migrate the DB before running tests in CI * Use prepared SQL queries to build the container * Automatic detection of the chosen DB backend based on the connection path (#53) * Update DATABASE_URL for testing environment * Update docs after CLI change (#53) * Error when DB content is wrong (#62)
1 parent 904cbf6 commit 05adb56

30 files changed

+3072
-78
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Rust Main
33

44
env:
55
CARGO_TERM_COLOR: always
6+
SQLX_VERSION: 0.8.6
7+
SQLX_FEATURES: "postgres"
68

79
# Run for every event affecting the main branch
810
on:
@@ -46,7 +48,7 @@ jobs:
4648
with:
4749
components: rustfmt clippy
4850
- name: Build with all features
49-
run: cargo check --all-features --future-incompat-report
51+
run: SQLX_OFFLINE=true cargo check --all-features --future-incompat-report
5052

5153
clippy:
5254
name: Clippy linter
@@ -59,20 +61,45 @@ jobs:
5961
with:
6062
components: rustfmt clippy
6163
- name: Linting with all features
62-
run: cargo clippy --all-features --no-deps -- -D warnings
64+
run: SQLX_OFFLINE=true cargo clippy --all-features --no-deps -- -D warnings
6365

6466
# Comprehensive test with all features
6567
test:
6668
name: Test
6769
needs: clippy
6870
runs-on: ubuntu-latest
71+
services:
72+
postgres:
73+
image: postgres:16
74+
env:
75+
POSTGRES_USER: postgres
76+
POSTGRES_PASSWORD: password
77+
POSTGRES_DB: quixote_test
78+
ports:
79+
- 5432:5432
80+
options: >-
81+
--health-cmd "pg_isready -U postgres"
82+
--health-interval 10s
83+
--health-timeout 5s
84+
--health-retries 5
6985
steps:
7086
- uses: actions/checkout@v6
7187
- uses: Swatinem/rust-cache@v2.8.2
7288
- uses: dtolnay/rust-toolchain@stable
89+
- name: Install SQLx-cli
90+
run:
91+
cargo install sqlx-cli
92+
--version=${{ env.SQLX_VERSION }}
93+
--features ${{ env.SQLX_FEATURES }}
94+
--no-default-features
95+
--locked
96+
- name: Migrate database
97+
run: SKIP_DOCKER=true ./script/init_postgresql.bash
7398
- name: Tests
99+
env:
100+
DATABASE_URL: postgres://postgres:password@localhost:5432/quixote
74101
run: |
75102
QUIXOTE_TEST_RPC=${{ secrets.QUIXOTE_TEST_RPC }} \
76103
QUIXOTE_TEST_RPC_USER=${{ secrets.QUIXOTE_TEST_RPC_USER }} \
77104
QUIXOTE_TEST_RPC_PASSWORD=${{ secrets.QUIXOTE_TEST_RPC_PASSWORD }} \
78-
cargo test
105+
cargo test --all-features

.sqlx/query-05067f823b93f335e0e5ef3c953aab0f1e9925152a9dc50a1c05e4b35988a23e.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-08ac39283505d7f7e171c4fbb86c526ef7acb8d1e140f99aa93b8474cc29a788.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-0c4d6dd0b6edea647a14a51d8e0697f908e8c9c5c6b76eb80653bf89396af9b8.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-3b1ea7fbd407ed5d116d40564bc1b964022082c63ceb3cd7d124f274e3bc611f.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-4cf740feceecaaa2bb1d60bfbdb11f6f2e61a9d4f120eed499c0bb20476d3e6e.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-4f91e0356313ac039cae996d75d76aa7a3c1dabf7867349adaf2cc270b1dec62.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-57b479c3ad6267dc15bac5e760af30b793646d2404ee7f6b4b5a20ec7a95450f.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-8ebcbc60059f25a3cec80b0356718f9500c7a7008dbdd40e7be8a33336fa58f1.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-b0922a34af154812b051b863677d1488b3415c365e6b9cf96b5c4eadf0d8d87d.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)