From 0924b7c464975395ebf318aadf255005d35f8f61 Mon Sep 17 00:00:00 2001 From: Alexander Watzinger Date: Tue, 8 Oct 2024 13:54:15 +0200 Subject: [PATCH] Moved annotation tables to model schema --- install/1_structure.sql | 395 +++++++++++++++------------- install/upgrade/text_annotation.sql | 43 +-- openatlas/database/annotation.py | 20 +- 3 files changed, 239 insertions(+), 219 deletions(-) diff --git a/install/1_structure.sql b/install/1_structure.sql index 5d3e95b20..f60de97ed 100644 --- a/install/1_structure.sql +++ b/install/1_structure.sql @@ -32,12 +32,6 @@ ALTER TABLE IF EXISTS ONLY web.hierarchy DROP CONSTRAINT IF EXISTS hierarchy_id_ ALTER TABLE IF EXISTS ONLY web.hierarchy_openatlas_class DROP CONSTRAINT IF EXISTS hierarchy_form_hierarchy_id_fkey; ALTER TABLE IF EXISTS ONLY web.entity_profile_image DROP CONSTRAINT IF EXISTS entity_profile_image_image_id_fkey; ALTER TABLE IF EXISTS ONLY web.entity_profile_image DROP CONSTRAINT IF EXISTS entity_profile_image_entity_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_user_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_source_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_entity_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_user_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_image_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_entity_id_fkey; ALTER TABLE IF EXISTS ONLY model.property DROP CONSTRAINT IF EXISTS property_range_class_code_fkey; ALTER TABLE IF EXISTS ONLY model.property_inheritance DROP CONSTRAINT IF EXISTS property_inheritance_super_code_fkey; ALTER TABLE IF EXISTS ONLY model.property_inheritance DROP CONSTRAINT IF EXISTS property_inheritance_sub_code_fkey; @@ -57,6 +51,12 @@ ALTER TABLE IF EXISTS ONLY model.entity DROP CONSTRAINT IF EXISTS entity_class_c ALTER TABLE IF EXISTS ONLY model.cidoc_class_inheritance DROP CONSTRAINT IF EXISTS class_inheritance_super_code_fkey; ALTER TABLE IF EXISTS ONLY model.cidoc_class_inheritance DROP CONSTRAINT IF EXISTS class_inheritance_sub_code_fkey; ALTER TABLE IF EXISTS ONLY model.cidoc_class_i18n DROP CONSTRAINT IF EXISTS class_i18n_class_code_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_user_id_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_source_id_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_entity_id_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_user_id_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_image_id_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_entity_id_fkey; ALTER TABLE IF EXISTS ONLY import.entity DROP CONSTRAINT IF EXISTS entity_user_id_fkey; ALTER TABLE IF EXISTS ONLY import.entity DROP CONSTRAINT IF EXISTS entity_project_id_fkey; ALTER TABLE IF EXISTS ONLY import.entity DROP CONSTRAINT IF EXISTS entity_entity_id_fkey; @@ -70,12 +70,12 @@ DROP TRIGGER IF EXISTS update_modified ON web.i18n; DROP TRIGGER IF EXISTS update_modified ON web.hierarchy_openatlas_class; DROP TRIGGER IF EXISTS update_modified ON web.hierarchy; DROP TRIGGER IF EXISTS update_modified ON web."group"; -DROP TRIGGER IF EXISTS update_modified ON web.annotation_text; -DROP TRIGGER IF EXISTS update_modified ON web.annotation_image; DROP TRIGGER IF EXISTS update_modified ON model.link; DROP TRIGGER IF EXISTS update_modified ON model.gis; DROP TRIGGER IF EXISTS update_modified ON model.file_info; DROP TRIGGER IF EXISTS update_modified ON model.entity; +DROP TRIGGER IF EXISTS update_modified ON model.annotation_text; +DROP TRIGGER IF EXISTS update_modified ON model.annotation_image; DROP TRIGGER IF EXISTS on_delete_entity ON model.entity; DROP TRIGGER IF EXISTS update_modified ON import.project; ALTER TABLE IF EXISTS ONLY web."user" DROP CONSTRAINT IF EXISTS user_username_key; @@ -109,8 +109,6 @@ ALTER TABLE IF EXISTS ONLY web."group" DROP CONSTRAINT IF EXISTS group_name_key; ALTER TABLE IF EXISTS ONLY web.entity_profile_image DROP CONSTRAINT IF EXISTS entity_profile_image_pkey; ALTER TABLE IF EXISTS ONLY web.entity_profile_image DROP CONSTRAINT IF EXISTS entity_profile_image_entity_id_key; ALTER TABLE IF EXISTS ONLY web.type_none_selectable DROP CONSTRAINT IF EXISTS entity_id_key; -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_pkey; -ALTER TABLE IF EXISTS ONLY web.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_pkey; ALTER TABLE IF EXISTS ONLY model.property DROP CONSTRAINT IF EXISTS property_pkey; ALTER TABLE IF EXISTS ONLY model.property_inheritance DROP CONSTRAINT IF EXISTS property_inheritance_pkey; ALTER TABLE IF EXISTS ONLY model.property_i18n DROP CONSTRAINT IF EXISTS property_i18n_property_code_language_code_key; @@ -130,6 +128,8 @@ ALTER TABLE IF EXISTS ONLY model.cidoc_class_inheritance DROP CONSTRAINT IF EXIS ALTER TABLE IF EXISTS ONLY model.cidoc_class_i18n DROP CONSTRAINT IF EXISTS class_i18n_pkey; ALTER TABLE IF EXISTS ONLY model.cidoc_class_i18n DROP CONSTRAINT IF EXISTS class_i18n_class_code_language_code_key; ALTER TABLE IF EXISTS ONLY model.cidoc_class DROP CONSTRAINT IF EXISTS class_code_key; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_pkey; +ALTER TABLE IF EXISTS ONLY model.annotation_image DROP CONSTRAINT IF EXISTS annotation_image_pkey; ALTER TABLE IF EXISTS ONLY import.project DROP CONSTRAINT IF EXISTS project_pkey; ALTER TABLE IF EXISTS ONLY import.project DROP CONSTRAINT IF EXISTS project_name_key; ALTER TABLE IF EXISTS ONLY import.entity DROP CONSTRAINT IF EXISTS entity_project_id_origin_id_key; @@ -139,6 +139,7 @@ ALTER TABLE IF EXISTS web.user_notes ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web.user_log ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web.user_bookmarks ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web."user" ALTER COLUMN id DROP DEFAULT; +ALTER TABLE IF EXISTS web.type_none_selectable ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web.system_log ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web.settings ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web.reference_system_openatlas_class ALTER COLUMN id DROP DEFAULT; @@ -148,7 +149,6 @@ ALTER TABLE IF EXISTS web.hierarchy_openatlas_class ALTER COLUMN id DROP DEFAULT ALTER TABLE IF EXISTS web.hierarchy ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web."group" ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS web.entity_profile_image ALTER COLUMN id DROP DEFAULT; -ALTER TABLE IF EXISTS web.annotation_image ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS model.property_inheritance ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS model.property_i18n ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS model.property ALTER COLUMN id DROP DEFAULT; @@ -159,6 +159,7 @@ ALTER TABLE IF EXISTS model.entity ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS model.cidoc_class_inheritance ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS model.cidoc_class_i18n ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS model.cidoc_class ALTER COLUMN id DROP DEFAULT; +ALTER TABLE IF EXISTS model.annotation_image ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS import.project ALTER COLUMN id DROP DEFAULT; ALTER TABLE IF EXISTS import.entity ALTER COLUMN id DROP DEFAULT; DROP SEQUENCE IF EXISTS web.user_settings_id_seq; @@ -171,8 +172,8 @@ DROP SEQUENCE IF EXISTS web.user_id_seq; DROP SEQUENCE IF EXISTS web.user_bookmarks_id_seq; DROP TABLE IF EXISTS web.user_bookmarks; DROP TABLE IF EXISTS web."user"; -DROP TABLE IF EXISTS web.type_none_selectable; DROP SEQUENCE IF EXISTS web.type_none_selectable_id_seq; +DROP TABLE IF EXISTS web.type_none_selectable; DROP SEQUENCE IF EXISTS web.settings_id_seq; DROP TABLE IF EXISTS web.settings; DROP SEQUENCE IF EXISTS web.reference_system_form_id_seq; @@ -192,10 +193,6 @@ DROP SEQUENCE IF EXISTS web.group_id_seq; DROP TABLE IF EXISTS web."group"; DROP SEQUENCE IF EXISTS web.entity_profile_image_id_seq; DROP TABLE IF EXISTS web.entity_profile_image; -DROP TABLE IF EXISTS web.annotation_text; -DROP SEQUENCE IF EXISTS web.annotation_text_id_seq; -DROP SEQUENCE IF EXISTS web.annotation_image_id_seq; -DROP TABLE IF EXISTS web.annotation_image; DROP SEQUENCE IF EXISTS model.property_inheritance_id_seq; DROP TABLE IF EXISTS model.property_inheritance; DROP SEQUENCE IF EXISTS model.property_id_seq; @@ -218,6 +215,10 @@ DROP SEQUENCE IF EXISTS model.cidoc_class_id_seq; DROP SEQUENCE IF EXISTS model.cidoc_class_i18n_id_seq; DROP TABLE IF EXISTS model.cidoc_class_i18n; DROP TABLE IF EXISTS model.cidoc_class; +DROP TABLE IF EXISTS model.annotation_text; +DROP SEQUENCE IF EXISTS model.annotation_text_id_seq; +DROP SEQUENCE IF EXISTS model.annotation_image_id_seq; +DROP TABLE IF EXISTS model.annotation_image; DROP SEQUENCE IF EXISTS import.project_id_seq; DROP TABLE IF EXISTS import.project; DROP SEQUENCE IF EXISTS import.entity_id_seq; @@ -403,6 +404,78 @@ ALTER TABLE import.project_id_seq OWNER TO openatlas; ALTER SEQUENCE import.project_id_seq OWNED BY import.project.id; +-- +-- Name: annotation_image; Type: TABLE; Schema: model; Owner: openatlas +-- + +CREATE TABLE model.annotation_image ( + id integer NOT NULL, + image_id integer NOT NULL, + entity_id integer, + coordinates text NOT NULL, + user_id integer, + text text, + created timestamp without time zone DEFAULT now() NOT NULL, + modified timestamp without time zone +); + + +ALTER TABLE model.annotation_image OWNER TO openatlas; + +-- +-- Name: annotation_image_id_seq; Type: SEQUENCE; Schema: model; Owner: openatlas +-- + +CREATE SEQUENCE model.annotation_image_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE model.annotation_image_id_seq OWNER TO openatlas; + +-- +-- Name: annotation_image_id_seq; Type: SEQUENCE OWNED BY; Schema: model; Owner: openatlas +-- + +ALTER SEQUENCE model.annotation_image_id_seq OWNED BY model.annotation_image.id; + + +-- +-- Name: annotation_text_id_seq; Type: SEQUENCE; Schema: web; Owner: openatlas +-- + +CREATE SEQUENCE model.annotation_text_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + MAXVALUE 2147483647 + CACHE 1; + + +ALTER TABLE model.annotation_text_id_seq OWNER TO openatlas; + +-- +-- Name: annotation_text; Type: TABLE; Schema: model; Owner: openatlas +-- + +CREATE TABLE model.annotation_text ( + id integer DEFAULT nextval('model.annotation_text_id_seq'::regclass) NOT NULL, + source_id integer NOT NULL, + entity_id integer, + link_start integer NOT NULL, + link_end integer NOT NULL, + user_id integer, + text text, + created timestamp without time zone DEFAULT now() NOT NULL, + modified timestamp without time zone +); + + +ALTER TABLE model.annotation_text OWNER TO openatlas; + -- -- Name: cidoc_class; Type: TABLE; Schema: model; Owner: openatlas -- @@ -738,6 +811,7 @@ COMMENT ON COLUMN model.openatlas_class.layout_icon IS 'For Bootstrap icons'; -- CREATE SEQUENCE model.openatlas_class_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -862,78 +936,6 @@ ALTER TABLE model.property_inheritance_id_seq OWNER TO openatlas; ALTER SEQUENCE model.property_inheritance_id_seq OWNED BY model.property_inheritance.id; --- --- Name: annotation_image; Type: TABLE; Schema: web; Owner: openatlas --- - -CREATE TABLE web.annotation_image ( - id integer NOT NULL, - image_id integer NOT NULL, - entity_id integer, - coordinates text NOT NULL, - user_id integer, - text text, - created timestamp without time zone DEFAULT now() NOT NULL, - modified timestamp without time zone -); - - -ALTER TABLE web.annotation_image OWNER TO openatlas; - --- --- Name: annotation_image_id_seq; Type: SEQUENCE; Schema: web; Owner: openatlas --- - -CREATE SEQUENCE web.annotation_image_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE web.annotation_image_id_seq OWNER TO openatlas; - --- --- Name: annotation_image_id_seq; Type: SEQUENCE OWNED BY; Schema: web; Owner: openatlas --- - -ALTER SEQUENCE web.annotation_image_id_seq OWNED BY web.annotation_image.id; - - --- --- Name: annotation_text_id_seq; Type: SEQUENCE; Schema: web; Owner: openatlas --- - -CREATE SEQUENCE web.annotation_text_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - MAXVALUE 2147483647 - CACHE 1; - - -ALTER TABLE web.annotation_text_id_seq OWNER TO openatlas; - --- --- Name: annotation_text; Type: TABLE; Schema: web; Owner: openatlas --- - -CREATE TABLE web.annotation_text ( - id integer DEFAULT nextval('web.annotation_text_id_seq'::regclass) NOT NULL, - source_id integer NOT NULL, - entity_id integer, - link_start integer NOT NULL, - link_end integer NOT NULL, - user_id integer, - text text, - created timestamp without time zone DEFAULT now() NOT NULL, - modified timestamp without time zone -); - - -ALTER TABLE web.annotation_text OWNER TO openatlas; - -- -- Name: entity_profile_image; Type: TABLE; Schema: web; Owner: openatlas -- @@ -1016,7 +1018,8 @@ CREATE TABLE web.hierarchy ( created timestamp without time zone DEFAULT now() NOT NULL, modified timestamp without time zone, category text DEFAULT 'standard'::text NOT NULL, - required boolean DEFAULT false NOT NULL + required boolean DEFAULT false NOT NULL, + allow_top_level_selection boolean DEFAULT true ); @@ -1247,6 +1250,7 @@ ALTER TABLE web.reference_system_openatlas_class OWNER TO openatlas; -- CREATE SEQUENCE web.reference_system_form_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1297,26 +1301,12 @@ ALTER TABLE web.settings_id_seq OWNER TO openatlas; ALTER SEQUENCE web.settings_id_seq OWNED BY web.settings.id; --- --- Name: type_none_selectable_id_seq; Type: SEQUENCE; Schema: web; Owner: openatlas --- - -CREATE SEQUENCE web.type_none_selectable_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - MAXVALUE 2147483647 - CACHE 1; - - -ALTER TABLE web.type_none_selectable_id_seq OWNER TO openatlas; - -- -- Name: type_none_selectable; Type: TABLE; Schema: web; Owner: openatlas -- CREATE TABLE web.type_none_selectable ( - id integer DEFAULT nextval('web.type_none_selectable_id_seq'::regclass) NOT NULL, + id integer NOT NULL, entity_id integer NOT NULL, created timestamp without time zone DEFAULT now() NOT NULL ); @@ -1328,7 +1318,29 @@ ALTER TABLE web.type_none_selectable OWNER TO openatlas; -- Name: TABLE type_none_selectable; Type: COMMENT; Schema: web; Owner: openatlas -- -COMMENT ON TABLE web.type_none_selectable IS 'IDs of types that are not meant to be selected, e.g. a category'; +COMMENT ON TABLE web.type_none_selectable IS 'IDs of types that are not for selection, e.g. a category'; + + +-- +-- Name: type_none_selectable_id_seq; Type: SEQUENCE; Schema: web; Owner: openatlas +-- + +CREATE SEQUENCE web.type_none_selectable_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE web.type_none_selectable_id_seq OWNER TO openatlas; + +-- +-- Name: type_none_selectable_id_seq; Type: SEQUENCE OWNED BY; Schema: web; Owner: openatlas +-- + +ALTER SEQUENCE web.type_none_selectable_id_seq OWNED BY web.type_none_selectable.id; -- @@ -1539,6 +1551,13 @@ ALTER TABLE ONLY import.entity ALTER COLUMN id SET DEFAULT nextval('import.entit ALTER TABLE ONLY import.project ALTER COLUMN id SET DEFAULT nextval('import.project_id_seq'::regclass); +-- +-- Name: annotation_image id; Type: DEFAULT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_image ALTER COLUMN id SET DEFAULT nextval('model.annotation_image_id_seq'::regclass); + + -- -- Name: cidoc_class id; Type: DEFAULT; Schema: model; Owner: openatlas -- @@ -1609,13 +1628,6 @@ ALTER TABLE ONLY model.property_i18n ALTER COLUMN id SET DEFAULT nextval('model. ALTER TABLE ONLY model.property_inheritance ALTER COLUMN id SET DEFAULT nextval('model.property_inheritance_id_seq'::regclass); --- --- Name: annotation_image id; Type: DEFAULT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_image ALTER COLUMN id SET DEFAULT nextval('web.annotation_image_id_seq'::regclass); - - -- -- Name: entity_profile_image id; Type: DEFAULT; Schema: web; Owner: openatlas -- @@ -1679,6 +1691,13 @@ ALTER TABLE ONLY web.settings ALTER COLUMN id SET DEFAULT nextval('web.settings_ ALTER TABLE ONLY web.system_log ALTER COLUMN id SET DEFAULT nextval('web.log_id_seq'::regclass); +-- +-- Name: type_none_selectable id; Type: DEFAULT; Schema: web; Owner: openatlas +-- + +ALTER TABLE ONLY web.type_none_selectable ALTER COLUMN id SET DEFAULT nextval('web.type_none_selectable_id_seq'::regclass); + + -- -- Name: user id; Type: DEFAULT; Schema: web; Owner: openatlas -- @@ -1746,6 +1765,22 @@ ALTER TABLE ONLY import.project ADD CONSTRAINT project_pkey PRIMARY KEY (id); +-- +-- Name: annotation_image annotation_image_pkey; Type: CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_image + ADD CONSTRAINT annotation_image_pkey PRIMARY KEY (id); + + +-- +-- Name: annotation_text annotation_text_pkey; Type: CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_text + ADD CONSTRAINT annotation_text_pkey PRIMARY KEY (id); + + -- -- Name: cidoc_class class_code_key; Type: CONSTRAINT; Schema: model; Owner: openatlas -- @@ -1898,22 +1933,6 @@ ALTER TABLE ONLY model.property ADD CONSTRAINT property_pkey PRIMARY KEY (id); --- --- Name: annotation_image annotation_image_pkey; Type: CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_image - ADD CONSTRAINT annotation_image_pkey PRIMARY KEY (id); - - --- --- Name: annotation_text annotation_text_pkey; Type: CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_text - ADD CONSTRAINT annotation_text_pkey PRIMARY KEY (id); - - -- -- Name: type_none_selectable entity_id_key; Type: CONSTRAINT; Schema: web; Owner: openatlas -- @@ -2177,45 +2196,45 @@ CREATE TRIGGER on_delete_entity BEFORE DELETE ON model.entity FOR EACH ROW EXECU -- --- Name: entity update_modified; Type: TRIGGER; Schema: model; Owner: openatlas +-- Name: annotation_image update_modified; Type: TRIGGER; Schema: model; Owner: openatlas -- -CREATE TRIGGER update_modified BEFORE UPDATE ON model.entity FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +CREATE TRIGGER update_modified BEFORE UPDATE ON model.annotation_image FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -- --- Name: file_info update_modified; Type: TRIGGER; Schema: model; Owner: openatlas +-- Name: annotation_text update_modified; Type: TRIGGER; Schema: model; Owner: openatlas -- -CREATE TRIGGER update_modified BEFORE UPDATE ON model.file_info FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +CREATE TRIGGER update_modified BEFORE UPDATE ON model.annotation_text FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -- --- Name: gis update_modified; Type: TRIGGER; Schema: model; Owner: openatlas +-- Name: entity update_modified; Type: TRIGGER; Schema: model; Owner: openatlas -- -CREATE TRIGGER update_modified BEFORE UPDATE ON model.gis FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +CREATE TRIGGER update_modified BEFORE UPDATE ON model.entity FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -- --- Name: link update_modified; Type: TRIGGER; Schema: model; Owner: openatlas +-- Name: file_info update_modified; Type: TRIGGER; Schema: model; Owner: openatlas -- -CREATE TRIGGER update_modified BEFORE UPDATE ON model.link FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +CREATE TRIGGER update_modified BEFORE UPDATE ON model.file_info FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -- --- Name: annotation_image update_modified; Type: TRIGGER; Schema: web; Owner: openatlas +-- Name: gis update_modified; Type: TRIGGER; Schema: model; Owner: openatlas -- -CREATE TRIGGER update_modified BEFORE UPDATE ON web.annotation_image FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +CREATE TRIGGER update_modified BEFORE UPDATE ON model.gis FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -- --- Name: annotation_text update_modified; Type: TRIGGER; Schema: web; Owner: openatlas +-- Name: link update_modified; Type: TRIGGER; Schema: model; Owner: openatlas -- -CREATE TRIGGER update_modified BEFORE UPDATE ON web.annotation_text FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +CREATE TRIGGER update_modified BEFORE UPDATE ON model.link FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -- @@ -2312,6 +2331,54 @@ ALTER TABLE ONLY import.entity ADD CONSTRAINT entity_user_id_fkey FOREIGN KEY (user_id) REFERENCES web."user"(id) ON UPDATE CASCADE ON DELETE CASCADE; +-- +-- Name: annotation_image annotation_image_entity_id_fkey; Type: FK CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_image + ADD CONSTRAINT annotation_image_entity_id_fkey FOREIGN KEY (entity_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE SET NULL; + + +-- +-- Name: annotation_image annotation_image_image_id_fkey; Type: FK CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_image + ADD CONSTRAINT annotation_image_image_id_fkey FOREIGN KEY (image_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: annotation_image annotation_image_user_id_fkey; Type: FK CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_image + ADD CONSTRAINT annotation_image_user_id_fkey FOREIGN KEY (user_id) REFERENCES web."user"(id) ON UPDATE CASCADE ON DELETE SET NULL; + + +-- +-- Name: annotation_text annotation_text_entity_id_fkey; Type: FK CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_text + ADD CONSTRAINT annotation_text_entity_id_fkey FOREIGN KEY (entity_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE SET NULL; + + +-- +-- Name: annotation_text annotation_text_source_id_fkey; Type: FK CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_text + ADD CONSTRAINT annotation_text_source_id_fkey FOREIGN KEY (source_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: annotation_text annotation_text_user_id_fkey; Type: FK CONSTRAINT; Schema: model; Owner: openatlas +-- + +ALTER TABLE ONLY model.annotation_text + ADD CONSTRAINT annotation_text_user_id_fkey FOREIGN KEY (user_id) REFERENCES web."user"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + -- -- Name: cidoc_class_i18n class_i18n_class_code_fkey; Type: FK CONSTRAINT; Schema: model; Owner: openatlas -- @@ -2464,54 +2531,6 @@ ALTER TABLE ONLY model.property ADD CONSTRAINT property_range_class_code_fkey FOREIGN KEY (range_class_code) REFERENCES model.cidoc_class(code) ON UPDATE CASCADE ON DELETE CASCADE; --- --- Name: annotation_image annotation_image_entity_id_fkey; Type: FK CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_image - ADD CONSTRAINT annotation_image_entity_id_fkey FOREIGN KEY (entity_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- Name: annotation_image annotation_image_image_id_fkey; Type: FK CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_image - ADD CONSTRAINT annotation_image_image_id_fkey FOREIGN KEY (image_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: annotation_image annotation_image_user_id_fkey; Type: FK CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_image - ADD CONSTRAINT annotation_image_user_id_fkey FOREIGN KEY (user_id) REFERENCES web."user"(id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- Name: annotation_text annotation_text_entity_id_fkey; Type: FK CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_text - ADD CONSTRAINT annotation_text_entity_id_fkey FOREIGN KEY (entity_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: annotation_text annotation_text_source_id_fkey; Type: FK CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_text - ADD CONSTRAINT annotation_text_source_id_fkey FOREIGN KEY (source_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: annotation_text annotation_text_user_id_fkey; Type: FK CONSTRAINT; Schema: web; Owner: openatlas --- - -ALTER TABLE ONLY web.annotation_text - ADD CONSTRAINT annotation_text_user_id_fkey FOREIGN KEY (user_id) REFERENCES web."user"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - -- -- Name: entity_profile_image entity_profile_image_entity_id_fkey; Type: FK CONSTRAINT; Schema: web; Owner: openatlas -- diff --git a/install/upgrade/text_annotation.sql b/install/upgrade/text_annotation.sql index 012f56e0d..c0f07cbb1 100644 --- a/install/upgrade/text_annotation.sql +++ b/install/upgrade/text_annotation.sql @@ -3,25 +3,26 @@ BEGIN; -- #2079: Text annotation -- Sync image annotation fields to text annotation fields -ALTER TABLE web.annotation_image RENAME COLUMN annotation TO text; -ALTER TABLE web.annotation_image ALTER COLUMN text DROP NOT NULL; -ALTER TABLE web.annotation_image ADD COLUMN modified timestamp without time zone; -CREATE TRIGGER update_modified BEFORE UPDATE ON web.annotation_image FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +ALTER TABLE web.annotation_image SET SCHEMA model; +ALTER TABLE model.annotation_image RENAME COLUMN annotation TO text; +ALTER TABLE model.annotation_image ALTER COLUMN text DROP NOT NULL; +ALTER TABLE model.annotation_image ADD COLUMN modified timestamp without time zone; +CREATE TRIGGER update_modified BEFORE UPDATE ON model.annotation_image FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -- Text annotation -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_user_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_source_id_fkey; -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_entity_id_fkey; -DROP TRIGGER IF EXISTS update_modified ON web.annotation_text; -ALTER TABLE IF EXISTS ONLY web.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_pkey; -DROP TABLE IF EXISTS web.annotation_text; -DROP SEQUENCE IF EXISTS web.annotation_text_id_seq; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_user_id_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_source_id_fkey; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_entity_id_fkey; +DROP TRIGGER IF EXISTS update_modified ON model.annotation_text; +ALTER TABLE IF EXISTS ONLY model.annotation_text DROP CONSTRAINT IF EXISTS annotation_text_pkey; +DROP TABLE IF EXISTS model.annotation_text; +DROP SEQUENCE IF EXISTS model.annotation_text_id_seq; -CREATE SEQUENCE web.annotation_text_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE MAXVALUE 2147483647 CACHE 1; -ALTER TABLE web.annotation_text_id_seq OWNER TO openatlas; +CREATE SEQUENCE model.annotation_text_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE MAXVALUE 2147483647 CACHE 1; +ALTER TABLE model.annotation_text_id_seq OWNER TO openatlas; -CREATE TABLE web.annotation_text ( - id integer DEFAULT nextval('web.annotation_text_id_seq'::regclass) NOT NULL, +CREATE TABLE model.annotation_text ( + id integer DEFAULT nextval('model.annotation_text_id_seq'::regclass) NOT NULL, source_id integer NOT NULL, entity_id integer, link_start integer NOT NULL, @@ -31,12 +32,12 @@ CREATE TABLE web.annotation_text ( created timestamp without time zone DEFAULT now() NOT NULL, modified timestamp without time zone ); -ALTER TABLE web.annotation_text OWNER TO openatlas; +ALTER TABLE model.annotation_text OWNER TO openatlas; -ALTER TABLE ONLY web.annotation_text ADD CONSTRAINT annotation_text_pkey PRIMARY KEY (id); -CREATE TRIGGER update_modified BEFORE UPDATE ON web.annotation_text FOR EACH ROW EXECUTE FUNCTION model.update_modified(); -ALTER TABLE ONLY web.annotation_text ADD CONSTRAINT annotation_text_entity_id_fkey FOREIGN KEY (entity_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE ONLY web.annotation_text ADD CONSTRAINT annotation_text_source_id_fkey FOREIGN KEY (source_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE ONLY web.annotation_text ADD CONSTRAINT annotation_text_user_id_fkey FOREIGN KEY (user_id) REFERENCES web."user"(id) ON UPDATE CASCADE ON DELETE CASCADE; +ALTER TABLE ONLY model.annotation_text ADD CONSTRAINT annotation_text_pkey PRIMARY KEY (id); +CREATE TRIGGER update_modified BEFORE UPDATE ON model.annotation_text FOR EACH ROW EXECUTE FUNCTION model.update_modified(); +ALTER TABLE ONLY model.annotation_text ADD CONSTRAINT annotation_text_entity_id_fkey FOREIGN KEY (entity_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; +ALTER TABLE ONLY model.annotation_text ADD CONSTRAINT annotation_text_source_id_fkey FOREIGN KEY (source_id) REFERENCES model.entity(id) ON UPDATE CASCADE ON DELETE CASCADE; +ALTER TABLE ONLY model.annotation_text ADD CONSTRAINT annotation_text_user_id_fkey FOREIGN KEY (user_id) REFERENCES web."user"(id) ON UPDATE CASCADE ON DELETE CASCADE; END; diff --git a/openatlas/database/annotation.py b/openatlas/database/annotation.py index b4be486ce..b2459460a 100644 --- a/openatlas/database/annotation.py +++ b/openatlas/database/annotation.py @@ -12,7 +12,7 @@ user_id, text, created - FROM web.annotation_image + FROM model.annotation_image """ ANNOTATION_TEXT_SELECT = \ @@ -26,7 +26,7 @@ user_id, text, created - FROM web.annotation_text + FROM model.annotation_text """ @@ -73,7 +73,7 @@ def get_annotation_image_orphans() -> list[dict[str, Any]]: a.user_id, a.text, a.created - FROM web.annotation_image a + FROM model.annotation_image a LEFT JOIN model.link l ON l.domain_id = a.image_id AND l.range_id = a.entity_id AND l.property_code = 'P67' @@ -85,7 +85,7 @@ def get_annotation_image_orphans() -> list[dict[str, Any]]: def insert_annotation_image(data: dict[str, Any]) -> None: g.cursor.execute( """ - INSERT INTO web.annotation_image ( + INSERT INTO model.annotation_image ( image_id, entity_id, coordinates, @@ -104,7 +104,7 @@ def insert_annotation_image(data: dict[str, Any]) -> None: def update_annotation_image(data: dict[str, Any]) -> None: g.cursor.execute( """ - UPDATE web.annotation_image + UPDATE model.annotation_image SET (entity_id, text) = (%(entity_id)s, %(text)s) WHERE id = %(id)s; """, @@ -113,7 +113,7 @@ def update_annotation_image(data: dict[str, Any]) -> None: def delete_annotation_image(id_: int) -> None: g.cursor.execute( - 'DELETE FROM web.annotation_image WHERE id = %(id)s;', + 'DELETE FROM model.annotation_image WHERE id = %(id)s;', {'id': id_}) @@ -121,7 +121,7 @@ def update_annotation_text(data: dict[str, Any]) -> None: print(data) g.cursor.execute( """ - UPDATE web.annotation_text + UPDATE model.annotation_text SET (entity_id, text, link_start, link_end) = (%(entity_id)s, %(text)s, %(link_start)s, %(link_end)s) WHERE id = %(id)s; @@ -131,7 +131,7 @@ def update_annotation_text(data: dict[str, Any]) -> None: def delete_annotation_text(id_: int) -> None: g.cursor.execute( - 'DELETE FROM web.annotation_text WHERE id = %(id)s;', + 'DELETE FROM model.annotation_text WHERE id = %(id)s;', {'id': id_}) @@ -140,7 +140,7 @@ def remove_entity_from_annotation_image( entity_id: int) -> None: g.cursor.execute( """ - UPDATE web.annotation_image + UPDATE model.annotation_image SET entity_id = NULL WHERE id = %(annotation_id)s AND entity_id = %(entity_id)s; """, @@ -150,7 +150,7 @@ def remove_entity_from_annotation_image( def insert_annotation_text(data: dict[str, Any]) -> None: g.cursor.execute( """ - INSERT INTO web.annotation_text ( + INSERT INTO model.annotation_text ( source_id, entity_id, link_start,