/ispyb-database

CREATE scripts and documentation for the Diamond flavour of the ISPyB database

Primary LanguageShellGNU Lesser General Public License v3.0LGPL-3.0

Build Status

ispyb-database

This package provides everything needed to create the Diamond flavour of the ISPyB database schema. As we evolve the schema we will publish the update scripts here, so hopefully it should be easy for other users of the schema to stay up-to-date.

Requirements

  • We recommend MariaDB 10.3 or later.
  • Linux with bash is assumed, but it's possible to make this work on other OSes.
  • If binary logging is enabled in the DB system, then execute this before importing the test schema: SET GLOBAL log_bin_trust_function_creators=ON;

Installation

Make sure you have installed the MariaDB server and client, and maybe secured the installation by running mariadb-secure-installation (or mysql_secure_installation on MariaDB 10.3 or older). You should copy .my.example.cnf to .my.cnf and then edit that file to set the user and password, e.g. user = root and use the password you set when securing.

In a test environment you can then run the build.sh file. This creates the database schema and applies the grants as described in the "Schema" and "Grants" sections below.

Schema

Run this on the command-line to create a database and import the schema stored in the SQL files:

mysql -e "CREATE DATABASE ispyb"
mysql ispyb < schemas/ispyb/tables.sql
mysql ispyb < schemas/ispyb/lookups.sql
mysql ispyb < schemas/ispyb/data.sql
mysql ispyb < schemas/ispyb/routines.sql

Note that the data.sql file contains test data, so is only useful in a development environment.

Grants

Then apply the grants:

mysql ispyb < grants/ispyb_acquisition.sql
mysql ispyb < grants/ispyb_processing.sql
mysql ispyb < grants/ispyb_web.sql

Note that the grants files are based on roles, so to actually use these grants, you also need to create database users and grant the roles to them. This is described in the header section of the grant files.

Miscellaneous Notes

Note that SynchWeb currently assumes sql_mode is not set. I.e. it assumes that you have a line like the below in the MariaDB .cnf file:

sql_mode=''

In a development environment it might be useful to log all SQL errors. In MariaDB, you can install the SQL Error Log Plugin to get these logged to a file sql_errors.log inside your datadir. Run this from the mariadb command-line:

INSTALL SONAME 'sql_errlog';

You can verify that it's installed and activated with:

SHOW PLUGINS SONAME WHERE Name = 'SQL_ERROR_LOG';

Updating

In order to update a production database, please follow this procedure:

  1. For all .sql files in schemas/ispyb/updates that have not already been run, read any comments inside the files to decide if/when you should run them. Run a file e.g. like this:
mysql ispyb < schemas/ispyb/updates/2019_03_29_BLSession_archived.sql
  1. If schemas/ispyb/routines.sql has been updated since you installed it, you can simply re-run it. E.g.:
mysql ispyb < schemas/ispyb/routines.sql
  1. If you ran the routines.sql, then re-apply the grants for the routines. E.g.:
mysql ispyb < grants/ispyb_acquisition.sql
mysql ispyb < grants/ispyb_processing.sql
mysql ispyb < grants/ispyb_web.sql

Documentation