Skip to content

Database schema and documentation for the Diamond flavour of the ISPyB database

License

Notifications You must be signed in to change notification settings

DiamondLightSource/ispyb-database

Repository files navigation

Build Status

ispyb-database

This package provides everything needed to create the Diamond flavour of the ISPyB database schema. As the schema evolves the update scripts will also be published here, so other users of the schema should be able to stay up-to-date.

Requirements

  • Server and a client packages of MariaDB 10.3 or later.
  • A Unix-like OS with bash shell.
  • The pandoc package (only required to build documentation at the end of the build.sh script.)
  • 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

  1. Install MariaDB. See the Wiki for ideas on how to install in a particular environment.
  2. 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. Optionally, you can also set e.g. host and port.
  3. In a test environment run the build.sh file. This creates the database schema and applies the grants as described in the "Schema" and "Grants" sections below.

Schema

Tip: Execute ./build.sh to create a development ispyb_build database and import all the schema and grants files into it.

Alternatively, do it manually:

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

mariadb -e "CREATE DATABASE ispyb"
mariadb ispyb < schemas/ispyb/tables.sql
mariadb ispyb < schemas/ispyb/lookups.sql
mariadb ispyb < schemas/ispyb/data.sql
mariadb 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:

mariadb ispyb < grants/ispyb_acquisition.sql
mariadb ispyb < grants/ispyb_import.sql
mariadb ispyb < grants/ispyb_processing.sql
mariadb ispyb < grants/ispyb_ro_nopii.sql
mariadb ispyb < grants/ispyb_scripts_processing.sql
mariadb ispyb < grants/ispyb_ssx_writer.sql
mariadb ispyb < grants/ispyb_touchscreen.sql
mariadb ispyb < grants/ispyb_web.sql
mariadb ispyb < grants/ispyb_web_verify_tests.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:
mariadb 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.:
mariadb ispyb < schemas/ispyb/routines.sql
  1. If you ran the routines.sql, then re-apply the grants for the routines. E.g.:
mariadb ispyb < grants/ispyb_acquisition.sql
mariadb ispyb < grants/ispyb_processing.sql
mariadb ispyb < grants/ispyb_web.sql

Useful scripts

  • build.sh: Creates a development ispyb_build database and imports all the schema and grants files into it.
  • release.sh: Makes a release, see the Releasing section.
  • bin/backup.sh: Makes a backup of the development database.
  • bin/missed_updates.sh: Generates a list of files in the schemas/ispyb/updates/ folder that haven't been applied.
  • bin/export_session.sh: Exports a given session's database rows to SQL files. These can then easily be imported into an empty ispyb database. This can be used e.g. to create a single-session ISPyB/SynchWeb instance if combined with all the relevant data files and processing files for the session, and an instance of SynchWeb.

Documentation