Skip to content
Snippets Groups Projects
Commit 390133f4 authored by Sabine Schröder's avatar Sabine Schröder
Browse files

#7: some minor corrections already done; still to carefully check all tables

parent 217b2c47
No related branches found
No related tags found
No related merge requests found
Pipeline #40519 passed
......@@ -10,7 +10,7 @@ from .models_person import Person
from .models_organisation import Organisation
from sqlalchemy import Table, Column, Integer, String, \
ForeignKey, text, CheckConstraint, Sequence
ForeignKey, text, CheckConstraint, UniqueConstraint, Sequence
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
......@@ -51,16 +51,21 @@ class Contact(Base):
+-----------------+---------+-----------+----------+----------------------------------------+
Indexes:
"contacts_pkey" PRIMARY KEY, btree (id)
"contacts_person_id_organisation_id" UNIQUE CONSTRAINT, btree (person_id, organisation_id)
Check constraints:
"ck_contact" CHECK (person_id > 0 AND organisation_id = 0 OR person_id = 0 AND organisation_id > 0)
Foreign-key constraints:
"contacts_organisation_id_fkey" FOREIGN KEY (organisation_id) REFERENCES organisations(id)
"contacts_person_id_fkey" FOREIGN KEY (person_id) REFERENCES persons(id)
Referenced by:
TABLE "stationmeta_roles" CONSTRAINT "stationmeta_roles_contact_id_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED
TABLE "timeseries_roles" CONSTRAINT "timeseries_roles_contact_id_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED
"""
__tablename__ = 'contacts'
__table_args__ = (
CheckConstraint('((person_id > 0) AND (organisation_id = 0)) OR ((person_id = 0) AND (organisation_id > 0))'),
UniqueConstraint('person_id', 'organisation_id')
)
id = Column(Integer, primary_key=True, server_default=text("nextval('contacts_id_seq'::regclass)"))
......
......@@ -17,7 +17,7 @@ class Organisation(Base):
+----------------+------------------------+-----------+----------+-------------------------------------------+
| name | character varying(32) | | not null | |
+----------------+------------------------+-----------+----------+-------------------------------------------+
| longname | character varying(128) | | not null | |
| longname | character varying(256) | | not null | |
+----------------+------------------------+-----------+----------+-------------------------------------------+
| kind | integer | | not null | |
+----------------+------------------------+-----------+----------+-------------------------------------------+
......@@ -45,7 +45,7 @@ class Organisation(Base):
id = Column(Integer, ORGANISATIONS_ID_SEQ, primary_key=True, server_default=ORGANISATIONS_ID_SEQ.next_value())
name = Column(String(32), nullable=False)
longname = Column(String(128), nullable=False)
longname = Column(String(256), nullable=False)
kind = Column(ForeignKey('ok_vocabulary.enum_val'), nullable=False)
city = Column(String(64), nullable=False)
postcode = Column(String(16), nullable=False)
......
......@@ -34,7 +34,7 @@ class TimeseriesRole(Base):
+---------------+---------+-----------+----------+----------------------------------------------+
Indexes:
"timeseries_roles_pkey" PRIMARY KEY, btree (id)
"timeseries_roles_role_contact_id_uniq" UNIQUE CONSTRAINT, btree (role, contact_id)
"timeseries_roles_role_status_contact_id_uniq" UNIQUE CONSTRAINT, btree (role, status, contact_id)
"timeseries_roles_contact_id" btree (contact_id)
Check constraints:
"timeseries_roles_role_check" CHECK (role >= 0)
......@@ -47,7 +47,7 @@ class TimeseriesRole(Base):
__table_args__ = (
CheckConstraint('role >= 0'),
CheckConstraint('status >= 0'),
UniqueConstraint('role', 'contact_id')
UniqueConstraint('role', 'status', 'contact_id')
)
id = Column(Integer, TIMESERIES_ROLES_ID_SEQ, primary_key=True, server_default=TIMESERIES_ROLES_ID_SEQ.next_value())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment