Skip to content

Commit

Permalink
dbutil: Update dump cmd.
Browse files Browse the repository at this point in the history
This commit updates the dump command so that it works with all of the
user database implemenations. It also simplifies the implementation to
only allow for dumping a single user to stdout. There is no use case
that requires dumping all of the users at once. The migrate command
should be used when migrating databases, not the dump command.
  • Loading branch information
lukebp authored Aug 8, 2022
1 parent ec4a9c8 commit 35c283d
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions politeiawww/cmd/politeiawww_dbutil/politeiawww_dbutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const usageMsg = `politeiawww_dbutil usage:
CockroachDB args : <importDir>
-dump
Dump the entire database or the contents of a specific user
Required DB flag : -leveldb
Required DB flag : -leveldb or -cockroachdb or -mysql
LevelDB args : <username>
-createkey
Create a new encryption key that can be used to encrypt data at rest
Expand All @@ -179,28 +179,19 @@ const usageMsg = `politeiawww_dbutil usage:
CockroachDB args : <username>`

func cmdDump() error {
// If email is provided, only dump that user.
args := flag.Args()
if len(args) == 1 {
username := args[0]
u, err := userDB.UserGetByUsername(username)

if err != nil {
return err
}

fmt.Printf("Key : %v\n", username)
fmt.Printf("Record : %v", spew.Sdump(u))
return nil
if len(args) == 0 {
return fmt.Errorf("username was not provided")
}

err := userDB.AllUsers(func(u *user.User) {
fmt.Printf("Key : %v\n", u.Username)
fmt.Printf("Record : %v\n", spew.Sdump(u))
})
username := args[0]
u, err := userDB.UserGetByUsername(username)
if err != nil {
return err
}

fmt.Printf("%v", spew.Sdump(u))

return nil
}

Expand Down Expand Up @@ -863,18 +854,12 @@ func _main() error {
}

switch {
case *addCredits || *setAdmin || *stubUsers || *resetTotp:
case *addCredits || *setAdmin || *stubUsers || *resetTotp || *dump:
// These commands must be run with -cockroachdb, -mysql or -leveldb.
if !*level && !*cockroach && !*mysql {
return fmt.Errorf("missing database flag; must use " +
"-leveldb, -cockroachdb or -mysql")
}
case *dump:
// These commands must be run with -leveldb.
if !*level {
return fmt.Errorf("missing database flag; must use " +
"-leveldb with this command")
}
case *verifyIdentities, *setEmail:
// These commands must be run with either -cockroachdb or -mysql.
if !*cockroach && !*mysql {
Expand Down

0 comments on commit 35c283d

Please sign in to comment.