This guide covers how to set up MySQL as a datastore for Warrant.
Note: Please first refer to the development guide to ensure that your Go environment is set up and you have checked out the Warrant source or downloaded a binary.
Follow the MySQL Installation Guide for your OS to install and start MySQL. For MacOS users, we recommend installing MySQL using homebrew.
The Warrant server requires certain configuration, defined either within a warrant.yaml
file (located within the same directory as the binary) or via environment variables. This configuration includes some common variables and some MySQL specific variables. Here's a sample config:
port: 8000
logLevel: 1
enableAccessLog: true
autoMigrate: true
authentication:
apiKey: replace_with_api_key
datastore:
mysql:
username: replace_with_username
password: replace_with_password
hostname: 127.0.0.1
database: warrant
Note: You can create a database via the mysql command line and configure it as the database
attribute under datastore
.
You can also customize your database connection by providing a DSN (Data Source Name). If provided, this string is used to open the given database rather using the individual variables, i.e. user
, password
, hostname
.
datastore:
mysql:
dsn: root:@tcp(127.0.0.1:3306)/warrant?parseTime=true
Note: parseTime=true
must be included when providing a DSN to parse DATE
and DATETIME
values to time.Time
.
Warrant uses golang-migrate to manage sql db migrations. If the autoMigrate
config flag is set to true, the server will automatically run migrations on start. If you prefer managing migrations and upgrades manually, please set the autoMigrate
flag to false.
You can install golang-migrate yourself and run the MySQL migrations manually:
migrate -path ./migrations/datastore/mysql/ -database mysql://username:password@hostname/warrant up