mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-07-31 15:56:14 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2268c3a962 |
@@ -0,0 +1,35 @@
|
||||
"""repair refund sweep claim lease
|
||||
|
||||
Revision ID: b7c9d1e3f5a2
|
||||
Revises: aa50fde387a2
|
||||
Create Date: 2026-07-30 03:10:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "b7c9d1e3f5a2"
|
||||
down_revision = "aa50fde387a2"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
columns = {
|
||||
column["name"]
|
||||
for column in sa.inspect(conn).get_columns("cashu_transactions")
|
||||
}
|
||||
if "sweep_started_at" not in columns:
|
||||
op.add_column(
|
||||
"cashu_transactions",
|
||||
sa.Column("sweep_started_at", sa.Integer(), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Revision aa50fde387a2 owns this column, so downgrading only the repair
|
||||
# migration must preserve the schema expected at that revision.
|
||||
pass
|
||||
@@ -37,7 +37,7 @@ def test_fresh_node_migrates_fee_payout_schema_to_head(tmp_path: Path) -> None:
|
||||
"payout_in_progress_msats, payout_started_at FROM routstr_fees"
|
||||
).fetchone()
|
||||
|
||||
assert version == ("aa50fde387a2",)
|
||||
assert version == ("b7c9d1e3f5a2",)
|
||||
assert {
|
||||
"id",
|
||||
"accumulated_msats",
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _run_alembic(root: Path, database_url: str, *args: str) -> None:
|
||||
env = os.environ.copy()
|
||||
env["DATABASE_URL"] = database_url
|
||||
subprocess.run(
|
||||
[sys.executable, "-m", "alembic", *args],
|
||||
cwd=root,
|
||||
env=env,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def test_refund_sweep_repair_restores_column_missing_at_stamped_head(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
database_path = tmp_path / "missing-refund-sweep-claim.db"
|
||||
database_url = f"sqlite+aiosqlite:///{database_path}"
|
||||
|
||||
_run_alembic(root, database_url, "upgrade", "9c4d8e2f1a6b")
|
||||
_run_alembic(root, database_url, "stamp", "aa50fde387a2")
|
||||
|
||||
with sqlite3.connect(database_path) as connection:
|
||||
columns_before_repair = {
|
||||
row[1]
|
||||
for row in connection.execute("PRAGMA table_info(cashu_transactions)")
|
||||
}
|
||||
assert "sweep_started_at" not in columns_before_repair
|
||||
|
||||
_run_alembic(root, database_url, "upgrade", "head")
|
||||
|
||||
with sqlite3.connect(database_path) as connection:
|
||||
version = connection.execute(
|
||||
"SELECT version_num FROM alembic_version"
|
||||
).fetchone()
|
||||
columns_after_repair = {
|
||||
row[1]
|
||||
for row in connection.execute("PRAGMA table_info(cashu_transactions)")
|
||||
}
|
||||
|
||||
assert version == ("b7c9d1e3f5a2",)
|
||||
assert "sweep_started_at" in columns_after_repair
|
||||
Reference in New Issue
Block a user