Skip to content

Commit

Permalink
Make concept based table IDs 64 bit
Browse files Browse the repository at this point in the history
While we still have some headroom for the datasets we work with at the
moment, keeping the IDs of concept table based tables (inheritance) at
32 bit would have been a limit at some point. Already we see large
segmentation datasets that make this headroom rather small. Therefore
this migration will rewrite all concept based tables as well as tables
that reference them through foreign keys so that 64 bit IDs are used.

This migration also updates the review table to use 64 bit IDs. It also
fixes the history views of the catmaid_sampler table, which haven't been
kept up to date with column changes.

In addition a lot of missing foreign key constraints have been added.
They shouldn't have a big import on performance and in fact no real
difference could be measured.

The column order of concept changed slightly to improve the column
alignment and reduce padding. So far we wasted 4 Bytes per row, because
project_id occupied 4 Bytes and required 4 Bytes of padding, because it
was followed by a bigint. This is changed now and no more padding is
needed. This also lowers the impact on storage of the change to 64 bit
IDs.

Also, the indices backing the primary keys of many semantic tables
include now additional data like the class_id for class instances and
the relation_id for some relation instance types. This Postgres 11
feature allows to use more index-only scans.

In addition many index names follow now a more consistent pattern.

I tested this migration by multiple reviews and analyzing the schema
diff generated by pgquarrel for both migration 92 vs 93 as well as 92 vs
(93 -> 92) (i.e. a rollback). These migrations look reasonable and the
effective migration (diff) from 92 to 93 is attached at the end of this
commit message. The actual migration is more complicated, because it
cares also about column ordering, which below schema changes don't.

Fixes #1848

---

Effective migration 93:

ALTER SEQUENCE catmaid_sampler_id_seq AS bigint MAXVALUE 9223372036854775807;

CREATE SEQUENCE skeleton_origin_id_seq1 NO MINVALUE NO MAXVALUE;

ALTER TABLE ONLY cardinality_restriction ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint;

ALTER TABLE ONLY cardinality_restriction ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY cardinality_restriction
	ADD CONSTRAINT cardinality_restriction_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY cardinality_restriction__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint;

ALTER TABLE ONLY catmaid_sampler ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY catmaid_sampler
	DROP CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s;

ALTER TABLE ONLY catmaid_sampler
	ADD CONSTRAINT catmaid_sampler_sampler_state_id_fkey FOREIGN KEY (sampler_state_id) REFERENCES catmaid_samplerstate(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_sampler
	DROP CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id;

ALTER TABLE ONLY catmaid_sampler
	ADD CONSTRAINT catmaid_sampler_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_sampler
	DROP CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id;

ALTER TABLE ONLY catmaid_sampler
	ADD CONSTRAINT catmaid_sampler_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_sampler__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY catmaid_samplerdomain
	DROP CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id;

ALTER TABLE ONLY catmaid_samplerdomain
	ADD CONSTRAINT catmaid_samplerdomain_sampler_id_fkey FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id);

ALTER TABLE ONLY catmaid_samplerdomain
	DROP CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id;

ALTER TABLE ONLY catmaid_samplerdomain
	ADD CONSTRAINT catmaid_samplerdomain_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_samplerdomainend
	DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id;

ALTER TABLE ONLY catmaid_samplerdomainend
	ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_samplerinterval
	DROP CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id;

ALTER TABLE ONLY catmaid_samplerinterval
	ADD CONSTRAINT catmaid_samplerinterval_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_samplerinterval
	DROP CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id;

ALTER TABLE ONLY catmaid_samplerinterval
	ADD CONSTRAINT catmaid_samplerinterval_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY catmaid_skeleton_summary
	DROP CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins;

