Skip to content
Snippets Groups Projects
schema-094.sql 46.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • SET standard_conforming_strings = off;
    
    SET check_function_bodies = false;
    SET client_min_messages = warning;
    
    SET escape_string_warning = off;
    
    6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    SET search_path = public, pg_catalog;
    CREATE DOMAIN archiving_status AS character varying(100)
    	CONSTRAINT archiving_status_check CHECK (((VALUE)::text = ANY (ARRAY[('LOCKED'::character varying)::text, ('AVAILABLE'::character varying)::text, ('ARCHIVED'::character varying)::text, ('ARCHIVE_PENDING'::character varying)::text, ('UNARCHIVE_PENDING'::character varying)::text, ('BACKUP_PENDING'::character varying)::text])));
    CREATE DOMAIN authorization_role AS character varying(40)
    	CONSTRAINT authorization_role_check CHECK (((VALUE)::text = ANY (ARRAY[('ADMIN'::character varying)::text, ('POWER_USER'::character varying)::text, ('USER'::character varying)::text, ('OBSERVER'::character varying)::text, ('ETL_SERVER'::character varying)::text])));
    CREATE DOMAIN boolean_char AS boolean DEFAULT false;
    CREATE DOMAIN boolean_char_or_unknown AS character(1) DEFAULT 'U'::bpchar
    	CONSTRAINT boolean_char_or_unknown_check CHECK ((VALUE = ANY (ARRAY['F'::bpchar, 'T'::bpchar, 'U'::bpchar])));
    CREATE DOMAIN code AS character varying(60);
    CREATE DOMAIN column_label AS character varying(128);
    CREATE DOMAIN data_store_service_kind AS character varying(40)
    	CONSTRAINT data_store_service_kind_check CHECK (((VALUE)::text = ANY (ARRAY[('PROCESSING'::character varying)::text, ('QUERIES'::character varying)::text])));
    CREATE DOMAIN data_store_service_reporting_plugin_type AS character varying(40)
    	CONSTRAINT data_store_service_reporting_plugin_type_check CHECK (((VALUE)::text = ANY (ARRAY[('TABLE_MODEL'::character varying)::text, ('DSS_LINK'::character varying)::text])));
    CREATE DOMAIN description_2000 AS character varying(2000);
    CREATE DOMAIN entity_kind AS character varying(40)
    	CONSTRAINT entity_kind_check CHECK (((VALUE)::text = ANY (ARRAY[('SAMPLE'::character varying)::text, ('EXPERIMENT'::character varying)::text, ('DATA_SET'::character varying)::text, ('MATERIAL'::character varying)::text])));
    CREATE DOMAIN event_type AS character varying(40)
    	CONSTRAINT event_type_check CHECK (((VALUE)::text = ANY (ARRAY[('DELETION'::character varying)::text, ('MOVEMENT'::character varying)::text])));
    CREATE DOMAIN file AS bytea;
    CREATE DOMAIN file_name AS character varying(100);
    CREATE DOMAIN grid_expression AS character varying(2000);
    CREATE DOMAIN grid_id AS character varying(200);
    CREATE DOMAIN object_name AS character varying(50);
    CREATE DOMAIN ordinal_int AS bigint
    	CONSTRAINT ordinal_int_check CHECK ((VALUE > 0));
    CREATE DOMAIN query_type AS character varying(40)
    	CONSTRAINT query_type_check CHECK (((VALUE)::text = ANY (ARRAY[('GENERIC'::character varying)::text, ('EXPERIMENT'::character varying)::text, ('SAMPLE'::character varying)::text, ('DATA_SET'::character varying)::text, ('MATERIAL'::character varying)::text])));
    CREATE DOMAIN real_value AS real;
    CREATE DOMAIN script_type AS character varying(40)
    	CONSTRAINT script_type_check CHECK (((VALUE)::text = ANY (ARRAY[('DYNAMIC_PROPERTY'::character varying)::text, ('MANAGED_PROPERTY'::character varying)::text])));
    CREATE DOMAIN tech_id AS bigint;
    CREATE DOMAIN text_value AS text;
    CREATE DOMAIN time_stamp AS timestamp with time zone;
    CREATE DOMAIN time_stamp_dfl AS timestamp with time zone NOT NULL DEFAULT now();
    CREATE DOMAIN title_100 AS character varying(100);
    CREATE DOMAIN user_id AS character varying(50);
    CREATE FUNCTION check_created_or_modified_data_set_owner_is_alive() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
    	owner_code	CODE;
    	owner_del_id	TECH_ID;
    BEGIN
    	IF (NEW.del_id IS NOT NULL) THEN
    		RETURN NEW;
    	END IF;
      -- check sample
      IF (NEW.samp_id IS NOT NULL) THEN
      	SELECT del_id, code INTO owner_del_id, owner_code
      	  FROM samples 
      	  WHERE id = NEW.samp_id;
      	IF (owner_del_id IS NOT NULL) THEN 
    			RAISE EXCEPTION 'Data Set (Code: %) cannot be connected to a Sample (Code: %) %.', 
    			                NEW.code, owner_code, deletion_description(owner_del_id);
    		END IF;
    	END IF;
    	-- check experiment
    	SELECT del_id, code INTO owner_del_id, owner_code
        FROM experiments 
        WHERE id = NEW.expe_id;
      IF (owner_del_id IS NOT NULL) THEN 
    		RAISE EXCEPTION 'Data Set (Code: %) cannot be connected to an Experiment (Code: %) %.', 
    		                NEW.code, owner_code, deletion_description(owner_del_id);
    	END IF;	
    	RETURN NEW;
    END;
    $$;
    CREATE FUNCTION check_created_or_modified_sample_owner_is_alive() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
    	owner_code	CODE;
    	owner_del_id	TECH_ID;
    BEGIN
    	IF (NEW.del_id IS NOT NULL) THEN
    		RETURN NEW;
    	END IF;
      -- check experiment (can't be deleted)
      IF (NEW.expe_id IS NOT NULL) THEN
      	SELECT del_id, code INTO owner_del_id, owner_code
      	  FROM experiments 
      	  WHERE id = NEW.expe_id;
      	IF (owner_del_id IS NOT NULL) THEN 
    			RAISE EXCEPTION 'Sample (Code: %) cannot be connected to an Experiment (Code: %) %.', 
       		                NEW.code, owner_code, deletion_description(owner_del_id);
    		END IF;
    	END IF;
    	RETURN NEW;
    END;
    $$;
    CREATE FUNCTION check_deletion_consistency_on_experiment_deletion() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
      counter  INTEGER;
    BEGIN
    	IF (OLD.del_id IS NOT NULL OR NEW.del_id IS NULL) THEN
    		RETURN NEW;
    	END IF;
    	
      -- check datasets
    	SELECT count(*) INTO counter 
    	  FROM data
    	  WHERE data.expe_id = NEW.id AND data.del_id IS NULL;
    	IF (counter > 0) THEN
    	  RAISE EXCEPTION 'Experiment (Code: %) deletion failed because at least one of its data sets was not deleted.', NEW.code;
    	END IF;
    	-- check samples
    	SELECT count(*) INTO counter 
    	  FROM samples 
    	  WHERE samples.expe_id = NEW.id AND samples.del_id IS NULL;
    	IF (counter > 0) THEN
    	  RAISE EXCEPTION 'Experiment (Code: %) deletion failed because at least one of its samples was not deleted.', NEW.code;
    	END IF;
    	RETURN NEW;
    END;
    $$;
    CREATE FUNCTION check_deletion_consistency_on_sample_deletion() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
      counter  INTEGER;
    BEGIN
    	IF (OLD.del_id IS NOT NULL OR NEW.del_id IS NULL) THEN
    		RETURN NEW;
    	END IF;
      -- all directly connected data sets need to be deleted
      -- check datasets
    	SELECT count(*) INTO counter 
    	  FROM data
    	  WHERE data.samp_id = NEW.id AND data.del_id IS NULL;
    	IF (counter > 0) THEN
    	  RAISE EXCEPTION 'Sample (Code: %) deletion failed because at least one of its data sets was not deleted.', NEW.code;
    	END IF;
      -- all components need to be deleted
    	SELECT count(*) INTO counter 
    	  FROM samples 
    	  WHERE samples.samp_id_part_of = NEW.id AND samples.del_id IS NULL;
    	IF (counter > 0) THEN
    	  RAISE EXCEPTION 'Sample (Code: %) deletion failed because at least one of its component samples was not deleted.', NEW.code;
    	END IF;
    	-- all children need to be deleted
    	SELECT count(*) INTO counter 
    		FROM sample_relationships sr, samples sc
    		WHERE sample_id_parent = NEW.id AND sc.id = sr.sample_id_child AND sc.del_id IS NULL;
    	IF (counter > 0) THEN
    		RAISE EXCEPTION 'Sample (Code: %) deletion failed because at least one of its child samples was not deleted.', NEW.code;
    	END IF;
    	RETURN NEW;
    END;
    $$;
    CREATE FUNCTION controlled_vocabulary_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       v_code  CODE;
    BEGIN
       select code into v_code from data_types where id = NEW.daty_id;
       -- Check if the data is of type "CONTROLLEDVOCABULARY"
       if v_code = 'CONTROLLEDVOCABULARY' then
          if NEW.covo_id IS NULL then
             RAISE EXCEPTION 'Insert/Update of Property Type (Code: %) failed, as its Data Type is CONTROLLEDVOCABULARY, but it is not linked to a Controlled Vocabulary.', NEW.code;
          end if;
       end if;
       RETURN NEW;
    END;
    $$;
    CREATE FUNCTION data_set_property_with_material_data_type_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       v_type_id  CODE;
       v_type_id_prop  CODE;
    BEGIN
       if NEW.mate_prop_id IS NOT NULL then
    			-- find material type id of the property type 
    			select pt.maty_prop_id into v_type_id_prop 
    			  from data_set_type_property_types dstpt, property_types pt 
    			 where NEW.dstpt_id = dstpt.id AND dstpt.prty_id = pt.id;
    		
    			if v_type_id_prop IS NOT NULL then
    				-- find material type id of the material which consists the entity's property value
    				select entity.maty_id into v_type_id 
    				  from materials entity
    				 where NEW.mate_prop_id = entity.id;
    				if v_type_id != v_type_id_prop then
    					RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).', 
    												 NEW.mate_prop_id, v_type_id, v_type_id_prop;
    				end if;
    			end if;
       end if;
       RETURN NEW;
    END;
    $$;
    CREATE FUNCTION deletion_description(del_id tech_id) RETURNS character varying
        LANGUAGE plpgsql
        AS $$
    DECLARE
      del_person VARCHAR;
      del_date VARCHAR;
      del_reason VARCHAR;
    BEGIN
      SELECT p.last_name || ' ' || p.first_name || ' (' || p.email || ')', 
             to_char(d.registration_timestamp, 'YYYY-MM-DD HH:MM:SS'), d.reason 
        INTO del_person, del_date, del_reason FROM deletions d, persons p 
        WHERE d.pers_id_registerer = p.id AND d.id = del_id;
      RETURN 'deleted by ' || del_person || ' on ' || del_date || ' with reason: "' || del_reason || '"';
    END;
    $$;
    CREATE FUNCTION experiment_property_with_material_data_type_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       v_type_id  CODE;
       v_type_id_prop  CODE;
    BEGIN
       if NEW.mate_prop_id IS NOT NULL then
    			-- find material type id of the property type 
    			select pt.maty_prop_id into v_type_id_prop 
    			  from experiment_type_property_types etpt, property_types pt 
    			 where NEW.etpt_id = etpt.id AND etpt.prty_id = pt.id;
    		
    			if v_type_id_prop IS NOT NULL then
    				-- find material type id of the material which consists the entity's property value
    				select entity.maty_id into v_type_id 
    				  from materials entity
    				 where NEW.mate_prop_id = entity.id;
    				if v_type_id != v_type_id_prop then
    					RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).', 
    												 NEW.mate_prop_id, v_type_id, v_type_id_prop;
    				end if;
    			end if;
       end if;
       RETURN NEW;
    END;
    $$;
    CREATE FUNCTION external_data_storage_format_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       v_covo_code  CODE;
       data_code CODE;
    BEGIN
       select code into v_covo_code from controlled_vocabularies
          where is_internal_namespace = true and 
             id = (select covo_id from controlled_vocabulary_terms where id = NEW.cvte_id_stor_fmt);
       -- Check if the data storage format is a term of the controlled vocabulary "STORAGE_FORMAT"
       if v_covo_code != 'STORAGE_FORMAT' then
          select code into data_code from data_all where id = NEW.data_id; 
          RAISE EXCEPTION 'Insert/Update of Data (Code: %) failed, as its Storage Format is %, but is required to be STORAGE_FORMAT.', data_code, v_covo_code;
       end if;
       RETURN NEW;
    END;
    $$;
    CREATE FUNCTION material_property_with_material_data_type_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       v_type_id  CODE;
       v_type_id_prop  CODE;
    BEGIN
       if NEW.mate_prop_id IS NOT NULL then
    			-- find material type id of the property type 
    			select pt.maty_prop_id into v_type_id_prop 
    			  from material_type_property_types etpt, property_types pt 
    			 where NEW.mtpt_id = etpt.id AND etpt.prty_id = pt.id;
    		
    			if v_type_id_prop IS NOT NULL then
    				-- find material type id of the material which consists the entity's property value
    				select entity.maty_id into v_type_id 
    				  from materials entity
    				 where NEW.mate_prop_id = entity.id;
    				if v_type_id != v_type_id_prop then
    					RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).', 
    							 NEW.mate_prop_id, v_type_id, v_type_id_prop;
    				end if;
    			end if;
       end if;
       RETURN NEW;
    END;
    $$;
    CREATE FUNCTION rename_sequence(old_name character varying, new_name character varying) RETURNS integer
        LANGUAGE plpgsql
        AS $$
    DECLARE
      CURR_SEQ_VAL   INTEGER;
    BEGIN
      SELECT INTO CURR_SEQ_VAL NEXTVAL(OLD_NAME);
      EXECUTE 'CREATE SEQUENCE ' || NEW_NAME || ' START WITH ' || CURR_SEQ_VAL;
      EXECUTE 'DROP SEQUENCE ' || OLD_NAME;
      RETURN CURR_SEQ_VAL;
    END;
    $$;
    CREATE FUNCTION sample_code_uniqueness_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       counter  INTEGER;
    BEGIN
      LOCK TABLE samples_all IN EXCLUSIVE MODE;
      
    	  IF (NEW.samp_id_part_of is NULL) THEN
    		  IF (NEW.dbin_id is not NULL) THEN
    			  SELECT count(*) into counter FROM samples_all 
    		      where id != NEW.id and code = NEW.code and samp_id_part_of is NULL and dbin_id = NEW.dbin_id;
            IF (counter > 0) THEN
    				  RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample with the same code already exists.', NEW.code;
            END IF;
    		  ELSIF (NEW.space_id is not NULL) THEN
    			  SELECT count(*) into counter FROM samples_all 
    				  where id != NEW.id and code = NEW.code and samp_id_part_of is NULL and space_id = NEW.space_id;
    			  IF (counter > 0) THEN
    				  RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because space sample with the same code already exists.', NEW.code;
    			  END IF;
          END IF;
        ELSE
    		  IF (NEW.dbin_id is not NULL) THEN
    			  SELECT count(*) into counter FROM samples_all 
    				  where id != NEW.id and code = NEW.code and samp_id_part_of = NEW.samp_id_part_of and dbin_id = NEW.dbin_id;
    			  IF (counter > 0) THEN
    				  RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample with the same code and being the part of the same container already exists.', NEW.code;
    			  END IF;
    		  ELSIF (NEW.space_id is not NULL) THEN
    			  SELECT count(*) into counter FROM samples_all 
    				  where id != NEW.id and code = NEW.code and samp_id_part_of = NEW.samp_id_part_of and space_id = NEW.space_id;
    			  IF (counter > 0) THEN
    				  RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because space sample with the same code and being the part of the same container already exists.', NEW.code;
    			  END IF;
    		  END IF;
         END IF;   
      
      RETURN NEW;
    END;
    $$;
    CREATE FUNCTION sample_property_with_material_data_type_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       v_type_id  CODE;
       v_type_id_prop  CODE;
    BEGIN
       if NEW.mate_prop_id IS NOT NULL then
    			-- find material type id of the property type 
    			select pt.maty_prop_id into v_type_id_prop 
    			  from sample_type_property_types etpt, property_types pt 
    			 where NEW.stpt_id = etpt.id AND etpt.prty_id = pt.id;
    		
    			if v_type_id_prop IS NOT NULL then
    				-- find material type id of the material which consists the entity's property value
    				select entity.maty_id into v_type_id 
    				  from materials entity
    				 where NEW.mate_prop_id = entity.id;
    				if v_type_id != v_type_id_prop then
    					RAISE EXCEPTION 'Insert/Update of property value referencing material (id: %) failed, as referenced material type is different than expected (id %, expected id: %).', 
    												 NEW.mate_prop_id, v_type_id, v_type_id_prop;
    				end if;
    			end if;
       end if;
       RETURN NEW;
    END;
    $$;
    CREATE FUNCTION sample_subcode_uniqueness_check() RETURNS trigger
        LANGUAGE plpgsql
        AS $$
    DECLARE
       counter  INTEGER;
       unique_subcode  BOOLEAN_CHAR;
    BEGIN
      LOCK TABLE samples_all IN EXCLUSIVE MODE;
      
      SELECT is_subcode_unique into unique_subcode FROM sample_types WHERE id = NEW.saty_id;
      
      IF (unique_subcode) THEN
        IF (NEW.dbin_id is not NULL) THEN
    			SELECT count(*) into counter FROM samples_all 
    				where id != NEW.id and code = NEW.code and saty_id = NEW.saty_id and dbin_id = NEW.dbin_id;
    			IF (counter > 0) THEN
    				RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample of the same type with the same subcode already exists.', NEW.code;
    			END IF;
    		ELSIF (NEW.space_id is not NULL) THEN
    			SELECT count(*) into counter FROM samples_all 
    				where id != NEW.id and code = NEW.code and saty_id = NEW.saty_id and space_id = NEW.space_id;
    			IF (counter > 0) THEN
    				RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because space sample of the same type with the same subcode already exists.', NEW.code;
    			END IF;
    		END IF;
      END IF;
      
      RETURN NEW;
    END;
    $$;
    CREATE SEQUENCE attachment_content_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('attachment_content_id_seq', 8, true);
    SET default_tablespace = '';
    SET default_with_oids = false;
    CREATE TABLE attachment_contents (
        id tech_id NOT NULL,
        value file NOT NULL
    );
    CREATE SEQUENCE attachment_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('attachment_id_seq', 8, true);
    CREATE TABLE attachments (
        id tech_id NOT NULL,
        expe_id tech_id,
        file_name file_name NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        version integer NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        exac_id tech_id NOT NULL,
        samp_id tech_id,
        proj_id tech_id,
        title title_100,
        description description_2000,
        CONSTRAINT atta_arc_ck CHECK ((((((expe_id IS NOT NULL) AND (proj_id IS NULL)) AND (samp_id IS NULL)) OR (((expe_id IS NULL) AND (proj_id IS NOT NULL)) AND (samp_id IS NULL))) OR (((expe_id IS NULL) AND (proj_id IS NULL)) AND (samp_id IS NOT NULL))))
    );
    CREATE SEQUENCE authorization_group_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('authorization_group_id_seq', 1, false);
    CREATE TABLE authorization_group_persons (
        ag_id tech_id NOT NULL,
        pers_id tech_id NOT NULL
    );
    CREATE TABLE authorization_groups (
        id tech_id NOT NULL,
        dbin_id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now()
    );
    CREATE SEQUENCE code_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('code_seq', 1, false);
    CREATE TABLE controlled_vocabularies (
        id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        is_managed_internally boolean_char DEFAULT false NOT NULL,
        is_internal_namespace boolean_char DEFAULT false NOT NULL,
        dbin_id tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        is_chosen_from_list boolean_char DEFAULT true NOT NULL,
        source_uri character varying(250)
    );
    CREATE SEQUENCE controlled_vocabulary_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('controlled_vocabulary_id_seq', 5, true);
    CREATE TABLE controlled_vocabulary_terms (
        id tech_id NOT NULL,
        code object_name NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        covo_id tech_id NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        label column_label,
        description description_2000,
        ordinal ordinal_int NOT NULL,
        is_official boolean_char DEFAULT true NOT NULL,
        CONSTRAINT cvte_ck CHECK (((ordinal)::bigint > 0))
    );
    CREATE SEQUENCE core_plugin_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('core_plugin_id_seq', 1, false);
    CREATE TABLE core_plugins (
        id tech_id NOT NULL,
        name character varying(200) NOT NULL,
        version integer NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        master_reg_script text_value
    );
    CREATE SEQUENCE cvte_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('cvte_id_seq', 15, true);
    CREATE TABLE data_all (
        id tech_id NOT NULL,
        code code,
        dsty_id tech_id NOT NULL,
        data_producer_code code,
        production_timestamp time_stamp,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        is_placeholder boolean_char DEFAULT false,
        is_valid boolean_char DEFAULT true,
        modification_timestamp time_stamp DEFAULT now(),
        expe_id tech_id NOT NULL,
        dast_id tech_id NOT NULL,
        is_derived boolean_char NOT NULL,
        samp_id tech_id,
        pers_id_registerer tech_id,
        ctnr_order integer,
        ctnr_id tech_id DEFAULT NULL::bigint,
        del_id tech_id
    );
    CREATE VIEW data AS
        SELECT data_all.id, data_all.code, data_all.dsty_id, data_all.dast_id, data_all.expe_id, data_all.data_producer_code, data_all.production_timestamp, data_all.samp_id, data_all.registration_timestamp, data_all.pers_id_registerer, data_all.is_placeholder, data_all.is_valid, data_all.modification_timestamp, data_all.is_derived, data_all.ctnr_order, data_all.ctnr_id, data_all.del_id FROM data_all WHERE (data_all.del_id IS NULL);
    CREATE VIEW data_deleted AS
        SELECT data_all.id, data_all.code, data_all.dsty_id, data_all.dast_id, data_all.expe_id, data_all.data_producer_code, data_all.production_timestamp, data_all.samp_id, data_all.registration_timestamp, data_all.pers_id_registerer, data_all.is_placeholder, data_all.is_valid, data_all.modification_timestamp, data_all.is_derived, data_all.ctnr_order, data_all.ctnr_id, data_all.del_id FROM data_all WHERE (data_all.del_id IS NOT NULL);
    CREATE SEQUENCE data_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('data_id_seq', 18, true);
    CREATE TABLE data_set_properties (
        id tech_id NOT NULL,
        ds_id tech_id NOT NULL,
        dstpt_id tech_id NOT NULL,
        value text_value,
        cvte_id tech_id,
        mate_prop_id tech_id,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        pers_id_author tech_id NOT NULL,
        CONSTRAINT dspr_ck CHECK ((((((value IS NOT NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NULL)) OR (((value IS NULL) AND (cvte_id IS NOT NULL)) AND (mate_prop_id IS NULL))) OR (((value IS NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NOT NULL))))
    );
    CREATE TABLE data_set_properties_history (
        id tech_id NOT NULL,
        ds_id tech_id NOT NULL,
        dstpt_id tech_id NOT NULL,
        value text_value,
        cvte_id tech_id,
        mate_prop_id tech_id,
        valid_until_timestamp time_stamp DEFAULT now(),
        pers_id_author tech_id NOT NULL,
        valid_from_timestamp time_stamp NOT NULL,
        CONSTRAINT dsprh_ck CHECK ((((((value IS NOT NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NULL)) OR (((value IS NULL) AND (cvte_id IS NOT NULL)) AND (mate_prop_id IS NULL))) OR (((value IS NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NOT NULL))))
    );
    CREATE SEQUENCE data_set_property_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('data_set_property_id_seq', 20, true);
    CREATE SEQUENCE data_set_relationship_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('data_set_relationship_id_seq', 1, false);
    CREATE TABLE data_set_relationships_all (
        data_id_parent tech_id NOT NULL,
        data_id_child tech_id NOT NULL
    );
    CREATE VIEW data_set_relationships AS
        SELECT data_set_relationships_all.data_id_parent, data_set_relationships_all.data_id_child FROM ((data_set_relationships_all JOIN data_all parent ON (((data_set_relationships_all.data_id_parent)::bigint = (parent.id)::bigint))) JOIN data_all child ON (((data_set_relationships_all.data_id_child)::bigint = (child.id)::bigint))) WHERE ((parent.del_id IS NULL) AND (child.del_id IS NULL));
    CREATE SEQUENCE data_set_type_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('data_set_type_id_seq', 4, true);
    CREATE TABLE data_set_type_property_types (
        id tech_id NOT NULL,
        dsty_id tech_id NOT NULL,
        prty_id tech_id NOT NULL,
        is_mandatory boolean_char DEFAULT false NOT NULL,
        is_managed_internally boolean_char DEFAULT false NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        section description_2000,
        ordinal ordinal_int NOT NULL,
        script_id tech_id,
        is_shown_edit boolean_char DEFAULT true NOT NULL
    );
    CREATE TABLE data_set_types (
        id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000,
        dbin_id tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        main_ds_pattern character varying(300),
        main_ds_path character varying(1000),
        is_container boolean_char DEFAULT false
    );
    CREATE SEQUENCE data_store_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('data_store_id_seq', 1, true);
    CREATE TABLE data_store_service_data_set_types (
        data_store_service_id tech_id NOT NULL,
        data_set_type_id tech_id NOT NULL
    );
    CREATE TABLE data_store_services (
        id tech_id NOT NULL,
        key character varying(256) NOT NULL,
        label character varying(256) NOT NULL,
        kind data_store_service_kind NOT NULL,
        data_store_id tech_id NOT NULL,
        reporting_plugin_type data_store_service_reporting_plugin_type
    );
    CREATE SEQUENCE data_store_services_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('data_store_services_id_seq', 1, false);
    CREATE TABLE data_stores (
        id tech_id NOT NULL,
        dbin_id tech_id NOT NULL,
        code code NOT NULL,
        download_url character varying(1024) NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        remote_url character varying(250) NOT NULL,
        session_token character varying(50) NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        is_archiver_configured boolean_char DEFAULT false NOT NULL
    );
    CREATE SEQUENCE data_type_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('data_type_id_seq', 10, true);
    CREATE TABLE data_types (
        id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000 NOT NULL
    );
    CREATE SEQUENCE database_instance_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('database_instance_id_seq', 1, true);
    CREATE TABLE database_instances (
        id tech_id NOT NULL,
        code code NOT NULL,
        uuid code NOT NULL,
        is_original_source boolean_char DEFAULT false NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL
    );
    CREATE TABLE database_version_logs (
        db_version character varying(4) NOT NULL,
        module_name character varying(250),
        run_status character varying(10),
        run_status_timestamp timestamp without time zone,
        module_code bytea,
        run_exception bytea
    );
    CREATE SEQUENCE deletion_id_seq
        START WITH 5
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('deletion_id_seq', 4, true);
    CREATE TABLE deletions (
        id tech_id NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        reason description_2000 NOT NULL
    );
    CREATE SEQUENCE dstpt_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('dstpt_id_seq', 4, true);
    CREATE SEQUENCE etpt_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('etpt_id_seq', 7, true);
    CREATE SEQUENCE event_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('event_id_seq', 1, false);
    CREATE TABLE events (
        id tech_id NOT NULL,
        event_type event_type NOT NULL,
        description text_value,
        reason description_2000,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        entity_type character varying(80) NOT NULL,
        identifiers text_value NOT NULL,
        CONSTRAINT evnt_et_enum_ck CHECK (((entity_type)::text = ANY (ARRAY[('ATTACHMENT'::character varying)::text, ('DATASET'::character varying)::text, ('EXPERIMENT'::character varying)::text, ('SPACE'::character varying)::text, ('MATERIAL'::character varying)::text, ('PROJECT'::character varying)::text, ('PROPERTY_TYPE'::character varying)::text, ('SAMPLE'::character varying)::text, ('VOCABULARY'::character varying)::text, ('AUTHORIZATION_GROUP'::character varying)::text])))
    );
    CREATE SEQUENCE experiment_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('experiment_id_seq', 22, true);
    CREATE TABLE experiment_properties (
        id tech_id NOT NULL,
        expe_id tech_id NOT NULL,
        etpt_id tech_id NOT NULL,
        value text_value,
        cvte_id tech_id,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        mate_prop_id tech_id,
        pers_id_author tech_id NOT NULL,
        CONSTRAINT expr_ck CHECK ((((((value IS NOT NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NULL)) OR (((value IS NULL) AND (cvte_id IS NOT NULL)) AND (mate_prop_id IS NULL))) OR (((value IS NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NOT NULL))))
    );
    CREATE TABLE experiment_properties_history (
        id tech_id NOT NULL,
        expe_id tech_id NOT NULL,
        etpt_id tech_id NOT NULL,
        value text_value,
        cvte_id tech_id,
        mate_prop_id tech_id,
        valid_until_timestamp time_stamp DEFAULT now(),
        pers_id_author tech_id NOT NULL,
        valid_from_timestamp time_stamp NOT NULL,
        CONSTRAINT exprh_ck CHECK ((((((value IS NOT NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NULL)) OR (((value IS NULL) AND (cvte_id IS NOT NULL)) AND (mate_prop_id IS NULL))) OR (((value IS NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NOT NULL))))
    );
    CREATE SEQUENCE experiment_property_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('experiment_property_id_seq', 20, true);
    CREATE SEQUENCE experiment_type_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('experiment_type_id_seq', 2, true);
    CREATE TABLE experiment_type_property_types (
        id tech_id NOT NULL,
        exty_id tech_id NOT NULL,
        prty_id tech_id NOT NULL,
        is_mandatory boolean_char DEFAULT false NOT NULL,
        is_managed_internally boolean_char DEFAULT false NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        section description_2000,
        ordinal ordinal_int NOT NULL,
        script_id tech_id,
        is_shown_edit boolean_char DEFAULT true NOT NULL
    );
    CREATE TABLE experiment_types (
        id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000,
        dbin_id tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now()
    );
    CREATE TABLE experiments_all (
        id tech_id NOT NULL,
        code code NOT NULL,
        exty_id tech_id NOT NULL,
        mate_id_study_object tech_id,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        proj_id tech_id NOT NULL,
        del_id tech_id,
        is_public boolean_char DEFAULT false NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        perm_id code NOT NULL
    );
    CREATE VIEW experiments AS
        SELECT experiments_all.id, experiments_all.perm_id, experiments_all.code, experiments_all.exty_id, experiments_all.mate_id_study_object, experiments_all.pers_id_registerer, experiments_all.registration_timestamp, experiments_all.modification_timestamp, experiments_all.proj_id, experiments_all.del_id, experiments_all.is_public FROM experiments_all WHERE (experiments_all.del_id IS NULL);
    CREATE VIEW experiments_deleted AS
        SELECT experiments_all.id, experiments_all.perm_id, experiments_all.code, experiments_all.exty_id, experiments_all.mate_id_study_object, experiments_all.pers_id_registerer, experiments_all.registration_timestamp, experiments_all.modification_timestamp, experiments_all.proj_id, experiments_all.del_id, experiments_all.is_public FROM experiments_all WHERE (experiments_all.del_id IS NOT NULL);
    CREATE TABLE external_data (
        data_id tech_id NOT NULL,
        location character varying(1024) NOT NULL,
        ffty_id tech_id NOT NULL,
        loty_id tech_id NOT NULL,
        cvte_id_stor_fmt tech_id NOT NULL,
        is_complete boolean_char_or_unknown DEFAULT 'U'::bpchar NOT NULL,
        cvte_id_store tech_id,
        status archiving_status DEFAULT 'AVAILABLE'::character varying NOT NULL,
        share_id code,
        size ordinal_int,
        present_in_archive boolean_char DEFAULT false,
        speed_hint integer DEFAULT (-50) NOT NULL
    );
    CREATE SEQUENCE file_format_type_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('file_format_type_id_seq', 8, true);
    CREATE TABLE file_format_types (
        id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000,
        dbin_id tech_id NOT NULL
    );
    CREATE SEQUENCE filter_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('filter_id_seq', 1, false);
    CREATE TABLE filters (
        id tech_id NOT NULL,
        dbin_id tech_id NOT NULL,
        name character varying(200) NOT NULL,
        description description_2000,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        expression text NOT NULL,
        is_public boolean NOT NULL,
        grid_id character varying(200) NOT NULL
    );
    CREATE TABLE grid_custom_columns (
        id tech_id NOT NULL,
        dbin_id tech_id NOT NULL,
        code character varying(200) NOT NULL,
        label column_label NOT NULL,
        description description_2000,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now(),
        expression grid_expression NOT NULL,
        is_public boolean NOT NULL,
        grid_id grid_id NOT NULL
    );
    CREATE SEQUENCE grid_custom_columns_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('grid_custom_columns_id_seq', 1, false);
    CREATE SEQUENCE locator_type_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('locator_type_id_seq', 1, true);
    CREATE TABLE locator_types (
        id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000
    );
    CREATE SEQUENCE material_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('material_id_seq', 3734, true);
    CREATE TABLE material_properties (
        id tech_id NOT NULL,
        mate_id tech_id NOT NULL,
        mtpt_id tech_id NOT NULL,
        value text_value,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        cvte_id tech_id,
        modification_timestamp time_stamp DEFAULT now(),
        mate_prop_id tech_id,
        pers_id_author tech_id NOT NULL,
        CONSTRAINT mapr_ck CHECK ((((((value IS NOT NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NULL)) OR (((value IS NULL) AND (cvte_id IS NOT NULL)) AND (mate_prop_id IS NULL))) OR (((value IS NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NOT NULL))))
    );
    CREATE TABLE material_properties_history (
        id tech_id NOT NULL,
        mate_id tech_id NOT NULL,
        mtpt_id tech_id NOT NULL,
        value text_value,
        cvte_id tech_id,
        mate_prop_id tech_id,
        valid_until_timestamp time_stamp DEFAULT now(),
        pers_id_author tech_id NOT NULL,
        valid_from_timestamp time_stamp NOT NULL,
        CONSTRAINT maprh_ck CHECK ((((((value IS NOT NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NULL)) OR (((value IS NULL) AND (cvte_id IS NOT NULL)) AND (mate_prop_id IS NULL))) OR (((value IS NULL) AND (cvte_id IS NULL)) AND (mate_prop_id IS NOT NULL))))
    );
    CREATE SEQUENCE material_property_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('material_property_id_seq', 9321, true);
    CREATE SEQUENCE material_type_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('material_type_id_seq', 7, true);
    CREATE TABLE material_type_property_types (
        id tech_id NOT NULL,
        maty_id tech_id NOT NULL,
        prty_id tech_id NOT NULL,
        is_mandatory boolean_char DEFAULT false NOT NULL,
        is_managed_internally boolean_char DEFAULT false NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        section description_2000,
        ordinal ordinal_int NOT NULL,
        script_id tech_id,
        is_shown_edit boolean_char DEFAULT true NOT NULL
    );
    CREATE TABLE material_types (
        id tech_id NOT NULL,
        code code NOT NULL,
        description description_2000,
        dbin_id tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now()
    );
    CREATE TABLE materials (
        id tech_id NOT NULL,
        code code NOT NULL,
        maty_id tech_id NOT NULL,
        pers_id_registerer tech_id NOT NULL,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        dbin_id tech_id NOT NULL,
        modification_timestamp time_stamp DEFAULT now()
    );
    CREATE SEQUENCE mtpt_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('mtpt_id_seq', 22, true);
    CREATE SEQUENCE perm_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('perm_id_seq', 1035, true);
    CREATE SEQUENCE person_id_seq
        START WITH 1
        INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1;
    SELECT pg_catalog.setval('person_id_seq', 4, true);
    CREATE TABLE persons (
        id tech_id NOT NULL,
        first_name character varying(30),
        last_name character varying(30),
        user_id user_id NOT NULL,
        email object_name,
        dbin_id tech_id NOT NULL,
        space_id tech_id,
        registration_timestamp time_stamp_dfl DEFAULT now() NOT NULL,
        pers_id_registerer tech_id,
        display_settings file