Rename Castle Accounting extension to Libra

Full identifier rename: module path lnbits.extensions.castle →
lnbits.extensions.libra, DB ext_castle → ext_libra, URL prefix
/castle/ → /libra/, manifest id castle → libra, fava ledger slug
default castle-ledger → libra-ledger, Beancount source metadata
castle-api → libra-api and link prefixes castle-{entry,tx}- →
libra-{entry,tx}-, column castle_wallet_id → libra_wallet_id, all
Python/JS/HTML identifiers (castle_ext, CastleSettings,
castle_reference, castleWalletConfigured, etc.).

Display name "Castle Accounting" → "Libra" (the scales/balance
metaphor — fits double-entry bookkeeping).

No backward compat: production hosts will be force-updated. Old
castle-prefixed Beancount metadata in existing Fava ledgers is
historical; new entries use libra-* prefixes going forward.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Padreug 2026-05-05 10:24:46 +02:00
commit c174cda48d
44 changed files with 953 additions and 953 deletions

View file

@ -5,24 +5,24 @@ from loguru import logger
from .crud import db
from .tasks import wait_for_paid_invoices
from .views import castle_generic_router
from .views_api import castle_api_router
from .views import libra_generic_router
from .views_api import libra_api_router
castle_ext: APIRouter = APIRouter(prefix="/castle", tags=["Castle"])
castle_ext.include_router(castle_generic_router)
castle_ext.include_router(castle_api_router)
libra_ext: APIRouter = APIRouter(prefix="/libra", tags=["Libra"])
libra_ext.include_router(libra_generic_router)
libra_ext.include_router(libra_api_router)
castle_static_files = [
libra_static_files = [
{
"path": "/castle/static",
"name": "castle_static",
"path": "/libra/static",
"name": "libra_static",
}
]
scheduled_tasks: list[asyncio.Task] = []
def castle_stop():
def libra_stop():
"""Clean up background tasks on extension shutdown"""
for task in scheduled_tasks:
try:
@ -31,32 +31,32 @@ def castle_stop():
logger.warning(ex)
def castle_start():
"""Initialize Castle extension background tasks"""
def libra_start():
"""Initialize Libra extension background tasks"""
from lnbits.tasks import create_permanent_unique_task
from .fava_client import init_fava_client
from .models import CastleSettings
from .models import LibraSettings
from .tasks import wait_for_account_sync
async def _init_fava():
"""Load saved settings from DB, fall back to defaults."""
from .crud import db as castle_db
from .crud import db as libra_db
settings = None
try:
row = await castle_db.fetchone(
row = await libra_db.fetchone(
"SELECT * FROM extension_settings LIMIT 1",
model=CastleSettings,
model=LibraSettings,
)
if row:
settings = row
logger.info(f"Loaded Castle settings from DB: {settings.fava_url}/{settings.fava_ledger_slug}")
logger.info(f"Loaded Libra settings from DB: {settings.fava_url}/{settings.fava_ledger_slug}")
except Exception as e:
logger.warning(f"Could not load settings from DB: {e}")
if not settings:
settings = CastleSettings()
logger.info(f"Using default Castle settings: {settings.fava_url}/{settings.fava_ledger_slug}")
settings = LibraSettings()
logger.info(f"Using default Libra settings: {settings.fava_url}/{settings.fava_ledger_slug}")
init_fava_client(
fava_url=settings.fava_url,
@ -69,16 +69,16 @@ def castle_start():
asyncio.get_event_loop().create_task(_init_fava())
except Exception as e:
logger.error(f"Failed to initialize Fava client: {e}")
logger.warning("Castle will not function without Fava. Please configure Fava settings.")
logger.warning("Libra will not function without Fava. Please configure Fava settings.")
# Start background tasks
task = create_permanent_unique_task("ext_castle", wait_for_paid_invoices)
task = create_permanent_unique_task("ext_libra", wait_for_paid_invoices)
scheduled_tasks.append(task)
# Start account sync task (runs hourly)
sync_task = create_permanent_unique_task("ext_castle_account_sync", wait_for_account_sync)
sync_task = create_permanent_unique_task("ext_libra_account_sync", wait_for_account_sync)
scheduled_tasks.append(sync_task)
logger.info("Castle account sync task started (runs hourly)")
logger.info("Libra account sync task started (runs hourly)")
__all__ = ["castle_ext", "castle_static_files", "db", "castle_start", "castle_stop"]
__all__ = ["libra_ext", "libra_static_files", "db", "libra_start", "libra_stop"]