ALTER TABLE ONLY catmaid_skeleton_summary
	ADD CONSTRAINT catmaid_skeleton_summary_last_editor_id_fkey FOREIGN KEY (last_editor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_skeleton_summary
	DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk;

ALTER TABLE ONLY catmaid_skeleton_summary
	ADD CONSTRAINT catmaid_skeleton_summary_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY catmaid_skeleton_summary
	DROP CONSTRAINT last_editor_id_fkey;

ALTER TABLE ONLY change_request ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY change_request ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY change_request
	DROP CONSTRAINT change_request_connector_id_fkey;

ALTER TABLE ONLY change_request
	ADD CONSTRAINT change_request_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY change_request
	ADD CONSTRAINT change_request_recipient_id_fkey FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY change_request
	DROP CONSTRAINT change_request_treenode_id_fkey;

ALTER TABLE ONLY change_request
	ADD CONSTRAINT change_request_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY change_request
	DROP CONSTRAINT change_request_user_id_fkey;

ALTER TABLE ONLY change_request
	ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY change_request
	DROP CONSTRAINT recipient_id_refs_id;

ALTER TABLE ONLY change_request__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class ALTER COLUMN class_name SET DATA TYPE text;

ALTER TABLE ONLY class ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY class
	ADD CONSTRAINT class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class__history ALTER COLUMN class_name SET DATA TYPE text;

ALTER TABLE ONLY class__history ALTER COLUMN class_name DROP DEFAULT;

ALTER TABLE ONLY class__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class_class ALTER COLUMN class_a SET DATA TYPE bigint;

ALTER TABLE ONLY class_class ALTER COLUMN class_a SET NOT NULL;

ALTER TABLE ONLY class_class ALTER COLUMN class_b SET DATA TYPE bigint;

ALTER TABLE ONLY class_class ALTER COLUMN class_b SET NOT NULL;

ALTER TABLE ONLY class_class ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class_class ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY class_class ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY class_class
	ADD CONSTRAINT class_class_class_a_fkey FOREIGN KEY (class_a) REFERENCES class(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class_class
	ADD CONSTRAINT class_class_class_b_fkey FOREIGN KEY (class_b) REFERENCES class(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class_class
	ADD CONSTRAINT class_class_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class_class
	ADD CONSTRAINT class_class_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class_class
	ADD CONSTRAINT class_class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class_class__history ALTER COLUMN class_a SET DATA TYPE bigint;

ALTER TABLE ONLY class_class__history ALTER COLUMN class_b SET DATA TYPE bigint;

ALTER TABLE ONLY class_class__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class_class__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance ALTER COLUMN class_id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY class_instance
	ADD CONSTRAINT class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class_instance
	DROP CONSTRAINT class_instance_pkey;

ALTER TABLE ONLY class_instance
	ADD CONSTRAINT class_instance_id_pkey PRIMARY KEY (id) INCLUDE (class_id);

ALTER TABLE ONLY class_instance__history ALTER COLUMN class_id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance ALTER COLUMN class_instance_a SET NOT NULL;

ALTER TABLE ONLY class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance ALTER COLUMN class_instance_b SET NOT NULL;

ALTER TABLE ONLY class_instance_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY class_instance_class_instance
	ADD CONSTRAINT class_instance_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY class_instance_class_instance
	DROP CONSTRAINT class_instance_class_instance_pkey;

ALTER TABLE ONLY class_instance_class_instance
	ADD CONSTRAINT class_instance_class_instance_id_pkey PRIMARY KEY (id) INCLUDE (relation_id);

ALTER TABLE ONLY class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY concept ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY concept ALTER COLUMN id SET DEFAULT nextval('concept_id_seq'::regclass);

ALTER TABLE ONLY concept ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY concept
	ADD CONSTRAINT concept_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY concept
	ADD CONSTRAINT concept_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY concept__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY connector_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY connector_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY connector_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY connector_class_instance
	ADD CONSTRAINT connector_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY connector_class_instance
	DROP CONSTRAINT connector_class_instance_connector_id_fkey;

ALTER TABLE ONLY connector_class_instance
	ADD CONSTRAINT connector_class_instance_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY connector_class_instance
	ADD CONSTRAINT connector_class_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY connector_class_instance
	ADD CONSTRAINT connector_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY connector_class_instance
	ADD CONSTRAINT connector_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY connector_class_instance
	DROP CONSTRAINT connector_class_instance_pkey;

ALTER TABLE ONLY connector_class_instance
	ADD CONSTRAINT connector_class_instance_id_pkey PRIMARY KEY (id) INCLUDE (relation_id);

ALTER TABLE ONLY connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY connector_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY log ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY log ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY log
	ADD CONSTRAINT log_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY log
	ADD CONSTRAINT log_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY point_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY point_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY point_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY point_class_instance
	ADD CONSTRAINT point_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_class_instance
	ADD CONSTRAINT point_class_instance_point_id_fkey FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_class_instance
	ADD CONSTRAINT point_class_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_class_instance
	ADD CONSTRAINT point_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_class_instance
	DROP CONSTRAINT point_class_instance_sa_id;

ALTER TABLE ONLY point_class_instance
	ADD CONSTRAINT point_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_class_instance
	DROP CONSTRAINT point_connector_class_instance_id_fkey;

ALTER TABLE ONLY point_class_instance
	DROP CONSTRAINT point_class_instance_pkey;

ALTER TABLE ONLY point_class_instance
	ADD CONSTRAINT point_class_instance_id_pkey PRIMARY KEY (id) INCLUDE (relation_id);

ALTER TABLE ONLY point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY point_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY point_connector ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY point_connector ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY point_connector ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY point_connector
	DROP CONSTRAINT point_connector_connector_id_fkey;

ALTER TABLE ONLY point_connector
	ADD CONSTRAINT point_connector_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_connector
	ADD CONSTRAINT point_connector_point_id_fkey FOREIGN KEY (point_id) REFERENCES point(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_connector
	ADD CONSTRAINT point_connector_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_connector
	ADD CONSTRAINT point_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_connector
	DROP CONSTRAINT point_connector_sa_id;

ALTER TABLE ONLY point_connector
	ADD CONSTRAINT point_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY point_connector
	DROP CONSTRAINT point_connector_pkey;

ALTER TABLE ONLY point_connector
	ADD CONSTRAINT point_connector_id_pkey PRIMARY KEY (id) INCLUDE (relation_id);

ALTER TABLE ONLY point_connector__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY point_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY region_of_interest_class_instance ALTER COLUMN class_instance_id SET NOT NULL;

ALTER TABLE ONLY region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY region_of_interest_class_instance ALTER COLUMN region_of_interest_id SET NOT NULL;

ALTER TABLE ONLY region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY region_of_interest_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY region_of_interest_class_instance
	DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey;

ALTER TABLE ONLY region_of_interest_class_instance
	ADD CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY region_of_interest_class_instance
	ADD CONSTRAINT region_of_interest_class_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY region_of_interest_class_instance
	ADD CONSTRAINT region_of_interest_class_instance_region_of_interest_id_fkey FOREIGN KEY (region_of_interest_id) REFERENCES region_of_interest(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY region_of_interest_class_instance
	ADD CONSTRAINT region_of_interest_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY region_of_interest_class_instance
	ADD CONSTRAINT region_of_interest_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY region_of_interest_class_instance
	DROP CONSTRAINT region_of_interest_class_instance_pkey;

ALTER TABLE ONLY region_of_interest_class_instance
	ADD CONSTRAINT region_of_interest_class_instance_id_pkey PRIMARY KEY (id) INCLUDE (relation_id);

ALTER TABLE ONLY region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY relation ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY relation ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY relation
	ADD CONSTRAINT relation_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY relation
	ADD CONSTRAINT relation_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY relation__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY relation_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY relation_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY relation_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY relation_instance
	ADD CONSTRAINT relation_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY relation_instance
	ADD CONSTRAINT relation_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY relation_instance
	ADD CONSTRAINT relation_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY relation_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY relation_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY restriction ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint;

ALTER TABLE ONLY restriction ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY restriction
	DROP CONSTRAINT restricted_link_fkey;

ALTER TABLE ONLY restriction
	ADD CONSTRAINT restriction_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY restriction
	ADD CONSTRAINT restriction_restricted_link_id_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id);

ALTER TABLE ONLY restriction
	ADD CONSTRAINT restriction_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY restriction__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint;

ALTER TABLE ONLY review ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY review ALTER COLUMN review_time SET DEFAULT now();

ALTER TABLE ONLY review ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY review ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY review
	DROP CONSTRAINT review_reviewer_id_refs_id;

ALTER TABLE ONLY review
	ADD CONSTRAINT review_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY review
	DROP CONSTRAINT review_skeleton_id_refs_id;

ALTER TABLE ONLY review
	ADD CONSTRAINT review_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY review
	ADD CONSTRAINT review_user_id_fkey FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY review
	DROP CONSTRAINT treenode_id_fkey;

ALTER TABLE ONLY review__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY review__history ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY skeleton_origin ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY skeleton_origin
	DROP CONSTRAINT skeleton_origin_data_source_id_fkey;

ALTER TABLE ONLY skeleton_origin
	ADD CONSTRAINT skeleton_origin_data_source_id_fkey1 FOREIGN KEY (data_source_id) REFERENCES data_source(id) ON DELETE CASCADE;

ALTER TABLE ONLY skeleton_origin
	DROP CONSTRAINT skeleton_origin_project_id_fkey;

ALTER TABLE ONLY skeleton_origin
	ADD CONSTRAINT skeleton_origin_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE;

ALTER TABLE ONLY skeleton_origin
	DROP CONSTRAINT skeleton_origin_skeleton_id_fkey;

ALTER TABLE ONLY skeleton_origin
	ADD CONSTRAINT skeleton_origin_skeleton_id_fkey1 FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE;

ALTER TABLE ONLY skeleton_origin
	DROP CONSTRAINT skeleton_origin_user_id_fkey;

ALTER TABLE ONLY skeleton_origin
	ADD CONSTRAINT skeleton_origin_user_id_fkey1 FOREIGN KEY (user_id) REFERENCES auth_user(id);

ALTER TABLE ONLY skeleton_origin__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_class_instance ALTER COLUMN class_instance_id SET NOT NULL;

ALTER TABLE ONLY stack_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_class_instance ALTER COLUMN stack_id SET NOT NULL;

ALTER TABLE ONLY stack_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY stack_class_instance
	DROP CONSTRAINT stack_class_instance_class_instance_id_fkey;

ALTER TABLE ONLY stack_class_instance
	ADD CONSTRAINT stack_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_class_instance
	ADD CONSTRAINT stack_class_instance_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_class_instance
	ADD CONSTRAINT stack_class_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_class_instance
	DROP CONSTRAINT stack_class_instance_stack_id_fkey;

ALTER TABLE ONLY stack_class_instance
	ADD CONSTRAINT stack_class_instance_stack_id_fkey FOREIGN KEY (stack_id) REFERENCES stack(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_class_instance
	ADD CONSTRAINT stack_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_class_instance
	DROP CONSTRAINT stack_class_instance_pkey;

ALTER TABLE ONLY stack_class_instance
	ADD CONSTRAINT stack_class_instance_id_pkey PRIMARY KEY (id) INCLUDE (relation_id);

ALTER TABLE ONLY stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_group_class_instance ALTER COLUMN class_instance_id SET NOT NULL;

ALTER TABLE ONLY stack_group_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_group_class_instance ALTER COLUMN stack_group_id SET NOT NULL;

ALTER TABLE ONLY stack_group_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY stack_group_class_instance
	DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey;

ALTER TABLE ONLY stack_group_class_instance
	ADD CONSTRAINT stack_group_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_group_class_instance
	ADD CONSTRAINT stack_group_class_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_group_class_instance
	ADD CONSTRAINT stack_group_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_group_class_instance
	DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey;

ALTER TABLE ONLY stack_group_class_instance
	ADD CONSTRAINT stack_group_class_instance_stack_group_id_fkey FOREIGN KEY (stack_group_id) REFERENCES stack_group(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_group_class_instance
	ADD CONSTRAINT stack_group_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY stack_group_class_instance
	DROP CONSTRAINT stack_group_class_instance_pkey;

ALTER TABLE ONLY stack_group_class_instance
	ADD CONSTRAINT stack_group_class_instance_id_pkey PRIMARY KEY (id) INCLUDE (relation_id);

ALTER TABLE ONLY stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY suppressed_virtual_treenode
	ADD CONSTRAINT suppressed_virtual_treenode_child_id_fkey FOREIGN KEY (child_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY suppressed_virtual_treenode
	DROP CONSTRAINT suppressed_vnodes_child_id_refs_id;

ALTER TABLE ONLY treenode ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode
	ADD CONSTRAINT treenode_editor_id_fkey FOREIGN KEY (editor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode
	ADD CONSTRAINT treenode_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode
	ADD CONSTRAINT treenode_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode
	DROP CONSTRAINT treenode_pkey;

ALTER TABLE ONLY treenode
	ADD CONSTRAINT treenode_id_pkey PRIMARY KEY (id) INCLUDE (parent_id);

ALTER TABLE ONLY treenode__history ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY treenode_class_instance
	ADD CONSTRAINT treenode_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_class_instance
	ADD CONSTRAINT treenode_class_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_class_instance
	ADD CONSTRAINT treenode_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_class_instance
	DROP CONSTRAINT treenode_class_instance_treenode_id_fkey;

ALTER TABLE ONLY treenode_class_instance
	ADD CONSTRAINT treenode_class_instance_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_class_instance
	ADD CONSTRAINT treenode_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_connector ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_connector ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_connector ALTER COLUMN skeleton_id SET NOT NULL;

ALTER TABLE ONLY treenode_connector ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY treenode_connector
	ADD CONSTRAINT treenode_connector_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_connector
	ADD CONSTRAINT treenode_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_connector
	ADD CONSTRAINT treenode_connector_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_connector
	ADD CONSTRAINT treenode_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY treenode_connector__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE bigint;

ALTER TABLE ONLY volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY volume_class_instance ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY volume_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint;

ALTER TABLE ONLY volume_class_instance ALTER COLUMN txid SET NOT NULL;

ALTER TABLE ONLY volume_class_instance
	ADD CONSTRAINT volume_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY volume_class_instance
	DROP CONSTRAINT volume_class_instance_id_fkey;

ALTER TABLE ONLY volume_class_instance
	ADD CONSTRAINT volume_class_instance_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY volume_class_instance
	ADD CONSTRAINT volume_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY volume_class_instance
	DROP CONSTRAINT volume_class_instance_sa_id;

ALTER TABLE ONLY volume_class_instance
	ADD CONSTRAINT volume_class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY volume_class_instance
	ADD CONSTRAINT volume_class_instance_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES catmaid_volume(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint;

ALTER TABLE ONLY volume_class_instance__history ALTER COLUMN id SET DATA TYPE bigint;

ALTER TABLE ONLY volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint;

CREATE INDEX catmaid_sampler_project_id_idx ON catmaid_sampler USING btree (project_id);

CREATE INDEX catmaid_sampler_sampler_state_id_idx ON catmaid_sampler USING btree (sampler_state_id);

CREATE INDEX catmaid_sampler_skeleton_id_idx ON catmaid_sampler USING btree (skeleton_id);

CREATE INDEX catmaid_sampler_user_id_idx ON catmaid_sampler USING btree (user_id);

CREATE INDEX catmaid_skeleton_summary_project_id_idx ON catmaid_skeleton_summary USING btree (project_id);

CREATE INDEX class_class_name_idx ON class USING btree (class_name);

CREATE UNIQUE INDEX point_connector_project_id_point_id_connector_id_relation_id_un ON point_connector USING btree (project_id, point_id, connector_id, relation_id);

CREATE INDEX review_project_id_idx ON review USING btree (project_id);

CREATE INDEX review_reviewer_id_idx ON review USING btree (reviewer_id);

CREATE INDEX review_skeleton_id_idx ON review USING btree (skeleton_id);

CREATE INDEX review_treenode_id_idx ON review USING btree (treenode_id);

CREATE INDEX treenode_class_instance_class_instance_id_idx ON treenode_class_instance USING btree (class_instance_id);

CREATE INDEX treenode_class_instance_project_id_idx ON treenode_class_instance USING btree (project_id);

CREATE INDEX treenode_class_instance_relation_id_idx ON treenode_class_instance USING btree (relation_id);

CREATE INDEX treenode_class_instance_treenode_id_idx ON treenode_class_instance USING btree (treenode_id);

CREATE INDEX treenode_class_instance_user_id_idx ON treenode_class_instance USING btree (user_id);

CREATE INDEX treenode_connector_connector_id_idx ON treenode_connector USING btree (connector_id);

CREATE INDEX treenode_connector_creation_time_idx_idx ON treenode_connector USING btree (creation_time);

CREATE INDEX treenode_connector_project_id_idx ON treenode_connector USING btree (project_id);

CREATE UNIQUE INDEX treenode_connector_project_id_treenode_id_connector_id_relation ON treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id);

CREATE INDEX treenode_connector_relation_id_idx ON treenode_connector USING btree (relation_id);

CREATE INDEX treenode_connector_skeleton_id_idx ON treenode_connector USING btree (skeleton_id);

CREATE INDEX treenode_connector_treenode_id_idx ON treenode_connector USING btree (treenode_id);

CREATE INDEX treenode_connector_user_id_idx ON treenode_connector USING btree (user_id);

CREATE INDEX treenode_creation_time_idx ON treenode USING btree (creation_time);

CREATE INDEX treenode_edition_time_idx ON treenode USING btree (edition_time);

CREATE INDEX treenode_parent_id_idx ON treenode USING btree (parent_id);

CREATE INDEX treenode_project_id_location_x_idx ON treenode USING btree (project_id, location_x);

CREATE INDEX treenode_project_id_location_y_idx ON treenode USING btree (project_id, location_y);

CREATE INDEX treenode_project_id_location_z_idx ON treenode USING btree (project_id, location_z);

CREATE INDEX treenode_project_id_user_id_idx ON treenode USING btree (user_id, project_id);

CREATE INDEX treenode_skeleton_id_project_id_idx ON treenode USING btree (skeleton_id, project_id);

DROP INDEX catmaid_sampler_project_id_c93395a7;

DROP INDEX catmaid_sampler_sampler_state_id_80e7961f;

DROP INDEX catmaid_sampler_skeleton_id_dfc98008;

DROP INDEX catmaid_sampler_user_id_8d1c228f;

DROP INDEX catmaid_skeleton_summary_project_id_7340fa33;

DROP INDEX point_connector_project_id_uniq;

DROP INDEX review_project_id;

DROP INDEX review_reviewer_id;

DROP INDEX review_skeleton_id;

DROP INDEX review_treenode_id;

DROP INDEX treenode_class_instance_class_instance_id;

DROP INDEX treenode_class_instance_project_id;

DROP INDEX treenode_class_instance_relation_id;

DROP INDEX treenode_class_instance_treenode_id;

DROP INDEX treenode_class_instance_user_id;

DROP INDEX treenode_connector_connector_id;

DROP INDEX treenode_connector_creation_time_idx;

DROP INDEX treenode_connector_project_id;

DROP INDEX treenode_connector_project_id_uniq;

DROP INDEX treenode_connector_relation_id;

DROP INDEX treenode_connector_skeleton_id;

DROP INDEX treenode_connector_treenode_id;

DROP INDEX treenode_connector_user_id;

DROP INDEX treenode_creation_time_index;

DROP INDEX treenode_edition_time_index;

DROP INDEX treenode_location_x_index;

DROP INDEX treenode_location_y_index;

DROP INDEX treenode_location_z_index;

DROP INDEX treenode_parent_id;

DROP INDEX treenode_project_id_skeleton_id_index;

DROP INDEX treenode_project_id_user_id_index;

DROP INDEX treenode_skeleton_id_index;

CREATE TRIGGER on_edit_cardinality_restrictions BEFORE UPDATE ON cardinality_restriction FOR EACH ROW EXECUTE PROCEDURE on_edit();

CREATE TRIGGER on_edit_point_class_instance BEFORE UPDATE ON point_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit();

CREATE TRIGGER on_edit_point_connector BEFORE UPDATE ON point_connector FOR EACH ROW EXECUTE PROCEDURE on_edit();

CREATE TRIGGER on_edit_region_of_interest_class_instance BEFORE UPDATE ON region_of_interest_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit();

CREATE TRIGGER on_stack_class_instance BEFORE UPDATE ON stack_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit();

CREATE TRIGGER on_stack_group_class_instance BEFORE UPDATE ON stack_group_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit();

CREATE TRIGGER on_edit_volume_class_instance BEFORE UPDATE ON volume_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit();

DROP SEQUENCE skeleton_origin_id_seq;
  • Loading branch information
tomka committed Nov 8, 2019
1 parent 02f50bf commit 8ac20a0
Show file tree
Hide file tree
Showing 10 changed files with 2,772 additions and 24 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
startup, advisory locks are now used. This should make the startup of parallel
CATMAID workers more robust.

- The application of migration 82 might take a while to complete, because it
- The application of migration 88-91 might take a while to complete, because it
rewrites a potentially big table (treenode_edge). Therefore, make also sure
that there is enough space available at the database storate location (25% of
database data directory should be plenty). If no replication is used, setting
the following Postgres options can speed up the process: `wal_level = minimal`,
`archive_mode = off` and `max_wal_senders = 0`.
the following Postgres options can speed up the process: `wal_level =
minimal`, `archive_mode = off` and `max_wal_senders = 0`.

- Both `configuration.py.example` and `create_configuration.py` support now the
option `catmaid_default_enabled_tools`, which defines the list of front-end
Expand Down
6 changes: 3 additions & 3 deletions django/applications/catmaid/control/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def _update_neuron_annotations(project_id:Union[int,str], neuron_id,
cursor.execute('''
UPDATE class_instance_class_instance
SET class_instance_a = %s, user_id = missing.u_id
FROM UNNEST(%s::integer[], %s::integer[]) AS missing(cici_id, u_id)
FROM UNNEST(%s::bigint[], %s::integer[]) AS missing(cici_id, u_id)
WHERE id = missing.cici_id;
''', (neuron_id, cici_ids, u_ids))

Expand Down Expand Up @@ -679,12 +679,12 @@ def _update_neuron_annotations(project_id:Union[int,str], neuron_id,
cursor.execute("""
UPDATE class_instance_class_instance
SET creation_time = to_update.creation_time
FROM UNNEST(%s::integer[], %s::timestamptz[])
FROM UNNEST(%s::bigint[], %s::timestamptz[])
AS to_update(cici_id, creation_time)
WHERE id = to_update.cici_id;
UPDATE class_instance_class_instance
SET edition_Time = to_update.edition_time
FROM UNNEST(%s::integer[], %s::timestamptz[])
FROM UNNEST(%s::bigint[], %s::timestamptz[])
AS to_update(cici_id, edition_time)
WHERE id = to_update.cici_id;
""", (to_update_ids,
Expand Down
8 changes: 4 additions & 4 deletions django/applications/catmaid/control/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ def _many_to_many_synapses(skids1, skids2, relation_name, project_id) -> Tuple:
treenode t1,
treenode t2,
connector c
WHERE tc1.skeleton_id = ANY(%(skeleton_ids_1)s::int[])
WHERE tc1.skeleton_id = ANY(%(skeleton_ids_1)s::bigint[])
AND tc1.connector_id = c.id
AND tc2.skeleton_id = ANY(%(skeleton_ids_2)s::int[])
AND tc2.skeleton_id = ANY(%(skeleton_ids_2)s::bigint[])
AND tc1.connector_id = tc2.connector_id
AND tc1.relation_id = %(relation_id)s
AND (tc1.relation_id != tc2.relation_id
OR tc1.relation_id = ANY(%(undir_rel_ids)s::int[]))
OR tc1.relation_id = ANY(%(undir_rel_ids)s::bigint[]))
AND tc1.id != tc2.id
AND tc1.treenode_id = t1.id
AND tc2.treenode_id = t2.id
Expand Down Expand Up @@ -1066,7 +1066,7 @@ def get_connectors_in_bb_postgis3d(params) -> List:
JOIN (
SELECT DISTiNCT tc2.connector_id
FROM treenode_connector tc2
JOIN UNNEST(%(skeleton_ids)s::int[]) skeleton(id)
JOIN UNNEST(%(skeleton_ids)s::bigint[]) skeleton(id)
ON tc2.skeleton_id = skeleton.id
) allowed_connector(id)
ON allowed_connector.id = c.id
Expand Down
2 changes: 1 addition & 1 deletion django/applications/catmaid/control/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def label_update(request:HttpRequest, project_id, location_id, ntype:str) -> Jso
class_instance ci,
treenode_class_instance tci,
treenode tn,
unnest(%s::text[], %s::integer[]) AS ll (name, max)
unnest(%s::text[], %s::bigint[]) AS ll (name, max)
WHERE ci.name = ll.name
AND ci.project_id = %s
AND ci.class_id = %s
Expand Down
6 changes: 3 additions & 3 deletions django/applications/catmaid/control/landmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def get_landmark_group_locations(project_id, landmarkgroup_ids, with_names:bool=
FROM (
SELECT pci.point_id, pci.class_instance_id, array_agg(l.name) as names
FROM point_class_instance pci
JOIN UNNEST(%(landmarkgroup_ids)s::integer[]) landmarkgroup(id)
JOIN UNNEST(%(landmarkgroup_ids)s::bigint[]) landmarkgroup(id)
ON pci.class_instance_id = landmarkgroup.id
LEFT JOIN point_class_instance pci_l
ON pci_l.point_id = pci.point_id
Expand Down Expand Up @@ -937,7 +937,7 @@ def get_landmark_group_locations(project_id, landmarkgroup_ids, with_names:bool=
SELECT pci.point_id, pci.class_instance_id, p.location_x,
p.location_y, p.location_z
FROM point_class_instance pci
JOIN UNNEST(%(landmarkgroup_ids)s::integer[]) landmarkgroup(id)
JOIN UNNEST(%(landmarkgroup_ids)s::bigint[]) landmarkgroup(id)
ON pci.class_instance_id = landmarkgroup.id
JOIN point p
ON p.id = pci.point_id
Expand Down Expand Up @@ -966,7 +966,7 @@ def make_landmark_relation_index(project_id, landmarkgroup_ids) -> Tuple[Default
SELECT cici.id, lg.id, cici.relation_id, r.relation_name,
cici.class_instance_a, cici.class_instance_b
FROM class_instance_class_instance cici
JOIN UNNEST(%(landmarkgroup_ids)s::integer[]) lg(id)
JOIN UNNEST(%(landmarkgroup_ids)s::bigint[]) lg(id)
ON lg.id = cici.class_instance_a
OR lg.id = cici.class_instance_b
JOIN relation r
Expand Down
2 changes: 1 addition & 1 deletion django/applications/catmaid/control/similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def compute_random_and_add_delayed(self, project_id, user_id, name,
cursor.execute("""
SELECT css.skeleton_id
FROM catmaid_skeleton_summary css
JOIN UNNEST(%(skeleton_ids)s::int[]) skeleton(id)
JOIN UNNEST(%(skeleton_ids)s::bigint[]) skeleton(id)
ON css.skeleton_id = skeleton.id
WHERE project_id = %(project_id)s
AND cable_length >= %(min_cable)s
Expand Down
16 changes: 8 additions & 8 deletions django/applications/catmaid/control/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ def connectivity_counts(request:HttpRequest, project_id=None) -> JsonResponse:
cursor.execute("""
SELECT tc.skeleton_id, tc.relation_id, COUNT(tc)
FROM treenode_connector tc
JOIN UNNEST(%(skeleton_ids)s::int[]) skeleton(id)
JOIN UNNEST(%(skeleton_ids)s::bigint[]) skeleton(id)
ON skeleton.id = tc.skeleton_id
{extra_select}
WHERE tc.project_id = %(project_id)s
Expand Down Expand Up @@ -1572,7 +1572,7 @@ def newPartner():
t1.treenode_id, t2.treenode_id
FROM treenode_connector t1,
treenode_connector t2
WHERE t1.skeleton_id = ANY(%s::integer[])
WHERE t1.skeleton_id = ANY(%s::bigint[])
AND t1.relation_id = %s
AND t1.connector_id = t2.connector_id
AND t1.id != t2.id
Expand Down Expand Up @@ -1607,7 +1607,7 @@ def newPartner():
cursor.execute('''
SELECT skeleton_id, num_nodes
FROM catmaid_skeleton_summary
WHERE skeleton_id = ANY(%s::integer[])
WHERE skeleton_id = ANY(%s::bigint[])
GROUP BY skeleton_id
''', (partner_skids,))
for row in cursor.fetchall():
Expand All @@ -1617,7 +1617,7 @@ def newPartner():
cursor.execute('''
SELECT DISTINCT reviewer_id
FROM review
WHERE skeleton_id = ANY(%s::integer[])
WHERE skeleton_id = ANY(%s::bigint[])
''', (partner_skids,))
reviewers = [row[0] for row in cursor]

Expand Down Expand Up @@ -1940,8 +1940,8 @@ def get_connectivity_matrix(project_id, row_skeleton_ids, col_skeleton_ids,
FROM treenode_connector t1,
treenode_connector t2
{extra_join}
WHERE t1.skeleton_id = ANY(%(row_skeleton_ids)s::integer[])
AND t2.skeleton_id = ANY(%(col_skeleton_ids)s::integer[])
WHERE t1.skeleton_id = ANY(%(row_skeleton_ids)s::bigint[])
AND t2.skeleton_id = ANY(%(col_skeleton_ids)s::bigint[])
AND t1.connector_id = t2.connector_id
AND t1.relation_id = %(pre_rel_id)s
AND t2.relation_id = %(post_rel_id)s
Expand Down Expand Up @@ -3559,7 +3559,7 @@ def skeletons_by_node_labels(request:HttpRequest, project_id=None) -> JsonRespon
ON t.id = tci.treenode_id
JOIN class_instance ci
ON tci.class_instance_id = ci.id
JOIN UNNEST(%(label_ids)s::int[]) label(id)
JOIN UNNEST(%(label_ids)s::bigint[]) label(id)
ON label.id = ci.id
WHERE ci.project_id = %(project_id)s
AND tci.relation_id = %(labeled_as)s
Expand Down Expand Up @@ -3603,7 +3603,7 @@ def get_skeletons_in_bb(params) -> List:

if skeleton_ids:
extra_joins.append("""
JOIN UNNEST(%(skeleton_ids)s::int[]) query_skeleton(id)
JOIN UNNEST(%(skeleton_ids)s::bigint[]) query_skeleton(id)
ON query_skeleton.id = skeleton.id
""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,7 @@ class Migration(migrations.Migration):

dependencies = [
('catmaid', '0009_ensure_required_project_classes'),
('admin', '0003_logentry_add_action_flag_choices'),
]

operations = [
Expand Down
Loading

0 comments on commit 8ac20a0

Please sign in to comment.