Skip to content

Commit 724a26b

Browse files
authored
Merge pull request #21 from lightninglabs/migrate-db
multi: add migrate-db command
2 parents a0b6e04 + d18f5d3 commit 724a26b

31 files changed

+3318
-395
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
_obj
99
_test
1010

11+
# Test data directories
12+
testdata/
13+
1114
# Architecture specific extensions/prefixes
1215
*.[568vq]
1316
[568vq].out

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ XARGS := xargs -L 1
2222

2323
VERSION_TAG = $(shell git describe --tags)
2424

25+
DEV_TAGS = kvdb_etcd kvdb_postgres kvdb_sqlite
26+
RELEASE_TAGS = $(DEV_TAGS)
27+
2528
BUILD_SYSTEM = darwin-amd64 \
29+
darwin-arm64 \
2630
linux-386 \
2731
linux-amd64 \
2832
linux-armv6 \
@@ -49,7 +53,7 @@ endif
4953
make_ldflags = $(2) -X main.Commit=$(COMMIT)
5054

5155
DEV_GCFLAGS := -gcflags "all=-N -l"
52-
LDFLAGS := -ldflags "$(call make_ldflags, ${tags}, -s -w)"
56+
LDFLAGS := -ldflags "$(call make_ldflags, $(DEV_TAGS), -s -w)"
5357
DEV_LDFLAGS := -ldflags "$(call make_ldflags, $(DEV_TAGS))"
5458

5559
# For the release, we want to remove the symbol table and debug information (-s)
@@ -83,15 +87,15 @@ build:
8387

8488
install:
8589
@$(call print, "Installing lndinit.")
86-
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)
90+
$(GOINSTALL) -tags="$(DEV_TAGS)" $(LDFLAGS) $(PKG)
8791

8892
release-install:
8993
@$(call print, "Installing release lndinit.")
9094
env CGO_ENABLED=0 $(GOINSTALL) -v -trimpath -ldflags="$(RELEASE_LDFLAGS)" -tags="$(RELEASE_TAGS)" $(PKG)
9195

9296
release:
9397
@$(call print, "Creating release of lndinit.")
94-
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_LDFLAGS)"
98+
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_LDFLAGS)" "$(RELEASE_TAGS)"
9599

96100
docker-tools:
97101
@$(call print, "Building tools docker image.")
@@ -105,7 +109,7 @@ scratch: build
105109

106110
unit:
107111
@$(call print, "Running unit tests.")
108-
$(GOTEST) ./...
112+
$(GOTEST) -tags="$(DEV_TAGS)" ./...
109113

110114
fmt: $(GOIMPORTS_BIN)
111115
@$(call print, "Fixing imports.")
@@ -115,7 +119,7 @@ fmt: $(GOIMPORTS_BIN)
115119

116120
lint: docker-tools
117121
@$(call print, "Linting source.")
118-
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
122+
$(DOCKER_TOOLS) golangci-lint run -v --build-tags="$(DEV_TAGS)"$(LINT_WORKERS)
119123

120124
vendor:
121125
@$(call print, "Re-creating vendor directory.")

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ initialization, including seed and password generation.
1313
- [`store-configmap`](#store-configmap)
1414
- [`init-wallet`](#init-wallet)
1515
- [`wait-ready`](#wait-ready)
16+
- [`migrate-db`](#migrate-db)
1617
- [Example usage](#example-usage)
1718
- [Basic setup](#example-use-case-1-basic-setup)
1819
- [Kubernetes](#example-use-case-2-kubernetes)
@@ -64,6 +65,11 @@ No `lnd` needed, but seed will be in `lnd`-specific [`aezeed` format](https://gi
6465
`wait-ready` waits for `lnd` to be ready by connecting to `lnd`'s status RPC
6566
- Needs `lnd` to run, eventually
6667

68+
### migrate-db
69+
`migrate-db` migrates the content of one `lnd` database to another, for example
70+
from `bbolt` to Postgres. See [data migration guide](docs/data-migration.md) for
71+
more information.
72+
6773
---
6874

6975
## Example Usage

cmd_init_wallet.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (x *initWalletCommand) Execute(_ []string) error {
159159
if x.InitRpc.WatchOnly {
160160
// For initializing a watch-only wallet we need the
161161
// accounts JSON file.
162-
log("Reading accounts from file")
162+
logger.Info("Reading accounts from file")
163163
accountsBytes, err := readFile(x.InitRpc.AccountsFile)
164164
if err != nil {
165165
return err
@@ -215,7 +215,7 @@ func (x *initWalletCommand) readInput(requireSeed bool) (string, string, string,
215215
// Read all secrets from individual files.
216216
case storageFile:
217217
if requireSeed {
218-
log("Reading seed from file")
218+
logger.Info("Reading seed from file")
219219
seed, err = readFile(x.File.Seed)
220220
if err != nil {
221221
return "", "", "", err
@@ -224,14 +224,14 @@ func (x *initWalletCommand) readInput(requireSeed bool) (string, string, string,
224224

225225
// The seed passphrase is optional.
226226
if x.File.SeedPassphrase != "" {
227-
log("Reading seed passphrase from file")
227+
logger.Info("Reading seed passphrase from file")
228228
seedPassPhrase, err = readFile(x.File.SeedPassphrase)
229229
if err != nil {
230230
return "", "", "", err
231231
}
232232
}
233233

234-
log("Reading wallet password from file")
234+
logger.Info("Reading wallet password from file")
235235
walletPassword, err = readFile(x.File.WalletPassword)
236236
if err != nil {
237237
return "", "", "", err
@@ -248,7 +248,7 @@ func (x *initWalletCommand) readInput(requireSeed bool) (string, string, string,
248248
}
249249

250250
if requireSeed {
251-
log("Reading seed from k8s secret %s (namespace %s)",
251+
logger.Infof("Reading seed from k8s secret %s (namespace %s)",
252252
x.K8s.SecretName, x.K8s.Namespace)
253253
seed, _, err = readK8s(k8sSecret)
254254
if err != nil {
@@ -258,7 +258,7 @@ func (x *initWalletCommand) readInput(requireSeed bool) (string, string, string,
258258

259259
// The seed passphrase is optional.
260260
if x.K8s.SeedPassphraseKeyName != "" {
261-
log("Reading seed passphrase from k8s secret %s "+
261+
logger.Infof("Reading seed passphrase from k8s secret %s "+
262262
"(namespace %s)", x.K8s.SecretName,
263263
x.K8s.Namespace)
264264
k8sSecret.KeyName = x.K8s.SeedPassphraseKeyName
@@ -268,7 +268,7 @@ func (x *initWalletCommand) readInput(requireSeed bool) (string, string, string,
268268
}
269269
}
270270

271-
log("Reading wallet password from k8s secret %s (namespace %s)",
271+
logger.Infof("Reading wallet password from k8s secret %s (namespace %s)",
272272
x.K8s.SecretName, x.K8s.Namespace)
273273
k8sSecret.KeyName = x.K8s.WalletPasswordKeyName
274274
walletPassword, _, err = readK8s(k8sSecret)
@@ -329,7 +329,7 @@ func createWalletFile(cipherSeed *aezeed.CipherSeed, walletPassword, walletDir,
329329
func createWallet(walletDir string, cipherSeed *aezeed.CipherSeed,
330330
walletPassword []byte, network string) error {
331331

332-
log("Creating new wallet in %s", walletDir)
332+
logger.Infof("Creating new wallet in %s", walletDir)
333333

334334
// The network parameters are needed for some wallet internal things
335335
// like the chain genesis hash and timestamp.
@@ -358,15 +358,15 @@ func createWallet(walletDir string, cipherSeed *aezeed.CipherSeed,
358358
err)
359359
}
360360

361-
log("Wallet created successfully in %s", walletDir)
361+
logger.Infof("Wallet created successfully in %s", walletDir)
362362

363363
return nil
364364
}
365365

366366
func validateWallet(walletDir string, walletPassword []byte,
367367
network string) error {
368368

369-
log("Validating password for wallet in %s", walletDir)
369+
logger.Infof("Validating password for wallet in %s", walletDir)
370370

371371
// The network parameters are needed for some wallet internal things
372372
// like the chain genesis hash and timestamp.
@@ -391,7 +391,7 @@ func validateWallet(walletDir string, walletPassword []byte,
391391
err)
392392
}
393393

394-
log("Wallet password validated successfully")
394+
logger.Info("Wallet password validated successfully")
395395

396396
return nil
397397
}

0 commit comments

Comments
 (0)