Newer
Older
## Introduction
To run anis-server need at least two databases:
- One database to store the configuration (metamodel database)
- At least one database containing datasets
Here we will explain how the metamodel database works.
Anis-server needs a database to store all the configuration :
- The available business database(s) that should contain the shared datasets.
- The different scientific projects.
- The shared datasets and their attributes.
- The access rights on datasets (groups_datasets).

## Settings
By default anis-server is configured to connect to a PostgreSQL database created during the first launch of docker-compose.
The docker compose integrates a PostgreSQL database server named `db`.
You can find the `docker-compose.yml` file at the root of the anis-server project.
The database settings connection are given in the environment variables of the php container.

Here is the list of options concerning the metamodel database :
- `DATABASE_DEV_MODE`: Default to `1` in development mode and to `0` in production mode
- `DATABASE_CO_DRIVER`: Doctrine pdo driver used to connect to the database
- `DATABASE_CO_HOST`: Database server host
- `DATABASE_CO_PORT`: Database server listening port
- `DATABASE_CO_DBNAME`: Name of the anis-server metamodel database
- `DATABASE_CO_USER`: User name used to connect to the anis-server metamodel database
- `DATABASE_CO_PASSWORD`: Password used to connect to the anis-server metamodel database
You are free to change this configuration to connect to another database.
## Doctrine entities
Anis server uses a tool called doctrine to generate the database from the code.
You can find more information on the official website: [https://www.doctrine-project.org](https://www.doctrine-project.org).
Anis server stores the different doctrine entities in the `src/Entity` folder and each file corresponds to a table in the metamodel database.

If you want to change the structure of the database you must edit or add entities.
But be careful for each change you will have to re-generate the database and the doctrine proxies.
## Doctrine command-line tool
You can use the doctrine command-line tool to perform most of the operations.
To run the tool you must have launched anis-server with the `docker-compose.yml` file (see installation).
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
You must be at the root of the anis-server directory.
And you can then enter into the anis-server container by typing the following command:
```bash
$ make shell
```
Once in the container you can type the following command to execute doctrine-cli:
```bash
$ ./vendor/bin/doctrine
```
What you see are the different operations you can perform.

## Validate schema
If you have performed operations on entities you must ensure that the database schema remains valid.
Doctrine then proposes a command to perform that:
```bash
$ ./vendor/bin/doctrine orm:validate-schema
```
## Create database
If the tables of your database are not yet generated you must ask doctrine to create them with the following command:
```bash
$ ./vendor/bin/doctrine orm:schema-tool:create
```
## Drop database
If the tables of your database are already generated but you want to start from a blank database you can type the following command:
```bash
$ ./vendor/bin/doctrine orm:schema-tool:drop
```
## Update database
If you have made changes to your entities you must update the database with the following command:
```bash
$ ./vendor/bin/doctrine orm:schema-tool:update
```
## Generate proxies
If you have made changes to your entities you must also update the doctrine entities proxies.
The doctrine entities proxies are used to improve the performance of requests.
To regenerate them type the following command:
```bash
$ ./vendor/bin/doctrine orm:generate-proxies
```