Skip to content

Commit 3d6bb9c

Browse files
authored
Murfey database documentation (#387)
Updated the package READMEs to include latest packages used and instructions on setting up the PostgreSQL database for use with Murfey.
1 parent cbdc412 commit 3d6bb9c

File tree

2 files changed

+92
-8
lines changed

2 files changed

+92
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A transporter for data from Diamond eBIC microscope and detector machines onto the Diamond network.
44

5-
### Who is Murfey?
5+
## Who is Murfey?
66

77
Murfey, the package, is named after [Eliza Murfey, the inventor](https://nationalrrmuseum.org/blog/mother-of-invention-women-railroad-innovators/):
88

@@ -11,38 +11,38 @@ Murfey, the package, is named after [Eliza Murfey, the inventor](https://nationa
1111
> it was Murfey who designed the packings that would lubricate the axles with oil, aiding
1212
> in the reduction of derailments caused by seized axles and bearings.
1313
14-
### How do I set up a development environment?
14+
## How do I set up a development environment?
1515

1616
We suggest you start with your favourite virtual environment (mamba/conda/python virtualenv/...),
1717
then install using the following command.
1818

19-
#### From Git
20-
21-
```bash
19+
```text
2220
$ git clone [email protected]:DiamondLightSource/python-murfey.git
2321
$ cd python-murfey
2422
$ pip install -e .[client,server,developer]
2523
```
2624

2725
The packages included under the `[developer]` installation key contain some helpful tools to aid you with developing Murfey further:
2826

27+
- `bump-my-version` - Simplifies version control.
2928
- `ipykernel` - Enables interactive code development via Jupyter Notebooks.
3029
- `pre-commit` - Allows for the installation and running of hooks to help with linting, formatting, and type checking your code.
3130
- `pytest` - Used in conjunction with test functions to evaluate the reliability of your code.
32-
- `bump2version` - A nice little script to simplify version control.
31+
32+
Instructions for setting up the database for Murfey to register files to can be found [here](src/murfey/server/MURFEY_DB.md).
3333

3434
Finally, you may want to set up an ISPyB mock database server and a Zocalo
3535
development environment. The instructions for this are out of scope here.
3636

3737
You can then start the Murfey server with
3838

39-
```bash
39+
```text
4040
$ murfey.server
4141
```
4242

4343
and connect the client with
4444

45-
```bash
45+
```text
4646
$ murfey --server http://127.0.0.1:8000
4747
```
4848

src/murfey/server/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Murfey Database
2+
3+
Murfey has been designed to work with PostgreSQL databases to maintain a record of the files it has transferred, which allow it to oversee and manage multi-step data processing workflows. This page will walk readers through the process of setting up a PostgreSQL database for use with Murfey.
4+
5+
## Setting Up
6+
7+
### Installing `postgresql`
8+
9+
To start, we will install the `postgresql` package hosted on conda-forge. This can be done using either `conda` or `mamba`. In this example, we will create a new Python 3.9 environment named `murfey-db` which will be used to run `postgresql`.
10+
11+
```text
12+
(base)$ mamba create -n murfey-db python==3.9.*
13+
(base)$ mamba activate murfey-db
14+
(murfey-db)$ mamba install -c conda-forge postgresql
15+
```
16+
17+
### Creating and initialising the database
18+
19+
Next, we need to find a directory for the database to reside in. This can generally be any location in your file system, but for this example, we shall create a directory called `murfey` in the default home location of `~`.
20+
21+
```text
22+
(murfey-db)$ mkdir -p ~/murfey
23+
(murfey-db)$ cd ~/murfey
24+
(murfey-db)$ initdb -U murfey -D database -W
25+
```
26+
27+
With the command above, we are creating a new superuser named 'murfey' for this database in the folder 'database', which resides in `~/murfey`. The `-W` flag will prompt for a password to be set for this new superuser.
28+
29+
This database cluster can then be started by running the following command:
30+
31+
```text
32+
(murfey-db)$ pg_ctl start -D database -l database.log
33+
```
34+
35+
This will create a background process on your computer that will run this database instance. The `-l` flag in the command specifies the creation of a running log file, which we've named `database.log`. If you wish to stop the database process, you can simply run the following:
36+
37+
```text
38+
(murfey-db)$ pg_ctl stop -D database
39+
```
40+
41+
After that, we can proceed with creating the actual database for Murfey within this cluster using the following command:
42+
43+
```text
44+
createdb murfey --owner=murfey -U murfey -W
45+
```
46+
47+
This will create a database named 'murfey' owned by the user 'murfey'. This database can then be accessed and inspected by running the following command:
48+
49+
```text
50+
(murfey-db)$ psql murfey -U murfey -W
51+
```
52+
53+
To strengthen the security of your database, you can make password requests mandatory by editing the file `database/pg_hba.conf`. Change all instances of `trust` to `md5` or another one of the listed valid encryption methods.
54+
55+
### Configuring Murfey
56+
57+
At this point, we will need to configure Murfey to be able to connect to the database. To do so, we will need to create a configuration file for the instrument Murfey is supporting, a security configuration file, and a credentials file for the database. Instructions on how to do so can be found here (COMING SOON).
58+
59+
### Configuring the database
60+
61+
Next, we will need to create a role in the Murfey database under whose name the data will be registered. To do so, we start up `postgresql` and run the following commands:
62+
63+
```text
64+
(murfey-db)$ psql murfey -U murfey -W
65+
murfey=# create user murfey_server with password '[password here]' createdb;
66+
murfey=# grant all privileges on database murfey to murfey_server;
67+
murfey=# grant all privileges on schema public to murfey_server;
68+
```
69+
70+
The user 'murfey_server' will be stored under the 'username' key in the database credentials file used for this microscope, and the database name 'murfey' is stored under the 'database' key in that same file. The password you use when creating this role should be the encrypted one previously set up when creating the credentials file.
71+
72+
### Configuring Murfey again
73+
74+
Having created the the database user, we now need to go back to the Python environment we installed Murfey in in order to perform some final configurations.
75+
76+
```text
77+
(base)$ mamba activate murfey
78+
(murfey)$ murfey.create_db
79+
(murfey)$ murfey.add_user -u '[your choice of username]' -p '[your choice of password]'
80+
```
81+
82+
`murfey.create_db` will populate the 'murfey' PostgreSQL database with the tables needed to record your experimental data, and `murfey.add_user` creates a user in the 'murfeyuser' table that is authorised to connect to this Murfey server.
83+
84+
With this final step, the PostgreSQL database is ready to be used. Once you have installed Murfey on the client computer (COMING SOON), and have setup the relevant configuration files (COMING SOON), Murfey will be ready to support your data transfer and processing needs.

0 commit comments

Comments
 (0)