Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# --- Local Development (Docker MSSQL) ---
# --- Local Development (Docker PostgreSQL) ---
# Copy this file to .env and fill in the values
# Start MSSQL: docker compose up -d
# Create DB once: docker exec lds-mssql /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "YourStrong!Passw0rd" -C -Q "CREATE DATABASE LightningSpace"
# For local dev, only the settings below are required:
# Start PostgreSQL: docker compose up -d
ENVIRONMENT=loc
PORT=3000
SQL_HOST=localhost
SQL_PORT=1433
SQL_USERNAME=sa
SQL_PORT=5432
SQL_USERNAME=postgres
SQL_PASSWORD=YourStrong!Passw0rd
SQL_DB=LightningSpace
SQL_SYNCHRONIZE=true
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Access requires a wallet with the `DEBUG` role. The role hierarchy allows `ADMIN
name = 'addDebugWalletTIMESTAMP'

async up(queryRunner) {
await queryRunner.query(`UPDATE wallet SET role = 'Debug', updated = GETDATE() WHERE address = 'WALLET_ADDRESS'`);
await queryRunner.query(`UPDATE wallet SET role = 'Debug', updated = CURRENT_TIMESTAMP WHERE address = 'WALLET_ADDRESS'`);
}

async down(queryRunner) {
await queryRunner.query(`UPDATE wallet SET role = 'User', updated = GETDATE() WHERE address = 'WALLET_ADDRESS'`);
await queryRunner.query(`UPDATE wallet SET role = 'User', updated = CURRENT_TIMESTAMP WHERE address = 'WALLET_ADDRESS'`);
}
}
```
Expand All @@ -64,7 +64,7 @@ Access requires a wallet with the `DEBUG` role. The role hierarchy allows `ADMIN

**SQL Queries:**
```bash
./scripts/db-debug.sh "SELECT TOP 10 * FROM wallet"
./scripts/db-debug.sh "SELECT * FROM wallet LIMIT 10"
./scripts/db-debug.sh "SELECT * FROM monitoring_balance"
```

Expand All @@ -81,5 +81,5 @@ Access requires a wallet with the `DEBUG` role. The role hierarchy allows `ADMIN

- Only `SELECT` queries allowed (no INSERT, UPDATE, DELETE)
- Sensitive columns are automatically masked (signatures, keys, secrets)
- System schemas blocked (sys, information_schema)
- System schemas blocked (pg_catalog, information_schema)
- All queries are logged for audit
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: lds-mssql
postgres:
image: postgres:17-alpine
container_name: lds-postgres
environment:
ACCEPT_EULA: 'Y'
MSSQL_SA_PASSWORD: 'YourStrong!Passw0rd'
MSSQL_PID: Developer
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 'YourStrong!Passw0rd'
POSTGRES_DB: LightningSpace
ports:
- '1433:1433'
- '5432:5432'
volumes:
- mssql-data:/var/opt/mssql
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "YourStrong!Passw0rd" -C -Q "SELECT 1" -b -o /dev/null
test: ['CMD-SHELL', 'pg_isready -U postgres']
interval: 10s
timeout: 3s
retries: 10
start_period: 10s

volumes:
mssql-data:
postgres-data:
8 changes: 4 additions & 4 deletions migration/1693381371362-Initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ module.exports = class Initial1693381371362 {

async up(queryRunner) {
await queryRunner.query(
`CREATE TABLE "user" ("id" int NOT NULL IDENTITY(1,1), "created" datetime2 NOT NULL CONSTRAINT "DF_8ce4c93ba419b56bd82e533724d" DEFAULT getdate(), "updated" datetime2 NOT NULL CONSTRAINT "DF_5904a9d40152f354e4c7b0202fb" DEFAULT getdate(), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`,
`CREATE TABLE "user" ("id" SERIAL NOT NULL, "created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "wallet_provider" ("id" int NOT NULL IDENTITY(1,1), "created" datetime2 NOT NULL CONSTRAINT "DF_84c9dbd2dd0e662567cb7316479" DEFAULT getdate(), "updated" datetime2 NOT NULL CONSTRAINT "DF_8cb5099f91fbd28ae877b04aa74" DEFAULT getdate(), "name" nvarchar(255) NOT NULL, CONSTRAINT "UQ_1e7a695e2f2ea4ca54df5f0fc72" UNIQUE ("name"), CONSTRAINT "PK_5c7933595d00e530f9d0eecca81" PRIMARY KEY ("id"))`,
`CREATE TABLE "wallet_provider" ("id" SERIAL NOT NULL, "created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "name" varchar(255) NOT NULL, CONSTRAINT "UQ_1e7a695e2f2ea4ca54df5f0fc72" UNIQUE ("name"), CONSTRAINT "PK_5c7933595d00e530f9d0eecca81" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "wallet" ("id" int NOT NULL IDENTITY(1,1), "created" datetime2 NOT NULL CONSTRAINT "DF_2f026f6cfde1264d133a9da4a40" DEFAULT getdate(), "updated" datetime2 NOT NULL CONSTRAINT "DF_fb09ba370efe59a077ccb666826" DEFAULT getdate(), "address" nvarchar(255) NOT NULL, "signature" nvarchar(255) NOT NULL, "lnbitsUserId" nvarchar(255) NOT NULL, "lnbitsAddress" nvarchar(255) NOT NULL, "role" nvarchar(255) NOT NULL CONSTRAINT "DF_39dba1739ead1346b5eef893188" DEFAULT 'User', "walletProviderId" int NOT NULL, "userId" int NOT NULL, CONSTRAINT "UQ_1dcc9f5fd49e3dc52c6d2393c53" UNIQUE ("address"), CONSTRAINT "UQ_55b77268e1ab3d6caba35c2e1f7" UNIQUE ("lnbitsUserId"), CONSTRAINT "UQ_a380084e2f3e0213d45ce414129" UNIQUE ("lnbitsAddress"), CONSTRAINT "PK_bec464dd8d54c39c54fd32e2334" PRIMARY KEY ("id"))`,
`CREATE TABLE "wallet" ("id" SERIAL NOT NULL, "created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "address" varchar(255) NOT NULL, "signature" varchar(255) NOT NULL, "lnbitsUserId" varchar(255) NOT NULL, "lnbitsAddress" varchar(255) NOT NULL, "role" varchar(255) NOT NULL DEFAULT 'User', "walletProviderId" int NOT NULL, "userId" int NOT NULL, CONSTRAINT "UQ_1dcc9f5fd49e3dc52c6d2393c53" UNIQUE ("address"), CONSTRAINT "UQ_55b77268e1ab3d6caba35c2e1f7" UNIQUE ("lnbitsUserId"), CONSTRAINT "UQ_a380084e2f3e0213d45ce414129" UNIQUE ("lnbitsAddress"), CONSTRAINT "PK_bec464dd8d54c39c54fd32e2334" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "lightning_wallet" ("id" int NOT NULL IDENTITY(1,1), "created" datetime2 NOT NULL CONSTRAINT "DF_2a2a8f12dffb71a971554a4e5da" DEFAULT getdate(), "updated" datetime2 NOT NULL CONSTRAINT "DF_433f721ae8922b747c42ca5d6f5" DEFAULT getdate(), "lnbitsWalletId" nvarchar(255) NOT NULL, "asset" nvarchar(255) NOT NULL, "adminKey" nvarchar(255) NOT NULL, "invoiceKey" nvarchar(255) NOT NULL, "lnurlpId" nvarchar(255) NOT NULL, "walletId" int NOT NULL, CONSTRAINT "UQ_60f18254b76b69d24553d8c0562" UNIQUE ("lnbitsWalletId"), CONSTRAINT "PK_ea0c4797a4f0f6d0b9979e8a432" PRIMARY KEY ("id"))`,
`CREATE TABLE "lightning_wallet" ("id" SERIAL NOT NULL, "created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "lnbitsWalletId" varchar(255) NOT NULL, "asset" varchar(255) NOT NULL, "adminKey" varchar(255) NOT NULL, "invoiceKey" varchar(255) NOT NULL, "lnurlpId" varchar(255) NOT NULL, "walletId" int NOT NULL, CONSTRAINT "UQ_60f18254b76b69d24553d8c0562" UNIQUE ("lnbitsWalletId"), CONSTRAINT "PK_ea0c4797a4f0f6d0b9979e8a432" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "wallet" ADD CONSTRAINT "FK_5f9d93bd5c22ed5b4211b26718a" FOREIGN KEY ("walletProviderId") REFERENCES "wallet_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
Expand Down
28 changes: 14 additions & 14 deletions migration/1693922883477-addAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ module.exports = class addAsset1693922883477 {
name = 'addAsset1693922883477'

async up(queryRunner) {
await queryRunner.query(`EXEC sp_rename "lightning_wallet.asset", "assetId"`);
await queryRunner.query(`CREATE TABLE "dbo"."asset" ("id" int NOT NULL IDENTITY(1,1), "created" datetime2 NOT NULL CONSTRAINT "DF_3ee68e53a3e33a8df283f66aada" DEFAULT getdate(), "updated" datetime2 NOT NULL CONSTRAINT "DF_6ed5cbbccf21b8ef558f7ef2de5" DEFAULT getdate(), "name" nvarchar(255) NOT NULL, "displayName" nvarchar(255) NOT NULL, "description" nvarchar(255), "status" nvarchar(255) NOT NULL, CONSTRAINT "UQ_119b2d1c1bdccc42057c303c44f" UNIQUE ("name"), CONSTRAINT "PK_1209d107fe21482beaea51b745e" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "dbo"."wallet" ADD "addressOwnershipProof" nvarchar(255) NOT NULL`);
await queryRunner.query(`ALTER TABLE "dbo"."wallet" ADD CONSTRAINT "UQ_e27ddf84aefa72d600acbf393c5" UNIQUE ("addressOwnershipProof")`);
await queryRunner.query(`ALTER TABLE "dbo"."lightning_wallet" DROP COLUMN "assetId"`);
await queryRunner.query(`ALTER TABLE "dbo"."lightning_wallet" ADD "assetId" int NOT NULL`);
await queryRunner.query(`ALTER TABLE "dbo"."lightning_wallet" ADD CONSTRAINT "FK_37f046b3cbbb273f24a4badd1f7" FOREIGN KEY ("assetId") REFERENCES "dbo"."asset"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" RENAME COLUMN "asset" TO "assetId"`);
await queryRunner.query(`CREATE TABLE "asset" ("id" SERIAL NOT NULL, "created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "name" varchar(255) NOT NULL, "displayName" varchar(255) NOT NULL, "description" varchar(255), "status" varchar(255) NOT NULL, CONSTRAINT "UQ_119b2d1c1bdccc42057c303c44f" UNIQUE ("name"), CONSTRAINT "PK_1209d107fe21482beaea51b745e" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "wallet" ADD "addressOwnershipProof" varchar(255) NOT NULL`);
await queryRunner.query(`ALTER TABLE "wallet" ADD CONSTRAINT "UQ_e27ddf84aefa72d600acbf393c5" UNIQUE ("addressOwnershipProof")`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" DROP COLUMN "assetId"`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" ADD "assetId" int NOT NULL`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" ADD CONSTRAINT "FK_37f046b3cbbb273f24a4badd1f7" FOREIGN KEY ("assetId") REFERENCES "asset"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "dbo"."lightning_wallet" DROP CONSTRAINT "FK_37f046b3cbbb273f24a4badd1f7"`);
await queryRunner.query(`ALTER TABLE "dbo"."lightning_wallet" DROP COLUMN "assetId"`);
await queryRunner.query(`ALTER TABLE "dbo"."lightning_wallet" ADD "assetId" nvarchar(255) NOT NULL`);
await queryRunner.query(`ALTER TABLE "dbo"."wallet" DROP CONSTRAINT "UQ_e27ddf84aefa72d600acbf393c5"`);
await queryRunner.query(`ALTER TABLE "dbo"."wallet" DROP COLUMN "addressOwnershipProof"`);
await queryRunner.query(`DROP TABLE "dbo"."asset"`);
await queryRunner.query(`EXEC sp_rename "lightning_wallet.assetId", "asset"`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" DROP CONSTRAINT "FK_37f046b3cbbb273f24a4badd1f7"`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" DROP COLUMN "assetId"`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" ADD "assetId" varchar(255) NOT NULL`);
await queryRunner.query(`ALTER TABLE "wallet" DROP CONSTRAINT "UQ_e27ddf84aefa72d600acbf393c5"`);
await queryRunner.query(`ALTER TABLE "wallet" DROP COLUMN "addressOwnershipProof"`);
await queryRunner.query(`DROP TABLE "asset"`);
await queryRunner.query(`ALTER TABLE "lightning_wallet" RENAME COLUMN "assetId" TO "asset"`);
}
}
11 changes: 5 additions & 6 deletions migration/1697006086810-Transactions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading