Main principles¶
The Enhydris database is implemented in PostgreSQL. While the implementation of the database is through Django’s object-relational mapper, which is more or less RDBMS-independent, other RDBM’s besides PostgreSQL have not been used in debugging, so they may or may not work. In addition, Django does not offer functionality for upgrading the database (other than creating nonexistent tables). With each new release, we provide a script that upgrades the database, and this only works with PostgreSQL. If you use another database, you will have to modify the upgrade script appropriately. In other words, using databases besides PostgreSQL is unsupported.
In Django parlance, a model is a type of entity, which usually maps to a single database table. Therefore, in Django, we usually talk of models rather than of database tables, and we design models, which is close to a conceptual database design, leaving it to Django’s object-relational mapper to translate to the physical. In this text, we also speak more of models than of tables. Since a model is a Python class, we describe it as a Python class rather than as a relational database table. If, however, you feel more comfortable with tables, you can generally read the text understanding that a model is a table.
If you are interested in the physical structure of the database, you need to know the model translation rules, which are quite simple:
- The name of the table is the lower case name of the model, with a prefix. The prefix for the core of the database is hcore_. (More on the prefix below).
- Tables normally have an implicit integer id field, which is the primary key of the table.
- Table fields have the same name as model attributes, except for foreign keys.
- Foreign keys have the name of the model attribute suffixed with _id.
- When using multi-table inheritance, the primary key of the child table is also a foreign key to the id field of the parent table. The name of the database column for the key of the child table is the lower cased parent model name suffixed with _ptr_id.
There are two drawings that accompany this text: the drawing for the conceptual data model, and the drawing for the physical data model. You should avoid looking at the physical data model; it is cluttered and confusing, since it is machine-generated. It is only provided for the benefit of those who are not comfortable with Django’s object-relational mapping. However, it is best to learn to read the conceptual data model; if you become acquainted with the Django’s object-relational mapping rules listed above, you will be able to write SQL commands effortlessly, by using these rules in your head. The drawing of the physical data model is also far more likely to contain errors or to be outdated than the drawing and documentation for the conceptual data model.
The core of the Enhydris database is a list of measuring stations, with additional information such as instruments, photos, videos, and so on, and the hydrological and meteorological time series stored for each measuring station. This can be used in or assisted by many more applications, which may or may not be needed in each setup. A billing system is needed for agencies that charge for their data, but not for those who offer them freely or only internally. Some organisations may need to develop additional software for managing aqueducts, and some may not. Therefore, the core is kept as simple as possible. The core database tables use the hcore_ prefix. Other applications use another prefix. The name of a table is the lowercased model name preceeded by the prefix. For example, the table that corresponds to the Gentity model is hcore_gentity.
Multilinguality
Originally, the database was designed in order to be multilingual, that is, so that the content could be stored in an unlimited number of languages. The django-multilingual framework was used for this purpose. However, django-multilingual bugs slowed development too much, and it was decided to go for a more modest solution: texts are simply stored in two languages: the local language and the alternative language. For example, for a description, there are the “descr” field and the “descr_alt” field. Which languages are “descr” and “descr_alt” depends on the installation. For example, we use Greek as the local language and English as the alternative language.
We hope to get rid of this, but this will involve fixing django-multilingual or using another multilingual framework.
When any field in the API is marked as being multilingual, it means that it is accompanied by an additional identical field that has “_alt” appended to its name. (It also means that, instead, it should be defined in a Translation class nested in the model class, as would be the case if django-multilingual were used.)