Postgres migrations: remove balance view before children (#353)

* remove balance view before childredn

* update readme

* CI with postgres

* install postgres in CI

* run postgres tests in CI?

* disable postgres tests for now
This commit is contained in:
callebtc
2023-11-01 20:55:52 -03:00
committed by GitHub
parent aa36651629
commit a4abbc2eee
4 changed files with 36 additions and 10 deletions

View File

@@ -5,11 +5,27 @@ on: [push, pull_request]
jobs: jobs:
poetry: poetry:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: cashu
POSTGRES_PASSWORD: cashu
POSTGRES_DB: cashu
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest]
python-version: ["3.10.4"] python-version: ["3.10.4"]
poetry-version: ["1.5.1"] poetry-version: ["1.5.1"]
# db-url: ["", "postgres://cashu:cashu@localhost:5432/test"] # TODO: Postgres test not working
db-url: [""]
steps: steps:
- name: Checkout repository and submodules - name: Checkout repository and submodules
uses: actions/checkout@v2 uses: actions/checkout@v2
@@ -26,7 +42,7 @@ jobs:
cache: "poetry" cache: "poetry"
- name: Install dependencies - name: Install dependencies
run: | run: |
poetry install poetry install --extras pgsql
shell: bash shell: bash
- name: Run tests - name: Run tests
env: env:
@@ -34,6 +50,7 @@ jobs:
WALLET_NAME: test_wallet WALLET_NAME: test_wallet
MINT_HOST: localhost MINT_HOST: localhost
MINT_PORT: 3337 MINT_PORT: 3337
MINT_DATABASE: ${{ inputs.db-url }}
TOR: false TOR: false
run: | run: |
make test make test

View File

@@ -76,18 +76,20 @@ source ~/.bashrc
#### Poetry: Install Cashu #### Poetry: Install Cashu
```bash ```bash
# install cashu # install cashu
git clone https://github.com/callebtc/cashu.git git clone https://github.com/cashubtc/nutshell.git cashu
cd cashu cd cashu
pyenv local 3.10.4 pyenv local 3.10.4
poetry install poetry install
``` ```
If you would like to use PostgreSQL as the mint database, use the command `poetry install --extras pgsql`.
#### Poetry: Update Cashu #### Poetry: Update Cashu
To update Cashu to the newest version enter To update Cashu to the newest version enter
```bash ```bash
git pull && poetry install git pull && poetry install
``` ```
#### Poetry: Using Cashu #### Poetry: Using the Nutshell wallet
Cashu should be now installed. To execute the following commands, activate your virtual Poetry environment via Cashu should be now installed. To execute the following commands, activate your virtual Poetry environment via
@@ -183,11 +185,13 @@ You can find the API docs at [http://localhost:4448/docs](http://localhost:4448/
# Running a mint # Running a mint
This command runs the mint on your local computer. Skip this step if you want to use the [public test mint](#test-instance) instead. This command runs the mint on your local computer. Skip this step if you want to use the [public test mint](#test-instance) instead.
Before you can run your own mint, make sure to enable a Lightning backend in `MINT_LIGHTNING_BACKEND` and set `MINT_PRIVATE_KEY` in your `.env` file.
```bash ```bash
python -m cashu.mint poetry run mint
``` ```
You can turn off Lightning support and mint as many tokens as you like by setting `LIGHTNING=FALSE` in the `.env` file. For testing, you can use Nutshell without a Lightning backend by setting `MINT_LIGHTNING_BACKEND=FakeWallet` in the `.env` file.
# Running tests # Running tests

View File

@@ -183,9 +183,9 @@ async def m009_add_out_to_invoices(db: Database):
# column in invoices for marking whether the invoice is incoming (out=False) or outgoing (out=True) # column in invoices for marking whether the invoice is incoming (out=False) or outgoing (out=True)
async with db.connect() as conn: async with db.connect() as conn:
# we have to drop the balance views first and recreate them later # we have to drop the balance views first and recreate them later
await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance')}")
await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_issued')}") await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_issued')}")
await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_redeemed')}") await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_redeemed')}")
await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance')}")
# rename column pr to bolt11 # rename column pr to bolt11
await conn.execute( await conn.execute(

View File

@@ -57,11 +57,16 @@ async def ledger():
await ledger.load_used_proofs() await ledger.load_used_proofs()
await ledger.init_keysets() await ledger.init_keysets()
db_file = "test_data/mint/test.sqlite3" database_name = "test"
if not settings.mint_database.startswith("postgres"):
# clear sqlite database
db_file = os.path.join(settings.mint_database, database_name + ".sqlite3")
if os.path.exists(db_file): if os.path.exists(db_file):
os.remove(db_file) os.remove(db_file)
ledger = Ledger( ledger = Ledger(
db=Database("test", "test_data/mint"), db=Database(database_name, settings.mint_database),
seed=settings.mint_private_key, seed=settings.mint_private_key,
derivation_path=settings.mint_derivation_path, derivation_path=settings.mint_derivation_path,
lightning=FakeWallet(), lightning=FakeWallet(),