Skip to content

Add SQLite support for local development#79

Closed
TaprootFreak wants to merge 8 commits into
developfrom
feature/local-sqlite-db
Closed

Add SQLite support for local development#79
TaprootFreak wants to merge 8 commits into
developfrom
feature/local-sqlite-db

Conversation

@TaprootFreak

@TaprootFreak TaprootFreak commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR adds SQLite database support for local development while maintaining MSSQL for dev/prod environments.

Changes

  • Database Configuration: Environment-based database selection

    • ENVIRONMENT=loc → SQLite (local development)
    • ENVIRONMENT=dev|prd → MSSQL (existing production setup)
  • Dependencies: Added sqlite3 package as devDependency (not installed in production)

  • Entity Updates: Updated column type definitions for cross-database compatibility

    • length: 'MAX' / nvarchar(max)type: 'text' for SQLite compatibility
    • datetime2datetime for SQLite compatibility
    • type: 'float' for decimal numbers
    • No impact on prd: SQL_SYNCHRONIZE=false prevents schema changes, runtime queries are unaffected
  • Graceful degradation for local environment (all guarded by Environment.LOC):

    • Lightning WebSocket connections skipped
    • Alchemy webhook initialization skipped
    • EVM payment webhook setup skipped
    • CitreaClient wallet creation skipped
    • In dev/prd, missing config still fails loudly at startup (no silent failures)
  • Gitignore: Added testDB/ and SQLite database files

Local Development Setup

# 1. Create .env in api root
ENVIRONMENT=loc
PORT=3000
SQL_DB=testDB/lightning_space.db
SQL_SYNCHRONIZE=true
SQL_MIGRATE=false
JWT_SECRET=<any-string>
DISABLED_PROCESSES=*

# 2. Install, build & start
npm install && npm run build && npm run start

API available at http://localhost:3000/v1, Swagger at http://localhost:3000/swagger.

Production Safety

  • All local-only code paths are explicitly guarded by Environment.LOC checks
  • MSSQL database config block is completely unchanged for dev/prd
  • Entity column type changes only affect DDL (not runtime queries), and SQL_SYNCHRONIZE=false in prd prevents any schema modifications
  • sqlite3 is a devDependency — not installed in production builds
  • No business logic changes

Testing

  • Lint, build and all tests pass
  • Local development tested with SQLite
  • Existing dev/prd environments remain unchanged

Breaking Changes

None. Backward compatible, only affects local development when ENVIRONMENT=loc.

- Add sqlite3 dependency
- Configure environment-based database selection (SQLite for local, MSSQL for dev/prod)
- Update entity column types for SQLite compatibility
- Add testDB directory to gitignore
@TaprootFreak

Copy link
Copy Markdown
Contributor Author

Do not use Squash

- Skip Lightning WebSocket connections in loc environment
- Replace MSSQL-specific length:'MAX' with type:'text' for SQLite compat
- Skip Alchemy webhook init when auth token is not configured
- Skip EVM payment webhook setup when network is not configured
…te-db

# Conflicts:
#	package-lock.json
#	package.json
- Skip CitreaClient wallet creation when EVM_WALLET_SEED is not set
- Replace nvarchar(max) with text type in MonitoringEvmBalanceEntity
Use explicit environment check instead of missing config values
to ensure misconfigurations in dev/prd fail loudly at startup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant