refactor: update LNBits migration to use configuration object
- Replaced SQL statements with a configuration object for LNBits settings, enhancing code clarity and maintainability. - Simplified the migration process by utilizing the saveConfig function for applying configurations. - Marked the down migration as a no-op to prevent breaking existing configurations.
This commit is contained in:
parent
abe45c49f1
commit
0f64df1d69
1 changed files with 10 additions and 27 deletions
|
|
@ -1,34 +1,17 @@
|
||||||
const db = require('./db')
|
const { saveConfig } = require('../lib/new-settings-loader')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const config = {
|
||||||
`INSERT INTO user_config (name, display_name, type, data_type, config_type, enabled, secret, options)
|
'lnbits_endpoint': '',
|
||||||
VALUES
|
'lnbits_adminKey': '',
|
||||||
('lnbitsEndpoint', 'LNBits Server URL', 'text', 'string', 'wallets', false, false, null),
|
'LN_wallet': 'lnbits'
|
||||||
('lnbitsAdminKey', 'LNBits Admin Key', 'text', 'string', 'wallets', false, true, null)
|
}
|
||||||
ON CONFLICT (name) DO NOTHING`,
|
|
||||||
|
|
||||||
`INSERT INTO user_config (name, display_name, type, data_type, config_type, enabled, secret, options)
|
|
||||||
VALUES
|
|
||||||
('LN_wallet', 'Lightning Network Wallet', 'text', 'string', 'wallets', true, false,
|
|
||||||
'[{"code": "lnbits", "display": "LNBits"}, {"code": "galoy", "display": "Galoy (Blink)"}, {"code": "bitcoind", "display": "Bitcoin Core"}]')
|
|
||||||
ON CONFLICT (name)
|
|
||||||
DO UPDATE SET options = EXCLUDED.options
|
|
||||||
WHERE user_config.options NOT LIKE '%lnbits%'`
|
|
||||||
]
|
|
||||||
|
|
||||||
db.multi(sql, next)
|
saveConfig(config).then(next).catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.down = function (next) {
|
exports.down = function (next) {
|
||||||
const sql = [
|
// No-op - removing config entries is not typically done in down migrations
|
||||||
`DELETE FROM user_config
|
// as it could break existing configurations
|
||||||
WHERE name IN ('lnbitsEndpoint', 'lnbitsAdminKey')`,
|
next()
|
||||||
|
|
||||||
`UPDATE user_config
|
|
||||||
SET options = REPLACE(options, ', {"code": "lnbits", "display": "LNBits"}', '')
|
|
||||||
WHERE name = 'LN_wallet'`
|
|
||||||
]
|
|
||||||
|
|
||||||
db.multi(sql, next)
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue