github.com/decred/politeia@v1.4.0/politeiawww/cmd/politeiawww_dbutil/README.md (about)

     1  # politeiawww_dbutil
     2  
     3  politeiawww_dbutil is a tool that allows you to interact with the politeiawww
     4  database.
     5  
     6  **Note**: If you are using LevelDB for the user database you have to shut down
     7  politeiawww before using this tool.  LevelDB only allows for a single
     8  connection at a time.
     9  
    10  
    11  ## Usage
    12  
    13  You can specify the following options:
    14  
    15      Database options
    16        -leveldb
    17              Use LevelDB
    18        -cockroachdb
    19              Use CockroachDB
    20        -mysql
    21              Use MySQL
    22  
    23      Application options
    24        -testnet
    25              Use testnet database
    26        -datadir string
    27              politeiawww data directory
    28              (default osDataDir/politeiawww/data)
    29        -cockroachdbhost string
    30              CockroachDB ip:port 
    31              (default localhost:26257)
    32        -rootcert string
    33              File containing the CockroachDB SSL root cert
    34              (default ~/.cockroachdb/certs/clients/politeiawww/ca.crt)
    35        -clientcert string
    36              File containing the CockroachDB SSL client cert
    37              (default ~/.cockroachdb/certs/clients/politeiawww/client.politeiawww.crt)
    38        -clientkey string
    39              File containing the CockroachDB SSL client cert key
    40              (default ~/.cockroachdb/certs/clients/politeiawww/client.politeiawww.key)
    41        -encryptionkey string
    42              File containing the CockroachDB/MySQL encryption key
    43              (default osDataDir/politeiawww/sbox.key)
    44        -password string
    45              MySQL database password.
    46        -mysqlhost string
    47              MySQL ip:port 
    48              (default localhost:3306)
    49  
    50      Commands
    51        -addcredits
    52              Add proposal credits to a user's account
    53              Required DB flag : -leveldb, -cockroachdb or -mysql
    54              LevelDB args     : <email> <quantity>
    55              CockroachDB args : <username> <quantity>
    56        -setadmin
    57              Set the admin flag for a user
    58              Required DB flag : -leveldb, -cockroachdb or -mysql
    59              LevelDB args     : <email> <true/false>
    60              CockroachDB args : <username> <true/false>
    61        -setemail
    62              Set a user's email to the provided email address
    63              Required DB flag : -cockroachdb or -mysql
    64              CockroachDB args : <username> <email>
    65        -stubusers
    66              Create user stubs for the public keys in a politeia repo
    67              Required DB flag : -leveldb, -cockroachdb or -mysql
    68              LevelDB args     : <importDir>
    69              CockroachDB args : <importDir>
    70        -dump
    71              Dump the entire database or the contents of a specific user
    72              Required DB flag : -leveldb
    73              LevelDB args     : <username>
    74        -createkey
    75              Create a new encryption key that can be used to encrypt data at rest
    76              Required DB flag : None
    77              Args             : <destination (optional)>
    78                                 (default osDataDir/politeiawww/sbox.key)
    79        -migrate
    80              Migrate from one user database to another
    81              Required DB flag : None
    82              Args             : <fromDB> <toDB>
    83                                 Valid DBs are mysql, cockroachdb, leveldb
    84        -verifyidentities
    85              Verify a user's identities do not violate any politeia rules. Invalid
    86              identities are fixed.
    87              Required DB flag : -cockroachdb or -mysql 
    88              Args             : <username>
    89        -resettotp
    90              Reset a user's totp settings in case they are locked out and 
    91              confirm identity. 
    92              Required DB flag : -leveldb, -cockroachdb or -mysql
    93              LevelDB args     : <email>
    94              CockroachDB args : <username>
    95  
    96  ### Examples
    97  
    98  Mainnet example:
    99  
   100      $ politeiawww_dbutil -cockroachdb -setadmin username true
   101  
   102  Testnet example:
   103  
   104      $ politeiawww_dbutil -testnet -cockroachdb -setadmin username true
   105  
   106  ### Migrate user database
   107  
   108  The `-migrate` command allows you to migrate from one database type to another. 
   109  
   110  **Notes:**
   111   - CockroachDB & MySQL encrypt data at rest so if you migrating from levelDB 
   112   you will first need to create an encryption key using the `-createkey` command.  
   113  
   114   - The flags `-datadir`, `-cockroachdbhost`, `-rootcert`, `-clientcert`, 
   115   `-clientkey`, `-encryptionkey` and `mysqlhost` only need to be set if they 
   116   deviate from the defaults.
   117  
   118  Create an encryption key.
   119  
   120      $ politeiawww_dbutil -createkey
   121      Encryption key saved to: ~/.politeiawww/sbox.key
   122  
   123  Migrate the user database.
   124  
   125      $ politeiawww_dbutil -testnet -password grrr -migrate cockroachdb mysql
   126      CockroachDB : localhost:26257 testnet3
   127      MySQL : localhost:3306 testnet3
   128      Migrating records from cockroachdb to mysql...
   129      Users migrated : 6
   130      Paywall index  : 5
   131      Done!
   132  
   133  Update your politeiawww.conf file.  The location of the encryption key may
   134  differ depending on your operating system.
   135  
   136      userdb=mysql
   137      encryptionkey=~/.politeiawww/sbox.key
   138  
   139  ### Stubbing Users
   140  
   141  If you import data from a public politeia repo using the
   142  [politeiaimport](https://github.com/decred/politeia/tree/master/politeiad/cmd/politeiaimport)
   143  tool, you will also need to create user stubs in the politeiawww database for
   144  the public keys found in the import data.  Without the user stubs, politeiawww
   145  won't be able to associate the public keys with specific user accounts and will
   146  error out.