<p>Two scripts can be used to create a database for MIG.</p>
<ul>
<li><ahref="https://github.com/mozilla/mig/blob/master/src/mig/database/createlocaldb.sh">createlocaldb.sh</a> will create a database on an instance of postgresql running locally. This is used by the standalone installation script.</li>
</ul>
<ul>
<li><ahref="https://github.com/mozilla/mig/blob/master/src/mig/database/createremotedb.sh">createremotedb.sh</a> will connect to an existing MIG database on a remote postgresql server. This is a standard production setup. It assumes that you have created a database beforehand. You can pass the DB credentials by editing the bash variables at the top of the script before running it.</li>
<p>The full database schema is available as a SQL file in <ahref="https://github.com/mozilla/mig/blob/master/src/mig/database/schema.sql">src/mig/database/schema.sql</a>.</p>
<p>The <cite>actions</cite> table contains the detail of each action ran by the MIG platform. Its structure contains the base action fields found in the json format of an action, plus a number of additional fields such as timestamps and counters.</p>
<p>The <cite>agents</cite> table contains the registrations of each agents known of the MIG platform.</p>
<p>The <cite>commands</cite> table contains each action sent to each agent.</p>
<p><cite>investigators</cite> have a table that contains their public PGP key, and can be used when verifying signatures and generating ACLs.</p>
<p>The <cite>signatures</cite> table is a junction between an action and the investigators that signed the action.</p>
<p>MIG queries are stored separately from the rest of the source code. You can inspect and modify all queries directly in the Go files in <ahref="https://github.com/mozilla/mig/tree/master/src/mig/database">src/mig/database</a>.</p>
<p>In the future, this will probably be automated via the API. But for now, and until we have a strong authentication mechanism for API calls, it must be done manually in the database.</p>
<p>Adapt the query below to add a new investigator.</p>
<p>The following query retrieves a list of agents that have been online over the last 30 days, but have not sent a heartbeat in the last 5 minutes.</p>
<p>Sometimes during upgrades the older agent isn't shut down. You can find these endpoints with double agents in the database because each agent sends separate heartbeats for the same endpoint:</p>
<p>MIG data is stored both on the file system of the scheduler, and in the database. On the scheduler, each action and command are stored individually in a text file in /var/cache/mig (by default).</p>