This repository 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.
- Server and a client packages of MariaDB 10.6 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;
- Install MariaDB. The Wiki has ideas on how to install in a particular environment, including OS packages or containers via the provided Dockerfile. If you use the container approach with the provided Dockerfile, then steps 2 and 3 below are done for you automatically.
- Copy
.my.example.cnf
to.my.cnf
and then edit that file to set theuser
andpassword
, e.g.user = root
and correspondpassword
. Optionally, you can also set e.g.host
andport
. - 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.
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.
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.
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';
In order to update a production database, please follow this procedure:
- 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
- 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
- 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
build.sh
: Creates a developmentispyb_build
database and imports all the schema and grants files into it.release.sh
: Makes a release, see theRELEASE.md
file for details.bin/backup.sh
: Makes a backup of the development database, producing four files:tables.sql
,routines.sql
,lookups.sql
,data.sql
.bin/missed_updates.sh
: Generates a list of files in theschemas/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.
- Please refer to the
Wiki
for database diagrams, stored procedure how-to, MariaDB installation and more - A complete
list of tables and columns
for more details about the tables and columns - A complete
list of stored procedures
for more details about the stored procedures