From 390133f42584fbba31aba0b784e53e354cddbaed Mon Sep 17 00:00:00 2001 From: schroeder5 <s.schroeder@fz-juelich.de> Date: Mon, 6 Jul 2020 22:05:34 +0200 Subject: [PATCH] #7: some minor corrections already done; still to carefully check all tables --- toardb/contacts/models.py | 7 ++++++- toardb/contacts/models_organisation.py | 4 ++-- toardb/timeseries/models_role.py | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/toardb/contacts/models.py b/toardb/contacts/models.py index 0c33a6e..3846012 100644 --- a/toardb/contacts/models.py +++ b/toardb/contacts/models.py @@ -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)")) diff --git a/toardb/contacts/models_organisation.py b/toardb/contacts/models_organisation.py index 31d4dc4..d2427cf 100644 --- a/toardb/contacts/models_organisation.py +++ b/toardb/contacts/models_organisation.py @@ -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) diff --git a/toardb/timeseries/models_role.py b/toardb/timeseries/models_role.py index 2db40ea..6d3d53a 100644 --- a/toardb/timeseries/models_role.py +++ b/toardb/timeseries/models_role.py @@ -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()) -- GitLab