-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential future issue with skeleton_id being stored as integer (4 bytes) instead of bigint (8 bytes). #1848
Comments
I agree that we should migrate the At the moment 32 Bit IDs for Regardless, it seems reasonable to update this column rather sooner than later, especially with new segmentation data-sets coming up (like you already mentioned). In fact @schlegelp hit the 32 Bit |
Thanks. It's fine if the migration runs for a while: good maintenance is worth its weight in gold. |
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. Fixes #1848
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. Fixes #1848
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 should make this change to 64 bit IDs effectively free in terms of needed storage. Fixes #1848
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 should make this change to 64 bit IDs effectively free in terms of needed storage. Fixes #1848
The migration to update all The commit has more details, but I also added a couple of missing foreign key constraints, changed the @schlegelp: I updated the |
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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. Fixes #1848
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;
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;
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 98 vs 99 as well as 99 vs (99 -> 98) (i.e. a rollback). These migrations look reasonable and the effective migration (diff) from 98 to 99 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 catmaid/CATMAID#1848 --- Effective migration 99: ALTER SEQUENCE public.catmaid_sampler_id_seq AS integer MAXVALUE 2147483647; CREATE SEQUENCE public.skeleton_origin_id_seq AS integer NO MINVALUE NO MAXVALUE; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.cardinality_restriction DROP CONSTRAINT cardinality_restriction_project_id_fkey; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s FOREIGN KEY (sampler_state_id) REFERENCES catmaid_samplerstate(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_sampler_state_id_fkey; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_skeleton_id_fkey; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_user_id_fkey; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_sampler_id_fkey; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_start_node_id_fkey; ALTER TABLE ONLY public.catmaid_samplerdomainend ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomainend DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_end_node_id_fkey; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_start_node_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD COLUMN num_imported_nodes bigint DEFAULT 0 NOT NULL; ALTER TABLE ONLY public.catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_last_editor_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT last_editor_id_fkey FOREIGN KEY (last_editor_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_id_pkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_summary_pkey PRIMARY KEY (skeleton_id); ALTER TABLE ONLY public.change_request ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.change_request ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_connector_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_recipient_id_fkey; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_treenode_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_user_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.change_request ADD CONSTRAINT recipient_id_refs_id FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class ALTER COLUMN class_name SET DATA TYPE character varying(255); ALTER TABLE ONLY public.class ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class DROP CONSTRAINT class_user_id_fkey; ALTER TABLE ONLY public.class DROP CONSTRAINT class_id_pkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_pkey PRIMARY KEY (id); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DATA TYPE character varying(255); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DEFAULT NULL::character varying; ALTER TABLE ONLY public.class__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a DROP NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b DROP NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_class_a_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_class_b_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_project_id_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_relation_id_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_user_id_fkey; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_class__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance ALTER COLUMN class_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_user_id_fkey; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_id_pkey; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_pkey PRIMARY KEY (id); ALTER TABLE ONLY public.class_instance__history ALTER COLUMN class_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a DROP NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b DROP NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance DROP CONSTRAINT class_instance_class_instance_user_id_fkey; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.concept ALTER COLUMN id DROP DEFAULT; ALTER TABLE ONLY public.concept ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.concept DROP CONSTRAINT concept_project_id_fkey; ALTER TABLE ONLY public.concept DROP CONSTRAINT concept_user_id_fkey; ALTER TABLE ONLY public.concept__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_connector_id_fkey; ALTER TABLE ONLY public.connector_class_instance ADD CONSTRAINT connector_class_instance_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) ON DELETE CASCADE; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_project_id_fkey; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_relation_id_fkey; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_user_id_fkey; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.log ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.log ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.log DROP CONSTRAINT log_project_id_fkey; ALTER TABLE ONLY public.log DROP CONSTRAINT log_user_id_fkey; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_point_id_fkey; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_project_id_fkey; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_relation_id_fkey; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_class_instance_sa_id FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_user_id_fkey; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_connector_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_connector_id_fkey; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_point_id_fkey; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_project_id_fkey; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_relation_id_fkey; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_sa_id FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_user_id_fkey; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id DROP NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN region_of_interest_id DROP NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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); ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_project_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_region_of_interest_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_relation_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_user_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.relation ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_project_id_fkey; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_user_id_fkey; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_id_pkey; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_pkey PRIMARY KEY (id); ALTER TABLE ONLY public.relation__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.relation_instance DROP CONSTRAINT relation_instance_project_id_fkey; ALTER TABLE ONLY public.relation_instance DROP CONSTRAINT relation_instance_relation_id_fkey; ALTER TABLE ONLY public.relation_instance DROP CONSTRAINT relation_instance_user_id_fkey; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restricted_link_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id); ALTER TABLE ONLY public.restriction DROP CONSTRAINT restriction_project_id_fkey; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restriction_restricted_link_id_fkey; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restriction_user_id_fkey; ALTER TABLE ONLY public.restriction__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.review ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.review ALTER COLUMN review_time DROP DEFAULT; ALTER TABLE ONLY public.review ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.review ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.review ADD CONSTRAINT review_reviewer_id_refs_id FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_skeleton_id_fkey; ALTER TABLE ONLY public.review ADD CONSTRAINT review_skeleton_id_refs_id FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_treenode_id_fkey; ALTER TABLE ONLY public.review DROP CONSTRAINT review_user_id_fkey; ALTER TABLE ONLY public.review ADD CONSTRAINT treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.review__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.skeleton_origin ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_data_source_id_fkey FOREIGN KEY (data_source_id) REFERENCES data_source(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_data_source_id_fkey1; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_project_id_fkey1; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_skeleton_id_fkey1; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_user_id_fkey1; ALTER TABLE ONLY public.skeleton_origin__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id DROP NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN stack_id DROP NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.stack_class_instance ADD CONSTRAINT stack_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_instance_relation_id_fkey; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_project_id_fkey; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_stack_id_fkey; ALTER TABLE ONLY public.stack_class_instance ADD CONSTRAINT stack_class_instance_stack_id_fkey FOREIGN KEY (stack_id) REFERENCES stack(id); ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_user_id_fkey; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id DROP NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN stack_group_id DROP NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance ADD CONSTRAINT stack_group_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_project_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_relation_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance ADD CONSTRAINT stack_group_class_instance_stack_group_id_fkey FOREIGN KEY (stack_group_id) REFERENCES stack_group(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_user_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.suppressed_virtual_treenode DROP CONSTRAINT suppressed_virtual_treenode_child_id_fkey; ALTER TABLE ONLY public.suppressed_virtual_treenode ADD CONSTRAINT suppressed_vnodes_child_id_refs_id FOREIGN KEY (child_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode DROP CONSTRAINT treenode_editor_id_fkey; ALTER TABLE ONLY public.treenode DROP CONSTRAINT treenode_project_id_fkey; ALTER TABLE ONLY public.treenode DROP CONSTRAINT treenode_user_id_fkey; ALTER TABLE ONLY public.treenode__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_project_id_fkey; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_relation_id_fkey; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_treenode_id_fkey; ALTER TABLE ONLY public.treenode_class_instance ADD CONSTRAINT treenode_class_instance_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_user_id_fkey; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id DROP NOT NULL; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_project_id_fkey; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_relation_id_fkey; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_skeleton_id_fkey; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_user_id_fkey; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.volume_class_instance ADD CONSTRAINT volume_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_project_id_fkey; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_relation_id_fkey; ALTER TABLE ONLY public.volume_class_instance ADD CONSTRAINT volume_class_instance_sa_id FOREIGN KEY (volume_id) REFERENCES catmaid_volume(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_user_id_fkey; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_volume_id_fkey; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; CREATE INDEX catmaid_sampler_project_id_c93395a7 ON public.catmaid_sampler USING btree (project_id); CREATE INDEX catmaid_sampler_sampler_state_id_80e7961f ON public.catmaid_sampler USING btree (sampler_state_id); CREATE INDEX catmaid_sampler_skeleton_id_dfc98008 ON public.catmaid_sampler USING btree (skeleton_id); CREATE INDEX catmaid_sampler_user_id_8d1c228f ON public.catmaid_sampler USING btree (user_id); CREATE INDEX catmaid_skeleton_summary_num_imported_nodes_idx ON public.catmaid_skeleton_summary USING btree (num_imported_nodes); CREATE INDEX catmaid_skeleton_summary_project_id_7340fa33 ON public.catmaid_skeleton_summary USING btree (project_id); CREATE UNIQUE INDEX point_connector_project_id_uniq ON public.point_connector USING btree (project_id, point_id, connector_id, relation_id); CREATE INDEX review_project_id ON public.review USING btree (project_id); CREATE INDEX review_reviewer_id ON public.review USING btree (reviewer_id); CREATE INDEX review_skeleton_id ON public.review USING btree (skeleton_id); CREATE INDEX review_treenode_id ON public.review USING btree (treenode_id); CREATE INDEX treenode_class_instance_class_instance_id ON public.treenode_class_instance USING btree (class_instance_id); CREATE INDEX treenode_class_instance_project_id ON public.treenode_class_instance USING btree (project_id); CREATE INDEX treenode_class_instance_relation_id ON public.treenode_class_instance USING btree (relation_id); CREATE INDEX treenode_class_instance_treenode_id ON public.treenode_class_instance USING btree (treenode_id); CREATE INDEX treenode_class_instance_user_id ON public.treenode_class_instance USING btree (user_id); CREATE INDEX treenode_connector_connector_id ON public.treenode_connector USING btree (connector_id); CREATE INDEX treenode_connector_creation_time_idx ON public.treenode_connector USING btree (creation_time); CREATE INDEX treenode_connector_project_id ON public.treenode_connector USING btree (project_id); CREATE UNIQUE INDEX treenode_connector_project_id_uniq ON public.treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id); CREATE INDEX treenode_connector_relation_id ON public.treenode_connector USING btree (relation_id); CREATE INDEX treenode_connector_skeleton_id ON public.treenode_connector USING btree (skeleton_id); CREATE INDEX treenode_connector_treenode_id ON public.treenode_connector USING btree (treenode_id); CREATE INDEX treenode_connector_user_id ON public.treenode_connector USING btree (user_id); CREATE INDEX treenode_creation_time_index ON public.treenode USING btree (creation_time); CREATE INDEX treenode_edition_time_index ON public.treenode USING btree (edition_time); CREATE INDEX treenode_location_x_index ON public.treenode USING btree (project_id, location_x); CREATE INDEX treenode_location_y_index ON public.treenode USING btree (project_id, location_y); CREATE INDEX treenode_location_z_index ON public.treenode USING btree (project_id, location_z); CREATE INDEX treenode_parent_id ON public.treenode USING btree (parent_id); CREATE INDEX treenode_project_id_skeleton_id_index ON public.treenode USING btree (project_id, skeleton_id); CREATE INDEX treenode_project_id_user_id_index ON public.treenode USING btree (project_id, user_id); CREATE INDEX treenode_skeleton_id_index ON public.treenode USING btree (skeleton_id); CREATE OR REPLACE FUNCTION public.check_treenode_connector_related_reviews(tc treenode_connector) RETURNS void LANGUAGE plpgsql VOLATILE AS $$BEGIN -- Mark linked treenodes as unreviewed. If relation is postsynaptic, -- mark only one, otherwise mark all treenodes related to connector. IF EXISTS (SELECT 1 FROM relation WHERE id = tc.relation_id AND relation_name = 'postsynaptic_to') THEN DELETE FROM review WHERE treenode_id = tc.treenode_id; ELSE DELETE FROM review r USING treenode_connector tc2 WHERE r.treenode_id = tc2.treenode_id AND tc2.connector_id = tc.connector_id; END IF; END; $$; CREATE OR REPLACE FUNCTION public.drop_history_table(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', history_table_name); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_update_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_truncate_trigger_name(), live_table); EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', get_tracking_table_name(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_regular(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_tracking(), live_table); EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', get_history_update_fn_name_regular(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_truncate_trigger_name(), live_table); -- Remove from created table log DELETE FROM catmaid_history_table cht WHERE cht.live_table = $1; END; $$; CREATE OR REPLACE FUNCTION public.update_history_cardinality_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO cardinality_restriction__history (id,user_id,creation_time,edition_time,project_id,enabled,restricted_link_id,cardinality_type,value,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.enabled,ot.restricted_link_id,ot.cardinality_type,ot.value,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_change_request_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO change_request__history (id,user_id,creation_time,edition_time,project_id,type,description,status,recipient_id,location,treenode_id,connector_id,validate_action,approve_action,reject_action,completion_time,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.type,ot.description,ot.status,ot.recipient_id,ot.location,ot.treenode_id,ot.connector_id,ot.validate_action,ot.approve_action,ot.reject_action,ot.completion_time,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_class__history (id,user_id,creation_time,edition_time,project_id,relation_id,class_a,class_b,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.class_a,ot.class_b,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,class_instance_a,class_instance_b,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.class_instance_a,ot.class_instance_b,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance__history (id,user_id,creation_time,edition_time,project_id,class_id,name,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.class_id,ot.name,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class__history (id,user_id,creation_time,edition_time,project_id,class_name,description,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.class_name,ot.description,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_concept_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO concept__history (id,user_id,creation_time,edition_time,project_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_connector_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO connector_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,connector_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.connector_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,point_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.point_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_connector__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,point_id,connector_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.point_id,ot.connector_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_region_of_interest_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO region_of_interest_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,region_of_interest_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.region_of_interest_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation__history (id,user_id,creation_time,edition_time,project_id,relation_name,uri,description,isreciprocal,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_name,ot.uri,ot.description,ot.isreciprocal,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO restriction__history (id,user_id,creation_time,edition_time,project_id,enabled,restricted_link_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.enabled,ot.restricted_link_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,stack_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.stack_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_group_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_group_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,stack_group_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.stack_group_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,treenode_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.treenode_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_connector__history (id,user_id,creation_time,edition_time,project_id,relation_id,treenode_id,connector_id,skeleton_id,confidence,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.treenode_id,ot.connector_id,ot.skeleton_id,ot.confidence,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode__history (id,project_id,location_x,location_y,location_z,editor_id,user_id,creation_time,edition_time,skeleton_id,radius,confidence,parent_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.project_id,ot.location_x,ot.location_y,ot.location_z,ot.editor_id,ot.user_id,ot.creation_time,ot.edition_time,ot.skeleton_id,ot.radius,ot.confidence,ot.parent_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_volume_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO volume_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,volume_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.volume_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; DROP SEQUENCE public.skeleton_origin_id_seq1; DROP INDEX public.catmaid_sampler_project_id_idx; DROP INDEX public.catmaid_sampler_sampler_state_id_idx; DROP INDEX public.catmaid_sampler_skeleton_id_idx; DROP INDEX public.catmaid_sampler_user_id_idx; DROP INDEX public.catmaid_skeleton_summary_project_id_idx; DROP INDEX public.class_class_name_idx; DROP INDEX public.guardian_gr_content_ae6aec_idx; DROP INDEX public.guardian_us_content_179ed2_idx; DROP INDEX public.point_connector_project_id_point_id_connector_id_relation_id_un; DROP INDEX public.review_project_id_idx; DROP INDEX public.review_reviewer_id_idx; DROP INDEX public.review_skeleton_id_idx; DROP INDEX public.review_treenode_id_idx; DROP INDEX public.treenode_class_instance_class_instance_id_idx; DROP INDEX public.treenode_class_instance_project_id_idx; DROP INDEX public.treenode_class_instance_relation_id_idx; DROP INDEX public.treenode_class_instance_treenode_id_idx; DROP INDEX public.treenode_class_instance_user_id_idx; DROP INDEX public.treenode_connector_connector_id_idx; DROP INDEX public.treenode_connector_creation_time_idx_idx; DROP INDEX public.treenode_connector_project_id_idx; DROP INDEX public.treenode_connector_project_id_treenode_id_connector_id_relation; DROP INDEX public.treenode_connector_relation_id_idx; DROP INDEX public.treenode_connector_skeleton_id_idx; DROP INDEX public.treenode_connector_treenode_id_idx; DROP INDEX public.treenode_connector_user_id_idx; DROP INDEX public.treenode_creation_time_idx; DROP INDEX public.treenode_edition_time_idx; DROP INDEX public.treenode_parent_id_idx; DROP INDEX public.treenode_project_id_location_x_idx; DROP INDEX public.treenode_project_id_location_y_idx; DROP INDEX public.treenode_project_id_location_z_idx; DROP INDEX public.treenode_project_id_user_id_idx; DROP INDEX public.treenode_skeleton_id_project_id_idx; DROP FUNCTION public.drop_history_table_keep_data(live_table regclass); DROP TRIGGER on_edit_cardinality_restrictions ON public.cardinality_restriction; DROP TRIGGER on_edit_point_class_instance ON public.point_class_instance; DROP TRIGGER on_edit_point_connector ON public.point_connector; DROP TRIGGER on_edit_region_of_interest_class_instance ON public.region_of_interest_class_instance; DROP TRIGGER on_stack_class_instance ON public.stack_class_instance; DROP TRIGGER on_stack_group_class_instance ON public.stack_group_class_instance; DROP TRIGGER on_edit_volume_class_instance ON public.volume_class_instance;
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 98 vs 99 as well as 99 vs (99 -> 98) (i.e. a rollback). These migrations look reasonable and the effective migration (diff) from 98 to 99 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 catmaid/CATMAID#1848 --- Effective migration 99: ALTER SEQUENCE public.catmaid_sampler_id_seq AS integer MAXVALUE 2147483647; CREATE SEQUENCE public.skeleton_origin_id_seq AS integer NO MINVALUE NO MAXVALUE; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.cardinality_restriction DROP CONSTRAINT cardinality_restriction_project_id_fkey; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s FOREIGN KEY (sampler_state_id) REFERENCES catmaid_samplerstate(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_sampler_state_id_fkey; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_skeleton_id_fkey; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_user_id_fkey; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_sampler_id_fkey; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_start_node_id_fkey; ALTER TABLE ONLY public.catmaid_samplerdomainend ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomainend DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_end_node_id_fkey; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_start_node_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD COLUMN num_imported_nodes bigint DEFAULT 0 NOT NULL; ALTER TABLE ONLY public.catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_last_editor_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT last_editor_id_fkey FOREIGN KEY (last_editor_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_id_pkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_summary_pkey PRIMARY KEY (skeleton_id); ALTER TABLE ONLY public.change_request ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.change_request ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_connector_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_recipient_id_fkey; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_treenode_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_user_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.change_request ADD CONSTRAINT recipient_id_refs_id FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class ALTER COLUMN class_name SET DATA TYPE character varying(255); ALTER TABLE ONLY public.class ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class DROP CONSTRAINT class_user_id_fkey; ALTER TABLE ONLY public.class DROP CONSTRAINT class_id_pkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_pkey PRIMARY KEY (id); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DATA TYPE character varying(255); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DEFAULT NULL::character varying; ALTER TABLE ONLY public.class__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a DROP NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b DROP NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_class_a_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_class_b_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_project_id_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_relation_id_fkey; ALTER TABLE ONLY public.class_class DROP CONSTRAINT class_class_user_id_fkey; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_class__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_class__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance ALTER COLUMN class_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_user_id_fkey; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_id_pkey; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_pkey PRIMARY KEY (id); ALTER TABLE ONLY public.class_instance__history ALTER COLUMN class_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a DROP NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b DROP NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance DROP CONSTRAINT class_instance_class_instance_user_id_fkey; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.concept ALTER COLUMN id DROP DEFAULT; ALTER TABLE ONLY public.concept ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.concept DROP CONSTRAINT concept_project_id_fkey; ALTER TABLE ONLY public.concept DROP CONSTRAINT concept_user_id_fkey; ALTER TABLE ONLY public.concept__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_connector_id_fkey; ALTER TABLE ONLY public.connector_class_instance ADD CONSTRAINT connector_class_instance_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) ON DELETE CASCADE; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_project_id_fkey; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_relation_id_fkey; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_user_id_fkey; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.log ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.log ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.log DROP CONSTRAINT log_project_id_fkey; ALTER TABLE ONLY public.log DROP CONSTRAINT log_user_id_fkey; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_point_id_fkey; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_project_id_fkey; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_relation_id_fkey; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_class_instance_sa_id FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_user_id_fkey; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_connector_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_connector_id_fkey; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_connector_id_fkey FOREIGN KEY (connector_id) REFERENCES connector(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_point_id_fkey; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_project_id_fkey; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_relation_id_fkey; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_sa_id FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_user_id_fkey; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id DROP NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN region_of_interest_id DROP NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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); ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_project_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_region_of_interest_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_relation_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_user_id_fkey; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.relation ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_project_id_fkey; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_user_id_fkey; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_id_pkey; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_pkey PRIMARY KEY (id); ALTER TABLE ONLY public.relation__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.relation_instance DROP CONSTRAINT relation_instance_project_id_fkey; ALTER TABLE ONLY public.relation_instance DROP CONSTRAINT relation_instance_relation_id_fkey; ALTER TABLE ONLY public.relation_instance DROP CONSTRAINT relation_instance_user_id_fkey; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restricted_link_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id); ALTER TABLE ONLY public.restriction DROP CONSTRAINT restriction_project_id_fkey; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restriction_restricted_link_id_fkey; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restriction_user_id_fkey; ALTER TABLE ONLY public.restriction__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE integer; ALTER TABLE ONLY public.review ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.review ALTER COLUMN review_time DROP DEFAULT; ALTER TABLE ONLY public.review ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.review ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.review ADD CONSTRAINT review_reviewer_id_refs_id FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_skeleton_id_fkey; ALTER TABLE ONLY public.review ADD CONSTRAINT review_skeleton_id_refs_id FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_treenode_id_fkey; ALTER TABLE ONLY public.review DROP CONSTRAINT review_user_id_fkey; ALTER TABLE ONLY public.review ADD CONSTRAINT treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.review__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.skeleton_origin ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_data_source_id_fkey FOREIGN KEY (data_source_id) REFERENCES data_source(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_data_source_id_fkey1; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_project_id_fkey1; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_skeleton_id_fkey1; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_user_id_fkey1; ALTER TABLE ONLY public.skeleton_origin__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id DROP NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN stack_id DROP NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.stack_class_instance ADD CONSTRAINT stack_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_instance_relation_id_fkey; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_project_id_fkey; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_stack_id_fkey; ALTER TABLE ONLY public.stack_class_instance ADD CONSTRAINT stack_class_instance_stack_id_fkey FOREIGN KEY (stack_id) REFERENCES stack(id); ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_user_id_fkey; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id DROP NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN stack_group_id DROP NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance ADD CONSTRAINT stack_group_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_project_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_relation_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance ADD CONSTRAINT stack_group_class_instance_stack_group_id_fkey FOREIGN KEY (stack_group_id) REFERENCES stack_group(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_user_id_fkey; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.suppressed_virtual_treenode DROP CONSTRAINT suppressed_virtual_treenode_child_id_fkey; ALTER TABLE ONLY public.suppressed_virtual_treenode ADD CONSTRAINT suppressed_vnodes_child_id_refs_id FOREIGN KEY (child_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode DROP CONSTRAINT treenode_editor_id_fkey; ALTER TABLE ONLY public.treenode DROP CONSTRAINT treenode_project_id_fkey; ALTER TABLE ONLY public.treenode DROP CONSTRAINT treenode_user_id_fkey; ALTER TABLE ONLY public.treenode__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_project_id_fkey; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_relation_id_fkey; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_treenode_id_fkey; ALTER TABLE ONLY public.treenode_class_instance ADD CONSTRAINT treenode_class_instance_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_user_id_fkey; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id DROP NOT NULL; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_project_id_fkey; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_relation_id_fkey; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_skeleton_id_fkey; ALTER TABLE ONLY public.treenode_connector DROP CONSTRAINT treenode_connector_user_id_fkey; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN relation_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN txid DROP NOT NULL; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.volume_class_instance ADD CONSTRAINT volume_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_project_id_fkey; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_relation_id_fkey; ALTER TABLE ONLY public.volume_class_instance ADD CONSTRAINT volume_class_instance_sa_id FOREIGN KEY (volume_id) REFERENCES catmaid_volume(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_user_id_fkey; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_volume_id_fkey; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN id SET DATA TYPE integer; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE integer; CREATE INDEX catmaid_sampler_project_id_c93395a7 ON public.catmaid_sampler USING btree (project_id); CREATE INDEX catmaid_sampler_sampler_state_id_80e7961f ON public.catmaid_sampler USING btree (sampler_state_id); CREATE INDEX catmaid_sampler_skeleton_id_dfc98008 ON public.catmaid_sampler USING btree (skeleton_id); CREATE INDEX catmaid_sampler_user_id_8d1c228f ON public.catmaid_sampler USING btree (user_id); CREATE INDEX catmaid_skeleton_summary_num_imported_nodes_idx ON public.catmaid_skeleton_summary USING btree (num_imported_nodes); CREATE INDEX catmaid_skeleton_summary_project_id_7340fa33 ON public.catmaid_skeleton_summary USING btree (project_id); CREATE UNIQUE INDEX point_connector_project_id_uniq ON public.point_connector USING btree (project_id, point_id, connector_id, relation_id); CREATE INDEX review_project_id ON public.review USING btree (project_id); CREATE INDEX review_reviewer_id ON public.review USING btree (reviewer_id); CREATE INDEX review_skeleton_id ON public.review USING btree (skeleton_id); CREATE INDEX review_treenode_id ON public.review USING btree (treenode_id); CREATE INDEX treenode_class_instance_class_instance_id ON public.treenode_class_instance USING btree (class_instance_id); CREATE INDEX treenode_class_instance_project_id ON public.treenode_class_instance USING btree (project_id); CREATE INDEX treenode_class_instance_relation_id ON public.treenode_class_instance USING btree (relation_id); CREATE INDEX treenode_class_instance_treenode_id ON public.treenode_class_instance USING btree (treenode_id); CREATE INDEX treenode_class_instance_user_id ON public.treenode_class_instance USING btree (user_id); CREATE INDEX treenode_connector_connector_id ON public.treenode_connector USING btree (connector_id); CREATE INDEX treenode_connector_creation_time_idx ON public.treenode_connector USING btree (creation_time); CREATE INDEX treenode_connector_project_id ON public.treenode_connector USING btree (project_id); CREATE UNIQUE INDEX treenode_connector_project_id_uniq ON public.treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id); CREATE INDEX treenode_connector_relation_id ON public.treenode_connector USING btree (relation_id); CREATE INDEX treenode_connector_skeleton_id ON public.treenode_connector USING btree (skeleton_id); CREATE INDEX treenode_connector_treenode_id ON public.treenode_connector USING btree (treenode_id); CREATE INDEX treenode_connector_user_id ON public.treenode_connector USING btree (user_id); CREATE INDEX treenode_creation_time_index ON public.treenode USING btree (creation_time); CREATE INDEX treenode_edition_time_index ON public.treenode USING btree (edition_time); CREATE INDEX treenode_location_x_index ON public.treenode USING btree (project_id, location_x); CREATE INDEX treenode_location_y_index ON public.treenode USING btree (project_id, location_y); CREATE INDEX treenode_location_z_index ON public.treenode USING btree (project_id, location_z); CREATE INDEX treenode_parent_id ON public.treenode USING btree (parent_id); CREATE INDEX treenode_project_id_skeleton_id_index ON public.treenode USING btree (project_id, skeleton_id); CREATE INDEX treenode_project_id_user_id_index ON public.treenode USING btree (project_id, user_id); CREATE INDEX treenode_skeleton_id_index ON public.treenode USING btree (skeleton_id); CREATE OR REPLACE FUNCTION public.check_treenode_connector_related_reviews(tc treenode_connector) RETURNS void LANGUAGE plpgsql VOLATILE AS $$BEGIN -- Mark linked treenodes as unreviewed. If relation is postsynaptic, -- mark only one, otherwise mark all treenodes related to connector. IF EXISTS (SELECT 1 FROM relation WHERE id = tc.relation_id AND relation_name = 'postsynaptic_to') THEN DELETE FROM review WHERE treenode_id = tc.treenode_id; ELSE DELETE FROM review r USING treenode_connector tc2 WHERE r.treenode_id = tc2.treenode_id AND tc2.connector_id = tc.connector_id; END IF; END; $$; CREATE OR REPLACE FUNCTION public.drop_history_table(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', history_table_name); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_update_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_truncate_trigger_name(), live_table); EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', get_tracking_table_name(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_regular(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_tracking(), live_table); EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', get_history_update_fn_name_regular(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_truncate_trigger_name(), live_table); -- Remove from created table log DELETE FROM catmaid_history_table cht WHERE cht.live_table = $1; END; $$; CREATE OR REPLACE FUNCTION public.update_history_cardinality_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO cardinality_restriction__history (id,user_id,creation_time,edition_time,project_id,enabled,restricted_link_id,cardinality_type,value,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.enabled,ot.restricted_link_id,ot.cardinality_type,ot.value,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_change_request_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO change_request__history (id,user_id,creation_time,edition_time,project_id,type,description,status,recipient_id,location,treenode_id,connector_id,validate_action,approve_action,reject_action,completion_time,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.type,ot.description,ot.status,ot.recipient_id,ot.location,ot.treenode_id,ot.connector_id,ot.validate_action,ot.approve_action,ot.reject_action,ot.completion_time,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_class__history (id,user_id,creation_time,edition_time,project_id,relation_id,class_a,class_b,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.class_a,ot.class_b,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,class_instance_a,class_instance_b,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.class_instance_a,ot.class_instance_b,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance__history (id,user_id,creation_time,edition_time,project_id,class_id,name,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.class_id,ot.name,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class__history (id,user_id,creation_time,edition_time,project_id,class_name,description,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.class_name,ot.description,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_concept_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO concept__history (id,user_id,creation_time,edition_time,project_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_connector_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO connector_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,connector_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.connector_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,point_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.point_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_connector__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,point_id,connector_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.point_id,ot.connector_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_region_of_interest_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO region_of_interest_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,region_of_interest_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.region_of_interest_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation__history (id,user_id,creation_time,edition_time,project_id,relation_name,uri,description,isreciprocal,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_name,ot.uri,ot.description,ot.isreciprocal,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO restriction__history (id,user_id,creation_time,edition_time,project_id,enabled,restricted_link_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.enabled,ot.restricted_link_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,stack_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.stack_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_group_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_group_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,stack_group_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.stack_group_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,treenode_id,class_instance_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.treenode_id,ot.class_instance_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_connector__history (id,user_id,creation_time,edition_time,project_id,relation_id,treenode_id,connector_id,skeleton_id,confidence,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.treenode_id,ot.connector_id,ot.skeleton_id,ot.confidence,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode__history (id,project_id,location_x,location_y,location_z,editor_id,user_id,creation_time,edition_time,skeleton_id,radius,confidence,parent_id,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.project_id,ot.location_x,ot.location_y,ot.location_z,ot.editor_id,ot.user_id,ot.creation_time,ot.edition_time,ot.skeleton_id,ot.radius,ot.confidence,ot.parent_id,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_volume_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO volume_class_instance__history (id,user_id,creation_time,edition_time,project_id,relation_id,txid,volume_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.creation_time,ot.edition_time,ot.project_id,ot.relation_id,ot.txid,ot.volume_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; DROP SEQUENCE public.skeleton_origin_id_seq1; DROP INDEX public.catmaid_sampler_project_id_idx; DROP INDEX public.catmaid_sampler_sampler_state_id_idx; DROP INDEX public.catmaid_sampler_skeleton_id_idx; DROP INDEX public.catmaid_sampler_user_id_idx; DROP INDEX public.catmaid_skeleton_summary_project_id_idx; DROP INDEX public.class_class_name_idx; DROP INDEX public.guardian_gr_content_ae6aec_idx; DROP INDEX public.guardian_us_content_179ed2_idx; DROP INDEX public.point_connector_project_id_point_id_connector_id_relation_id_un; DROP INDEX public.review_project_id_idx; DROP INDEX public.review_reviewer_id_idx; DROP INDEX public.review_skeleton_id_idx; DROP INDEX public.review_treenode_id_idx; DROP INDEX public.treenode_class_instance_class_instance_id_idx; DROP INDEX public.treenode_class_instance_project_id_idx; DROP INDEX public.treenode_class_instance_relation_id_idx; DROP INDEX public.treenode_class_instance_treenode_id_idx; DROP INDEX public.treenode_class_instance_user_id_idx; DROP INDEX public.treenode_connector_connector_id_idx; DROP INDEX public.treenode_connector_creation_time_idx_idx; DROP INDEX public.treenode_connector_project_id_idx; DROP INDEX public.treenode_connector_project_id_treenode_id_connector_id_relation; DROP INDEX public.treenode_connector_relation_id_idx; DROP INDEX public.treenode_connector_skeleton_id_idx; DROP INDEX public.treenode_connector_treenode_id_idx; DROP INDEX public.treenode_connector_user_id_idx; DROP INDEX public.treenode_creation_time_idx; DROP INDEX public.treenode_edition_time_idx; DROP INDEX public.treenode_parent_id_idx; DROP INDEX public.treenode_project_id_location_x_idx; DROP INDEX public.treenode_project_id_location_y_idx; DROP INDEX public.treenode_project_id_location_z_idx; DROP INDEX public.treenode_project_id_user_id_idx; DROP INDEX public.treenode_skeleton_id_project_id_idx; DROP FUNCTION public.drop_history_table_keep_data(live_table regclass); DROP TRIGGER on_edit_cardinality_restrictions ON public.cardinality_restriction; DROP TRIGGER on_edit_point_class_instance ON public.point_class_instance; DROP TRIGGER on_edit_point_connector ON public.point_connector; DROP TRIGGER on_edit_region_of_interest_class_instance ON public.region_of_interest_class_instance; DROP TRIGGER on_stack_class_instance ON public.stack_class_instance; DROP TRIGGER on_stack_group_class_instance ON public.stack_group_class_instance; DROP TRIGGER on_edit_volume_class_instance ON public.volume_class_instance;
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 98 vs 99 as well as 99 vs (99 -> 98) (i.e. a rollback). These migrations look reasonable and the effective migration (diff) from 98 to 99 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 catmaid/CATMAID#1848 --- Effective migration 99: ALTER SEQUENCE public.catmaid_sampler_id_seq AS bigint MAXVALUE 9223372036854775807; CREATE SEQUENCE public.skeleton_origin_id_seq1 NO MINVALUE NO MAXVALUE; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.cardinality_restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_sampler_id_fkey FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id); ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomainend DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomainend ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP COLUMN num_imported_nodes; ALTER TABLE ONLY public.catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT last_editor_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_pkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_id_pkey PRIMARY KEY (skeleton_id) INCLUDE (num_nodes); ALTER TABLE ONLY public.change_request ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.change_request ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_connector_id_fkey; ALTER TABLE ONLY public.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 public.change_request ADD CONSTRAINT change_request_recipient_id_fkey FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_treenode_id_fkey; ALTER TABLE ONLY public.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 public.change_request DROP CONSTRAINT change_request_user_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT recipient_id_refs_id; ALTER TABLE ONLY public.change_request__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class ADD CONSTRAINT class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class DROP CONSTRAINT class_pkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_id_pkey PRIMARY KEY (id) INCLUDE (project_id, class_name); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class__history ALTER COLUMN class_name DROP DEFAULT; ALTER TABLE ONLY public.class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.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 public.class_class ADD CONSTRAINT class_class_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_class ADD CONSTRAINT class_class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_pkey; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_id_pkey PRIMARY KEY (id) INCLUDE (class_id, project_id, name); ALTER TABLE ONLY public.class_instance__history ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DEFAULT nextval('concept_id_seq'::regclass); ALTER TABLE ONLY public.concept ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.connector_class_instance DROP CONSTRAINT connector_class_instance_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.connector_class_instance ADD CONSTRAINT connector_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.log ADD CONSTRAINT log_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.log ADD CONSTRAINT log_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_point_id_fkey FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_sa_id; ALTER TABLE ONLY public.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 public.point_class_instance DROP CONSTRAINT point_connector_class_instance_id_fkey; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.point_connector ADD CONSTRAINT point_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_sa_id; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN region_of_interest_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.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 public.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 public.region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_pkey; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_id_pkey PRIMARY KEY (id) INCLUDE (project_id, relation_name); ALTER TABLE ONLY public.relation__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.relation_instance ADD CONSTRAINT relation_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance ADD CONSTRAINT relation_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restricted_link_fkey; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_restricted_link_id_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id); ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN review_time SET DEFAULT now(); ALTER TABLE ONLY public.review ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.review DROP CONSTRAINT review_reviewer_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_skeleton_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review ADD CONSTRAINT review_user_id_fkey FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT treenode_id_fkey; ALTER TABLE ONLY public.review__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_data_source_id_fkey; ALTER TABLE ONLY public.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 public.skeleton_origin DROP CONSTRAINT skeleton_origin_project_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_skeleton_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_skeleton_id_fkey1 FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_user_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_user_id_fkey1 FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.skeleton_origin__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN stack_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_class_instance DROP CONSTRAINT stack_class_instance_stack_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN stack_group_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.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 public.suppressed_virtual_treenode DROP CONSTRAINT suppressed_vnodes_child_id_refs_id; ALTER TABLE ONLY public.treenode ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_editor_id_fkey FOREIGN KEY (editor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance ADD CONSTRAINT treenode_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_treenode_id_fkey; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET NOT NULL; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.volume_class_instance DROP CONSTRAINT volume_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.volume_class_instance ADD CONSTRAINT volume_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_sa_id; ALTER TABLE ONLY public.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 public.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 public.volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; CREATE INDEX catmaid_sampler_project_id_idx ON public.catmaid_sampler USING btree (project_id); CREATE INDEX catmaid_sampler_sampler_state_id_idx ON public.catmaid_sampler USING btree (sampler_state_id); CREATE INDEX catmaid_sampler_skeleton_id_idx ON public.catmaid_sampler USING btree (skeleton_id); CREATE INDEX catmaid_sampler_user_id_idx ON public.catmaid_sampler USING btree (user_id); CREATE INDEX catmaid_skeleton_summary_project_id_idx ON public.catmaid_skeleton_summary USING btree (project_id); CREATE INDEX class_class_name_idx ON public.class USING btree (class_name) INCLUDE (id, project_id); CREATE INDEX guardian_gr_content_ae6aec_idx ON public.guardian_groupobjectpermission USING btree (content_type_id, object_pk); CREATE INDEX guardian_us_content_179ed2_idx ON public.guardian_userobjectpermission USING btree (content_type_id, object_pk); CREATE UNIQUE INDEX point_connector_project_id_point_id_connector_id_relation_id_un ON public.point_connector USING btree (project_id, point_id, connector_id, relation_id); CREATE INDEX review_project_id_idx ON public.review USING btree (project_id); CREATE INDEX review_reviewer_id_idx ON public.review USING btree (reviewer_id); CREATE INDEX review_skeleton_id_idx ON public.review USING btree (skeleton_id); CREATE INDEX review_treenode_id_idx ON public.review USING btree (treenode_id); CREATE INDEX treenode_class_instance_class_instance_id_idx ON public.treenode_class_instance USING btree (class_instance_id); CREATE INDEX treenode_class_instance_project_id_idx ON public.treenode_class_instance USING btree (project_id); CREATE INDEX treenode_class_instance_relation_id_idx ON public.treenode_class_instance USING btree (relation_id); CREATE INDEX treenode_class_instance_treenode_id_idx ON public.treenode_class_instance USING btree (treenode_id); CREATE INDEX treenode_class_instance_user_id_idx ON public.treenode_class_instance USING btree (user_id); CREATE INDEX treenode_connector_connector_id_idx ON public.treenode_connector USING btree (connector_id); CREATE INDEX treenode_connector_creation_time_idx_idx ON public.treenode_connector USING btree (creation_time); CREATE INDEX treenode_connector_project_id_idx ON public.treenode_connector USING btree (project_id); CREATE UNIQUE INDEX treenode_connector_project_id_treenode_id_connector_id_relation ON public.treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id); CREATE INDEX treenode_connector_relation_id_idx ON public.treenode_connector USING btree (relation_id); CREATE INDEX treenode_connector_skeleton_id_idx ON public.treenode_connector USING btree (skeleton_id); CREATE INDEX treenode_connector_treenode_id_idx ON public.treenode_connector USING btree (treenode_id); CREATE INDEX treenode_connector_user_id_idx ON public.treenode_connector USING btree (user_id); CREATE INDEX treenode_creation_time_idx ON public.treenode USING btree (creation_time); CREATE INDEX treenode_edition_time_idx ON public.treenode USING btree (edition_time); CREATE INDEX treenode_parent_id_idx ON public.treenode USING btree (parent_id); CREATE INDEX treenode_project_id_location_x_idx ON public.treenode USING btree (project_id, location_x); CREATE INDEX treenode_project_id_location_y_idx ON public.treenode USING btree (project_id, location_y); CREATE INDEX treenode_project_id_location_z_idx ON public.treenode USING btree (project_id, location_z); CREATE INDEX treenode_project_id_user_id_idx ON public.treenode USING btree (user_id, project_id); CREATE INDEX treenode_skeleton_id_project_id_idx ON public.treenode USING btree (skeleton_id, project_id); CREATE OR REPLACE FUNCTION public.check_treenode_connector_related_reviews(tc treenode_connector) RETURNS void LANGUAGE plpgsql VOLATILE AS $$BEGIN -- Mark linked treenodes as unreviewed. If relation is postsynaptic, -- mark only one, otherwise mark all treenodes related to connector. IF EXISTS (SELECT 1 FROM relation WHERE id = tc.relation_id AND relation_name = 'postsynaptic_to') THEN DELETE FROM review WHERE treenode_id = tc.treenode_id; ELSE DELETE FROM review r USING treenode_connector tc2 WHERE r.treenode_id = tc2.treenode_id AND tc2.connector_id = tc.connector_id; END IF; END; $$; CREATE OR REPLACE FUNCTION public.drop_history_table(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN PERFORM drop_history_table_keep_data(live_table); -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', get_tracking_table_name(live_table)); EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', history_table_name); END; $$; CREATE FUNCTION public.drop_history_table_keep_data(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_update_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_truncate_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_regular(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_tracking(), live_table); EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', get_history_update_fn_name_regular(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_truncate_trigger_name(), live_table); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_live_pk_index'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_sys_period'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_exec_transaction_id'); -- Remove from created table log DELETE FROM catmaid_history_table cht WHERE cht.live_table = $1; END; $$; CREATE OR REPLACE FUNCTION public.update_history_cardinality_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO cardinality_restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,cardinality_type,value,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id,ot.cardinality_type,ot.value, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_change_request_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO change_request__history (id,user_id,project_id,creation_time,edition_time,txid,type,description,status,recipient_id,location,treenode_id,connector_id,validate_action,approve_action,reject_action,completion_time,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.type,ot.description,ot.status,ot.recipient_id,ot.location,ot.treenode_id,ot.connector_id,ot.validate_action,ot.approve_action,ot.reject_action,ot.completion_time, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_class__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_a,class_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_a,ot.class_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_a,class_instance_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_a,ot.class_instance_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,class_id,name,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_id,ot.name, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class__history (id,user_id,project_id,creation_time,edition_time,txid,class_name,description,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_name,ot.description, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_concept_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO concept__history (id,user_id,project_id,creation_time,edition_time,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_connector_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO connector_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,connector_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.connector_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,connector_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.connector_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_region_of_interest_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO region_of_interest_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,region_of_interest_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.region_of_interest_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation__history (id,user_id,project_id,creation_time,edition_time,txid,relation_name,uri,description,isreciprocal,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_name,ot.uri,ot.description,ot.isreciprocal, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_group_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_group_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_group_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_group_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,connector_id,skeleton_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.connector_id,ot.skeleton_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode__history (id,project_id,location_x,location_y,location_z,editor_id,user_id,creation_time,edition_time,txid,skeleton_id,parent_id,radius,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.project_id,ot.location_x,ot.location_y,ot.location_z,ot.editor_id,ot.user_id,ot.creation_time,ot.edition_time,ot.txid,ot.skeleton_id,ot.parent_id,ot.radius,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_volume_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO volume_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,volume_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.volume_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE TRIGGER on_edit_cardinality_restrictions BEFORE UPDATE ON public.cardinality_restriction FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_class_instance BEFORE UPDATE ON public.point_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_connector BEFORE UPDATE ON public.point_connector FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_region_of_interest_class_instance BEFORE UPDATE ON public.region_of_interest_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_class_instance BEFORE UPDATE ON public.stack_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_group_class_instance BEFORE UPDATE ON public.stack_group_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_volume_class_instance BEFORE UPDATE ON public.volume_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); DROP SEQUENCE public.skeleton_origin_id_seq; DROP INDEX public.catmaid_sampler_project_id_c93395a7; DROP INDEX public.catmaid_sampler_sampler_state_id_80e7961f; DROP INDEX public.catmaid_sampler_skeleton_id_dfc98008; DROP INDEX public.catmaid_sampler_user_id_8d1c228f; DROP INDEX public.catmaid_skeleton_summary_num_imported_nodes_idx; DROP INDEX public.catmaid_skeleton_summary_project_id_7340fa33; DROP INDEX public.point_connector_project_id_uniq; DROP INDEX public.review_project_id; DROP INDEX public.review_reviewer_id; DROP INDEX public.review_skeleton_id; DROP INDEX public.review_treenode_id; DROP INDEX public.treenode_class_instance_class_instance_id; DROP INDEX public.treenode_class_instance_project_id; DROP INDEX public.treenode_class_instance_relation_id; DROP INDEX public.treenode_class_instance_treenode_id; DROP INDEX public.treenode_class_instance_user_id; DROP INDEX public.treenode_connector_connector_id; DROP INDEX public.treenode_connector_creation_time_idx; DROP INDEX public.treenode_connector_project_id; DROP INDEX public.treenode_connector_project_id_uniq; DROP INDEX public.treenode_connector_relation_id; DROP INDEX public.treenode_connector_skeleton_id; DROP INDEX public.treenode_connector_treenode_id; DROP INDEX public.treenode_connector_user_id; DROP INDEX public.treenode_creation_time_index; DROP INDEX public.treenode_edition_time_index; DROP INDEX public.treenode_location_x_index; DROP INDEX public.treenode_location_y_index; DROP INDEX public.treenode_location_z_index; DROP INDEX public.treenode_parent_id; DROP INDEX public.treenode_project_id_skeleton_id_index; DROP INDEX public.treenode_project_id_user_id_index; DROP INDEX public.treenode_skeleton_id_index;
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 98 vs 99 as well as 99 vs (99 -> 98) (i.e. a rollback). These migrations look reasonable and the effective migration (diff) from 98 to 99 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 catmaid/CATMAID#1848 --- Effective migration 99: ALTER SEQUENCE public.catmaid_sampler_id_seq AS bigint MAXVALUE 9223372036854775807; CREATE SEQUENCE public.skeleton_origin_id_seq1 NO MINVALUE NO MAXVALUE; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.cardinality_restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_sampler_id_fkey FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id); ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomainend DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomainend ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD COLUMN import_cable_length double precision DEFAULT 0 NOT NULL; ALTER TABLE ONLY public.catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT last_editor_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_pkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_id_pkey PRIMARY KEY (skeleton_id) INCLUDE (num_nodes); ALTER TABLE ONLY public.change_request ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.change_request ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_connector_id_fkey; ALTER TABLE ONLY public.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 public.change_request ADD CONSTRAINT change_request_recipient_id_fkey FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_treenode_id_fkey; ALTER TABLE ONLY public.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 public.change_request DROP CONSTRAINT change_request_user_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT recipient_id_refs_id; ALTER TABLE ONLY public.change_request__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class ADD CONSTRAINT class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class DROP CONSTRAINT class_pkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_id_pkey PRIMARY KEY (id) INCLUDE (project_id, class_name); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class__history ALTER COLUMN class_name DROP DEFAULT; ALTER TABLE ONLY public.class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.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 public.class_class ADD CONSTRAINT class_class_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_class ADD CONSTRAINT class_class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_pkey; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_id_pkey PRIMARY KEY (id) INCLUDE (class_id, project_id, name); ALTER TABLE ONLY public.class_instance__history ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DEFAULT nextval('concept_id_seq'::regclass); ALTER TABLE ONLY public.concept ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.connector_class_instance DROP CONSTRAINT connector_class_instance_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.connector_class_instance ADD CONSTRAINT connector_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.log ADD CONSTRAINT log_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.log ADD CONSTRAINT log_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_point_id_fkey FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_sa_id; ALTER TABLE ONLY public.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 public.point_class_instance DROP CONSTRAINT point_connector_class_instance_id_fkey; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.point_connector ADD CONSTRAINT point_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_sa_id; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN region_of_interest_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.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 public.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 public.region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_pkey; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_id_pkey PRIMARY KEY (id) INCLUDE (project_id, relation_name); ALTER TABLE ONLY public.relation__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.relation_instance ADD CONSTRAINT relation_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance ADD CONSTRAINT relation_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restricted_link_fkey; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_restricted_link_id_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id); ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN review_time SET DEFAULT now(); ALTER TABLE ONLY public.review ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.review DROP CONSTRAINT review_reviewer_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_skeleton_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review ADD CONSTRAINT review_user_id_fkey FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT treenode_id_fkey; ALTER TABLE ONLY public.review__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_data_source_id_fkey; ALTER TABLE ONLY public.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 public.skeleton_origin DROP CONSTRAINT skeleton_origin_project_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_skeleton_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_skeleton_id_fkey1 FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_user_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_user_id_fkey1 FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.skeleton_origin__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN stack_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_class_instance DROP CONSTRAINT stack_class_instance_stack_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN stack_group_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.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 public.suppressed_virtual_treenode DROP CONSTRAINT suppressed_vnodes_child_id_refs_id; ALTER TABLE ONLY public.treenode ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_editor_id_fkey FOREIGN KEY (editor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance ADD CONSTRAINT treenode_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_treenode_id_fkey; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET NOT NULL; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.volume_class_instance DROP CONSTRAINT volume_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.volume_class_instance ADD CONSTRAINT volume_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_sa_id; ALTER TABLE ONLY public.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 public.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 public.volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; CREATE INDEX catmaid_sampler_project_id_idx ON public.catmaid_sampler USING btree (project_id); CREATE INDEX catmaid_sampler_sampler_state_id_idx ON public.catmaid_sampler USING btree (sampler_state_id); CREATE INDEX catmaid_sampler_skeleton_id_idx ON public.catmaid_sampler USING btree (skeleton_id); CREATE INDEX catmaid_sampler_user_id_idx ON public.catmaid_sampler USING btree (user_id); CREATE INDEX catmaid_skeleton_summary_project_id_idx ON public.catmaid_skeleton_summary USING btree (project_id); CREATE INDEX class_class_name_idx ON public.class USING btree (class_name) INCLUDE (id, project_id); CREATE INDEX guardian_gr_content_ae6aec_idx ON public.guardian_groupobjectpermission USING btree (content_type_id, object_pk); CREATE INDEX guardian_us_content_179ed2_idx ON public.guardian_userobjectpermission USING btree (content_type_id, object_pk); CREATE UNIQUE INDEX point_connector_project_id_point_id_connector_id_relation_id_un ON public.point_connector USING btree (project_id, point_id, connector_id, relation_id); CREATE INDEX review_project_id_idx ON public.review USING btree (project_id); CREATE INDEX review_reviewer_id_idx ON public.review USING btree (reviewer_id); CREATE INDEX review_skeleton_id_idx ON public.review USING btree (skeleton_id); CREATE INDEX review_treenode_id_idx ON public.review USING btree (treenode_id); CREATE INDEX treenode_class_instance_class_instance_id_idx ON public.treenode_class_instance USING btree (class_instance_id); CREATE INDEX treenode_class_instance_project_id_idx ON public.treenode_class_instance USING btree (project_id); CREATE INDEX treenode_class_instance_relation_id_idx ON public.treenode_class_instance USING btree (relation_id); CREATE INDEX treenode_class_instance_treenode_id_idx ON public.treenode_class_instance USING btree (treenode_id); CREATE INDEX treenode_class_instance_user_id_idx ON public.treenode_class_instance USING btree (user_id); CREATE INDEX treenode_connector_connector_id_idx ON public.treenode_connector USING btree (connector_id); CREATE INDEX treenode_connector_creation_time_idx_idx ON public.treenode_connector USING btree (creation_time); CREATE INDEX treenode_connector_project_id_idx ON public.treenode_connector USING btree (project_id); CREATE UNIQUE INDEX treenode_connector_project_id_treenode_id_connector_id_relation ON public.treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id); CREATE INDEX treenode_connector_relation_id_idx ON public.treenode_connector USING btree (relation_id); CREATE INDEX treenode_connector_skeleton_id_idx ON public.treenode_connector USING btree (skeleton_id); CREATE INDEX treenode_connector_treenode_id_idx ON public.treenode_connector USING btree (treenode_id); CREATE INDEX treenode_connector_user_id_idx ON public.treenode_connector USING btree (user_id); CREATE INDEX treenode_creation_time_idx ON public.treenode USING btree (creation_time); CREATE INDEX treenode_edition_time_idx ON public.treenode USING btree (edition_time); CREATE INDEX treenode_parent_id_idx ON public.treenode USING btree (parent_id); CREATE INDEX treenode_project_id_location_x_idx ON public.treenode USING btree (project_id, location_x); CREATE INDEX treenode_project_id_location_y_idx ON public.treenode USING btree (project_id, location_y); CREATE INDEX treenode_project_id_location_z_idx ON public.treenode USING btree (project_id, location_z); CREATE INDEX treenode_project_id_user_id_idx ON public.treenode USING btree (user_id, project_id); CREATE INDEX treenode_skeleton_id_project_id_idx ON public.treenode USING btree (skeleton_id, project_id); CREATE OR REPLACE FUNCTION public.check_treenode_connector_related_reviews(tc treenode_connector) RETURNS void LANGUAGE plpgsql VOLATILE AS $$BEGIN -- Mark linked treenodes as unreviewed. If relation is postsynaptic, -- mark only one, otherwise mark all treenodes related to connector. IF EXISTS (SELECT 1 FROM relation WHERE id = tc.relation_id AND relation_name = 'postsynaptic_to') THEN DELETE FROM review WHERE treenode_id = tc.treenode_id; ELSE DELETE FROM review r USING treenode_connector tc2 WHERE r.treenode_id = tc2.treenode_id AND tc2.connector_id = tc.connector_id; END IF; END; $$; CREATE OR REPLACE FUNCTION public.drop_history_table(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN PERFORM drop_history_table_keep_data(live_table); -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', get_tracking_table_name(live_table)); EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', history_table_name); END; $$; CREATE FUNCTION public.drop_history_table_keep_data(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_update_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_truncate_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_regular(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_tracking(), live_table); EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', get_history_update_fn_name_regular(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_truncate_trigger_name(), live_table); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_live_pk_index'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_sys_period'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_exec_transaction_id'); -- Remove from created table log DELETE FROM catmaid_history_table cht WHERE cht.live_table = $1; END; $$; CREATE OR REPLACE FUNCTION public.update_history_cardinality_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO cardinality_restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,cardinality_type,value,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id,ot.cardinality_type,ot.value, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_change_request_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO change_request__history (id,user_id,project_id,creation_time,edition_time,txid,type,description,status,recipient_id,location,treenode_id,connector_id,validate_action,approve_action,reject_action,completion_time,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.type,ot.description,ot.status,ot.recipient_id,ot.location,ot.treenode_id,ot.connector_id,ot.validate_action,ot.approve_action,ot.reject_action,ot.completion_time, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_class__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_a,class_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_a,ot.class_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_a,class_instance_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_a,ot.class_instance_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,class_id,name,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_id,ot.name, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class__history (id,user_id,project_id,creation_time,edition_time,txid,class_name,description,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_name,ot.description, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_concept_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO concept__history (id,user_id,project_id,creation_time,edition_time,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_connector_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO connector_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,connector_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.connector_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,connector_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.connector_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_region_of_interest_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO region_of_interest_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,region_of_interest_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.region_of_interest_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation__history (id,user_id,project_id,creation_time,edition_time,txid,relation_name,uri,description,isreciprocal,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_name,ot.uri,ot.description,ot.isreciprocal, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_group_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_group_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_group_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_group_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,connector_id,skeleton_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.connector_id,ot.skeleton_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode__history (id,project_id,location_x,location_y,location_z,editor_id,user_id,creation_time,edition_time,txid,skeleton_id,parent_id,radius,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.project_id,ot.location_x,ot.location_y,ot.location_z,ot.editor_id,ot.user_id,ot.creation_time,ot.edition_time,ot.txid,ot.skeleton_id,ot.parent_id,ot.radius,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_volume_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO volume_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,volume_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.volume_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE TRIGGER on_edit_cardinality_restrictions BEFORE UPDATE ON public.cardinality_restriction FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_class_instance BEFORE UPDATE ON public.point_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_connector BEFORE UPDATE ON public.point_connector FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_region_of_interest_class_instance BEFORE UPDATE ON public.region_of_interest_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_class_instance BEFORE UPDATE ON public.stack_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_group_class_instance BEFORE UPDATE ON public.stack_group_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_volume_class_instance BEFORE UPDATE ON public.volume_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); DROP SEQUENCE public.skeleton_origin_id_seq; DROP INDEX public.catmaid_sampler_project_id_c93395a7; DROP INDEX public.catmaid_sampler_sampler_state_id_80e7961f; DROP INDEX public.catmaid_sampler_skeleton_id_dfc98008; DROP INDEX public.catmaid_sampler_user_id_8d1c228f; DROP INDEX public.catmaid_skeleton_summary_project_id_7340fa33; DROP INDEX public.point_connector_project_id_uniq; DROP INDEX public.review_project_id; DROP INDEX public.review_reviewer_id; DROP INDEX public.review_skeleton_id; DROP INDEX public.review_treenode_id; DROP INDEX public.treenode_class_instance_class_instance_id; DROP INDEX public.treenode_class_instance_project_id; DROP INDEX public.treenode_class_instance_relation_id; DROP INDEX public.treenode_class_instance_treenode_id; DROP INDEX public.treenode_class_instance_user_id; DROP INDEX public.treenode_connector_connector_id; DROP INDEX public.treenode_connector_creation_time_idx; DROP INDEX public.treenode_connector_project_id; DROP INDEX public.treenode_connector_project_id_uniq; DROP INDEX public.treenode_connector_relation_id; DROP INDEX public.treenode_connector_skeleton_id; DROP INDEX public.treenode_connector_treenode_id; DROP INDEX public.treenode_connector_user_id; DROP INDEX public.treenode_creation_time_index; DROP INDEX public.treenode_edition_time_index; DROP INDEX public.treenode_location_x_index; DROP INDEX public.treenode_location_y_index; DROP INDEX public.treenode_location_z_index; DROP INDEX public.treenode_parent_id; DROP INDEX public.treenode_project_id_skeleton_id_index; DROP INDEX public.treenode_project_id_user_id_index; DROP INDEX public.treenode_skeleton_id_index;
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 98 vs 99 as well as 99 vs (99 -> 98) (i.e. a rollback). These migrations look reasonable and the effective migration (diff) from 98 to 99 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 catmaid/CATMAID#1848 --- Effective migration 99: ALTER SEQUENCE public.catmaid_sampler_id_seq AS bigint MAXVALUE 9223372036854775807; CREATE SEQUENCE public.skeleton_origin_id_seq1 NO MINVALUE NO MAXVALUE; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.cardinality_restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_sampler_id_fkey FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id); ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomainend DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomainend ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT last_editor_id_fkey; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_pkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_id_pkey PRIMARY KEY (skeleton_id) INCLUDE (num_nodes); ALTER TABLE ONLY public.change_request ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.change_request ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_connector_id_fkey; ALTER TABLE ONLY public.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 public.change_request ADD CONSTRAINT change_request_recipient_id_fkey FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_treenode_id_fkey; ALTER TABLE ONLY public.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 public.change_request DROP CONSTRAINT change_request_user_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT recipient_id_refs_id; ALTER TABLE ONLY public.change_request__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class ADD CONSTRAINT class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class DROP CONSTRAINT class_pkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_id_pkey PRIMARY KEY (id) INCLUDE (project_id, class_name); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class__history ALTER COLUMN class_name DROP DEFAULT; ALTER TABLE ONLY public.class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.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 public.class_class ADD CONSTRAINT class_class_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_class ADD CONSTRAINT class_class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_pkey; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_id_pkey PRIMARY KEY (id) INCLUDE (class_id, project_id, name); ALTER TABLE ONLY public.class_instance__history ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DEFAULT nextval('concept_id_seq'::regclass); ALTER TABLE ONLY public.concept ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.connector_class_instance DROP CONSTRAINT connector_class_instance_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.connector_class_instance ADD CONSTRAINT connector_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.log ADD CONSTRAINT log_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.log ADD CONSTRAINT log_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_point_id_fkey FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_sa_id; ALTER TABLE ONLY public.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 public.point_class_instance DROP CONSTRAINT point_connector_class_instance_id_fkey; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.point_connector ADD CONSTRAINT point_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_sa_id; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN region_of_interest_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.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 public.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 public.region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_pkey; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_id_pkey PRIMARY KEY (id) INCLUDE (project_id, relation_name); ALTER TABLE ONLY public.relation__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.relation_instance ADD CONSTRAINT relation_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance ADD CONSTRAINT relation_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restricted_link_fkey; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_restricted_link_id_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id); ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN review_time SET DEFAULT now(); ALTER TABLE ONLY public.review ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.review DROP CONSTRAINT review_reviewer_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_skeleton_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review ADD CONSTRAINT review_user_id_fkey FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT treenode_id_fkey; ALTER TABLE ONLY public.review__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_data_source_id_fkey; ALTER TABLE ONLY public.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 public.skeleton_origin DROP CONSTRAINT skeleton_origin_project_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_skeleton_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_skeleton_id_fkey1 FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_user_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_user_id_fkey1 FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.skeleton_origin__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN stack_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_class_instance DROP CONSTRAINT stack_class_instance_stack_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN stack_group_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.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 public.suppressed_virtual_treenode DROP CONSTRAINT suppressed_vnodes_child_id_refs_id; ALTER TABLE ONLY public.treenode ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_editor_id_fkey FOREIGN KEY (editor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance ADD CONSTRAINT treenode_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_treenode_id_fkey; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET NOT NULL; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.volume_class_instance DROP CONSTRAINT volume_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.volume_class_instance ADD CONSTRAINT volume_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_sa_id; ALTER TABLE ONLY public.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 public.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 public.volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; CREATE INDEX catmaid_sampler_project_id_idx ON public.catmaid_sampler USING btree (project_id); CREATE INDEX catmaid_sampler_sampler_state_id_idx ON public.catmaid_sampler USING btree (sampler_state_id); CREATE INDEX catmaid_sampler_skeleton_id_idx ON public.catmaid_sampler USING btree (skeleton_id); CREATE INDEX catmaid_sampler_user_id_idx ON public.catmaid_sampler USING btree (user_id); CREATE INDEX catmaid_skeleton_summary_project_id_idx ON public.catmaid_skeleton_summary USING btree (project_id); CREATE INDEX class_class_name_idx ON public.class USING btree (class_name) INCLUDE (id, project_id); CREATE INDEX guardian_gr_content_ae6aec_idx ON public.guardian_groupobjectpermission USING btree (content_type_id, object_pk); CREATE INDEX guardian_us_content_179ed2_idx ON public.guardian_userobjectpermission USING btree (content_type_id, object_pk); CREATE UNIQUE INDEX point_connector_project_id_point_id_connector_id_relation_id_un ON public.point_connector USING btree (project_id, point_id, connector_id, relation_id); CREATE INDEX review_project_id_idx ON public.review USING btree (project_id); CREATE INDEX review_reviewer_id_idx ON public.review USING btree (reviewer_id); CREATE INDEX review_skeleton_id_idx ON public.review USING btree (skeleton_id); CREATE INDEX review_treenode_id_idx ON public.review USING btree (treenode_id); CREATE INDEX treenode_class_instance_class_instance_id_idx ON public.treenode_class_instance USING btree (class_instance_id); CREATE INDEX treenode_class_instance_project_id_idx ON public.treenode_class_instance USING btree (project_id); CREATE INDEX treenode_class_instance_relation_id_idx ON public.treenode_class_instance USING btree (relation_id); CREATE INDEX treenode_class_instance_treenode_id_idx ON public.treenode_class_instance USING btree (treenode_id); CREATE INDEX treenode_class_instance_user_id_idx ON public.treenode_class_instance USING btree (user_id); CREATE INDEX treenode_connector_connector_id_idx ON public.treenode_connector USING btree (connector_id); CREATE INDEX treenode_connector_creation_time_idx_idx ON public.treenode_connector USING btree (creation_time); CREATE INDEX treenode_connector_project_id_idx ON public.treenode_connector USING btree (project_id); CREATE UNIQUE INDEX treenode_connector_project_id_treenode_id_connector_id_relation ON public.treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id); CREATE INDEX treenode_connector_relation_id_idx ON public.treenode_connector USING btree (relation_id); CREATE INDEX treenode_connector_skeleton_id_idx ON public.treenode_connector USING btree (skeleton_id); CREATE INDEX treenode_connector_treenode_id_idx ON public.treenode_connector USING btree (treenode_id); CREATE INDEX treenode_connector_user_id_idx ON public.treenode_connector USING btree (user_id); CREATE INDEX treenode_creation_time_idx ON public.treenode USING btree (creation_time); CREATE INDEX treenode_edition_time_idx ON public.treenode USING btree (edition_time); CREATE INDEX treenode_parent_id_idx ON public.treenode USING btree (parent_id); CREATE INDEX treenode_project_id_location_x_idx ON public.treenode USING btree (project_id, location_x); CREATE INDEX treenode_project_id_location_y_idx ON public.treenode USING btree (project_id, location_y); CREATE INDEX treenode_project_id_location_z_idx ON public.treenode USING btree (project_id, location_z); CREATE INDEX treenode_project_id_user_id_idx ON public.treenode USING btree (user_id, project_id); CREATE INDEX treenode_skeleton_id_project_id_idx ON public.treenode USING btree (skeleton_id, project_id); CREATE OR REPLACE FUNCTION public.check_treenode_connector_related_reviews(tc treenode_connector) RETURNS void LANGUAGE plpgsql VOLATILE AS $$BEGIN -- Mark linked treenodes as unreviewed. If relation is postsynaptic, -- mark only one, otherwise mark all treenodes related to connector. IF EXISTS (SELECT 1 FROM relation WHERE id = tc.relation_id AND relation_name = 'postsynaptic_to') THEN DELETE FROM review WHERE treenode_id = tc.treenode_id; ELSE DELETE FROM review r USING treenode_connector tc2 WHERE r.treenode_id = tc2.treenode_id AND tc2.connector_id = tc.connector_id; END IF; END; $$; CREATE OR REPLACE FUNCTION public.drop_history_table(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN PERFORM drop_history_table_keep_data(live_table); -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', get_tracking_table_name(live_table)); EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', history_table_name); END; $$; CREATE FUNCTION public.drop_history_table_keep_data(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_update_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_truncate_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_regular(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_tracking(), live_table); EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', get_history_update_fn_name_regular(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_truncate_trigger_name(), live_table); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_live_pk_index'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_sys_period'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_exec_transaction_id'); -- Remove from created table log DELETE FROM catmaid_history_table cht WHERE cht.live_table = $1; END; $$; CREATE OR REPLACE FUNCTION public.update_history_cardinality_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO cardinality_restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,cardinality_type,value,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id,ot.cardinality_type,ot.value, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_change_request_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO change_request__history (id,user_id,project_id,creation_time,edition_time,txid,type,description,status,recipient_id,location,treenode_id,connector_id,validate_action,approve_action,reject_action,completion_time,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.type,ot.description,ot.status,ot.recipient_id,ot.location,ot.treenode_id,ot.connector_id,ot.validate_action,ot.approve_action,ot.reject_action,ot.completion_time, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_class__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_a,class_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_a,ot.class_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_a,class_instance_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_a,ot.class_instance_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,class_id,name,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_id,ot.name, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class__history (id,user_id,project_id,creation_time,edition_time,txid,class_name,description,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_name,ot.description, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_concept_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO concept__history (id,user_id,project_id,creation_time,edition_time,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_connector_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO connector_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,connector_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.connector_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,connector_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.connector_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_region_of_interest_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO region_of_interest_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,region_of_interest_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.region_of_interest_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation__history (id,user_id,project_id,creation_time,edition_time,txid,relation_name,uri,description,isreciprocal,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_name,ot.uri,ot.description,ot.isreciprocal, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_group_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_group_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_group_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_group_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,connector_id,skeleton_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.connector_id,ot.skeleton_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode__history (id,project_id,location_x,location_y,location_z,editor_id,user_id,creation_time,edition_time,txid,skeleton_id,parent_id,radius,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.project_id,ot.location_x,ot.location_y,ot.location_z,ot.editor_id,ot.user_id,ot.creation_time,ot.edition_time,ot.txid,ot.skeleton_id,ot.parent_id,ot.radius,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_volume_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO volume_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,volume_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.volume_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE TRIGGER on_edit_cardinality_restrictions BEFORE UPDATE ON public.cardinality_restriction FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_class_instance BEFORE UPDATE ON public.point_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_connector BEFORE UPDATE ON public.point_connector FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_region_of_interest_class_instance BEFORE UPDATE ON public.region_of_interest_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_class_instance BEFORE UPDATE ON public.stack_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_group_class_instance BEFORE UPDATE ON public.stack_group_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_volume_class_instance BEFORE UPDATE ON public.volume_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); DROP SEQUENCE public.skeleton_origin_id_seq; DROP INDEX public.catmaid_sampler_project_id_c93395a7; DROP INDEX public.catmaid_sampler_sampler_state_id_80e7961f; DROP INDEX public.catmaid_sampler_skeleton_id_dfc98008; DROP INDEX public.catmaid_sampler_user_id_8d1c228f; DROP INDEX public.catmaid_skeleton_summary_project_id_7340fa33; DROP INDEX public.point_connector_project_id_uniq; DROP INDEX public.review_project_id; DROP INDEX public.review_reviewer_id; DROP INDEX public.review_skeleton_id; DROP INDEX public.review_treenode_id; DROP INDEX public.treenode_class_instance_class_instance_id; DROP INDEX public.treenode_class_instance_project_id; DROP INDEX public.treenode_class_instance_relation_id; DROP INDEX public.treenode_class_instance_treenode_id; DROP INDEX public.treenode_class_instance_user_id; DROP INDEX public.treenode_connector_connector_id; DROP INDEX public.treenode_connector_creation_time_idx; DROP INDEX public.treenode_connector_project_id; DROP INDEX public.treenode_connector_project_id_uniq; DROP INDEX public.treenode_connector_relation_id; DROP INDEX public.treenode_connector_skeleton_id; DROP INDEX public.treenode_connector_treenode_id; DROP INDEX public.treenode_connector_user_id; DROP INDEX public.treenode_creation_time_index; DROP INDEX public.treenode_edition_time_index; DROP INDEX public.treenode_location_x_index; DROP INDEX public.treenode_location_y_index; DROP INDEX public.treenode_location_z_index; DROP INDEX public.treenode_parent_id; DROP INDEX public.treenode_project_id_skeleton_id_index; DROP INDEX public.treenode_project_id_user_id_index; DROP INDEX public.treenode_skeleton_id_index;
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 only a very small difference could be measured. Improved data security and consistency is this certainly worth. 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 98 vs 99 as well as 99 vs (99 -> 98) (i.e. a rollback). These migrations look reasonable and the effective migration (diff) from 98 to 99 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 catmaid/CATMAID#1848 --- Effective migration 99: ALTER SEQUENCE public.catmaid_sampler_id_seq AS bigint MAXVALUE 9223372036854775807; CREATE SEQUENCE public.skeleton_origin_id_seq1 NO MINVALUE NO MAXVALUE; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.cardinality_restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_sampler_id_fkey FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id); ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomainend DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomainend ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_pkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_id_pkey PRIMARY KEY (skeleton_id) INCLUDE (num_nodes); ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT last_editor_id_fkey; ALTER TABLE ONLY public.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 public.change_request ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.change_request ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_connector_id_fkey; ALTER TABLE ONLY public.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 public.change_request DROP CONSTRAINT change_request_treenode_id_fkey; ALTER TABLE ONLY public.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 public.change_request DROP CONSTRAINT change_request_user_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_recipient_id_fkey FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT recipient_id_refs_id; ALTER TABLE ONLY public.change_request__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class DROP CONSTRAINT class_user_id_fkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class DROP CONSTRAINT class_pkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_id_pkey PRIMARY KEY (id) INCLUDE (project_id, class_name); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class__history ALTER COLUMN class_name DROP DEFAULT; ALTER TABLE ONLY public.class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_pkey; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_id_pkey PRIMARY KEY (id) INCLUDE (class_id, project_id); ALTER TABLE ONLY public.class_instance__history ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DEFAULT nextval('concept_id_seq'::regclass); ALTER TABLE ONLY public.concept ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.connector_class_instance ADD CONSTRAINT connector_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.log ADD CONSTRAINT log_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.log ADD CONSTRAINT log_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_class_instance_point_id_fkey FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_sa_id; ALTER TABLE ONLY public.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 public.point_class_instance DROP CONSTRAINT point_connector_class_instance_id_fkey; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.point_connector ADD CONSTRAINT point_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_sa_id; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN region_of_interest_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.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 public.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 public.region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_pkey; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_id_pkey PRIMARY KEY (id) INCLUDE (project_id, relation_name); ALTER TABLE ONLY public.relation__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.relation_instance ADD CONSTRAINT relation_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance ADD CONSTRAINT relation_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restricted_link_fkey; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_restricted_link_id_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id); ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN review_time SET DEFAULT now(); ALTER TABLE ONLY public.review ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.review DROP CONSTRAINT review_reviewer_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_skeleton_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review ADD CONSTRAINT review_user_id_fkey FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT treenode_id_fkey; ALTER TABLE ONLY public.review__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_data_source_id_fkey; ALTER TABLE ONLY public.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 public.skeleton_origin DROP CONSTRAINT skeleton_origin_project_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_skeleton_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_skeleton_id_fkey1 FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_user_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_user_id_fkey1 FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.skeleton_origin__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN stack_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_class_instance DROP CONSTRAINT stack_class_instance_stack_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN stack_group_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.suppressed_virtual_treenode DROP CONSTRAINT suppressed_vnodes_child_id_refs_id; ALTER TABLE ONLY public.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 public.treenode ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_editor_id_fkey FOREIGN KEY (editor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance ADD CONSTRAINT treenode_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_treenode_id_fkey; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET NOT NULL; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.volume_class_instance DROP CONSTRAINT volume_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.volume_class_instance ADD CONSTRAINT volume_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_sa_id; ALTER TABLE ONLY public.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 public.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 public.volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; CREATE INDEX catmaid_sampler_project_id_idx ON public.catmaid_sampler USING btree (project_id); CREATE INDEX catmaid_sampler_sampler_state_id_idx ON public.catmaid_sampler USING btree (sampler_state_id); CREATE INDEX catmaid_sampler_skeleton_id_idx ON public.catmaid_sampler USING btree (skeleton_id); CREATE INDEX catmaid_sampler_user_id_idx ON public.catmaid_sampler USING btree (user_id); CREATE INDEX catmaid_skeleton_summary_project_id_idx ON public.catmaid_skeleton_summary USING btree (project_id); CREATE INDEX class_class_name_idx ON public.class USING btree (class_name) INCLUDE (id, project_id); CREATE INDEX guardian_gr_content_ae6aec_idx ON public.guardian_groupobjectpermission USING btree (content_type_id, object_pk); CREATE INDEX guardian_us_content_179ed2_idx ON public.guardian_userobjectpermission USING btree (content_type_id, object_pk); CREATE UNIQUE INDEX point_connector_project_id_point_id_connector_id_relation_id_un ON public.point_connector USING btree (project_id, point_id, connector_id, relation_id); CREATE INDEX review_project_id_idx ON public.review USING btree (project_id); CREATE INDEX review_reviewer_id_idx ON public.review USING btree (reviewer_id); CREATE INDEX review_skeleton_id_idx ON public.review USING btree (skeleton_id); CREATE INDEX review_treenode_id_idx ON public.review USING btree (treenode_id); CREATE INDEX treenode_class_instance_class_instance_id_idx ON public.treenode_class_instance USING btree (class_instance_id); CREATE INDEX treenode_class_instance_project_id_idx ON public.treenode_class_instance USING btree (project_id); CREATE INDEX treenode_class_instance_relation_id_idx ON public.treenode_class_instance USING btree (relation_id); CREATE INDEX treenode_class_instance_treenode_id_idx ON public.treenode_class_instance USING btree (treenode_id); CREATE INDEX treenode_class_instance_user_id_idx ON public.treenode_class_instance USING btree (user_id); CREATE INDEX treenode_connector_connector_id_idx ON public.treenode_connector USING btree (connector_id); CREATE INDEX treenode_connector_creation_time_idx_idx ON public.treenode_connector USING btree (creation_time); CREATE INDEX treenode_connector_project_id_idx ON public.treenode_connector USING btree (project_id); CREATE UNIQUE INDEX treenode_connector_project_id_treenode_id_connector_id_relation ON public.treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id); CREATE INDEX treenode_connector_relation_id_idx ON public.treenode_connector USING btree (relation_id); CREATE INDEX treenode_connector_skeleton_id_idx ON public.treenode_connector USING btree (skeleton_id); CREATE INDEX treenode_connector_treenode_id_idx ON public.treenode_connector USING btree (treenode_id); CREATE INDEX treenode_connector_user_id_idx ON public.treenode_connector USING btree (user_id); CREATE INDEX treenode_creation_time_idx ON public.treenode USING btree (creation_time); CREATE INDEX treenode_edition_time_idx ON public.treenode USING btree (edition_time); CREATE INDEX treenode_parent_id_idx ON public.treenode USING btree (parent_id); CREATE INDEX treenode_project_id_location_x_idx ON public.treenode USING btree (project_id, location_x); CREATE INDEX treenode_project_id_location_y_idx ON public.treenode USING btree (project_id, location_y); CREATE INDEX treenode_project_id_location_z_idx ON public.treenode USING btree (project_id, location_z); CREATE INDEX treenode_project_id_user_id_idx ON public.treenode USING btree (user_id, project_id); CREATE INDEX treenode_skeleton_id_project_id_idx ON public.treenode USING btree (skeleton_id, project_id); CREATE OR REPLACE FUNCTION public.check_treenode_connector_related_reviews(tc treenode_connector) RETURNS void LANGUAGE plpgsql VOLATILE AS $$BEGIN -- Mark linked treenodes as unreviewed. If relation is postsynaptic, -- mark only one, otherwise mark all treenodes related to connector. IF EXISTS (SELECT 1 FROM relation WHERE id = tc.relation_id AND relation_name = 'postsynaptic_to') THEN DELETE FROM review WHERE treenode_id = tc.treenode_id; ELSE DELETE FROM review r USING treenode_connector tc2 WHERE r.treenode_id = tc2.treenode_id AND tc2.connector_id = tc.connector_id; END IF; END; $$; CREATE OR REPLACE FUNCTION public.drop_history_table(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN PERFORM drop_history_table_keep_data(live_table); -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', get_tracking_table_name(live_table)); EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', history_table_name); END; $$; CREATE FUNCTION public.drop_history_table_keep_data(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_update_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_truncate_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_regular(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_tracking(), live_table); EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', get_history_update_fn_name_regular(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_truncate_trigger_name(), live_table); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_live_pk_index'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_sys_period'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_exec_transaction_id'); -- Remove from created table log DELETE FROM catmaid_history_table cht WHERE cht.live_table = $1; END; $$; CREATE OR REPLACE FUNCTION public.update_history_cardinality_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO cardinality_restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,cardinality_type,value,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id,ot.cardinality_type,ot.value, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_change_request_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO change_request__history (id,user_id,project_id,creation_time,edition_time,txid,type,description,status,recipient_id,location,treenode_id,connector_id,validate_action,approve_action,reject_action,completion_time,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.type,ot.description,ot.status,ot.recipient_id,ot.location,ot.treenode_id,ot.connector_id,ot.validate_action,ot.approve_action,ot.reject_action,ot.completion_time, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_class__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_a,class_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_a,ot.class_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_a,class_instance_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_a,ot.class_instance_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,class_id,name,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_id,ot.name, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class__history (id,user_id,project_id,creation_time,edition_time,txid,class_name,description,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_name,ot.description, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_concept_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO concept__history (id,user_id,project_id,creation_time,edition_time,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_connector_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO connector_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,connector_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.connector_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,connector_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.connector_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_region_of_interest_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO region_of_interest_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,region_of_interest_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.region_of_interest_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation__history (id,user_id,project_id,creation_time,edition_time,txid,relation_name,uri,description,isreciprocal,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_name,ot.uri,ot.description,ot.isreciprocal, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_group_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_group_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_group_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_group_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,connector_id,skeleton_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.connector_id,ot.skeleton_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode__history (id,project_id,location_x,location_y,location_z,editor_id,user_id,creation_time,edition_time,txid,skeleton_id,parent_id,radius,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.project_id,ot.location_x,ot.location_y,ot.location_z,ot.editor_id,ot.user_id,ot.creation_time,ot.edition_time,ot.txid,ot.skeleton_id,ot.parent_id,ot.radius,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_volume_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO volume_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,volume_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.volume_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE TRIGGER on_edit_cardinality_restrictions BEFORE UPDATE ON public.cardinality_restriction FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_class_instance BEFORE UPDATE ON public.point_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_connector BEFORE UPDATE ON public.point_connector FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_region_of_interest_class_instance BEFORE UPDATE ON public.region_of_interest_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_class_instance BEFORE UPDATE ON public.stack_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_group_class_instance BEFORE UPDATE ON public.stack_group_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_volume_class_instance BEFORE UPDATE ON public.volume_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); DROP SEQUENCE public.skeleton_origin_id_seq; DROP INDEX public.catmaid_sampler_project_id_c93395a7; DROP INDEX public.catmaid_sampler_sampler_state_id_80e7961f; DROP INDEX public.catmaid_sampler_skeleton_id_dfc98008; DROP INDEX public.catmaid_sampler_user_id_8d1c228f; DROP INDEX public.catmaid_skeleton_summary_project_id_7340fa33; DROP INDEX public.point_connector_project_id_uniq; DROP INDEX public.review_project_id; DROP INDEX public.review_reviewer_id; DROP INDEX public.review_skeleton_id; DROP INDEX public.review_treenode_id; DROP INDEX public.treenode_class_instance_class_instance_id; DROP INDEX public.treenode_class_instance_project_id; DROP INDEX public.treenode_class_instance_relation_id; DROP INDEX public.treenode_class_instance_treenode_id; DROP INDEX public.treenode_class_instance_user_id; DROP INDEX public.treenode_connector_connector_id; DROP INDEX public.treenode_connector_creation_time_idx; DROP INDEX public.treenode_connector_project_id; DROP INDEX public.treenode_connector_project_id_uniq; DROP INDEX public.treenode_connector_relation_id; DROP INDEX public.treenode_connector_skeleton_id; DROP INDEX public.treenode_connector_treenode_id; DROP INDEX public.treenode_connector_user_id; DROP INDEX public.treenode_creation_time_index; DROP INDEX public.treenode_edition_time_index; DROP INDEX public.treenode_location_x_index; DROP INDEX public.treenode_location_y_index; DROP INDEX public.treenode_location_z_index; DROP INDEX public.treenode_parent_id; DROP INDEX public.treenode_project_id_skeleton_id_index; DROP INDEX public.treenode_project_id_user_id_index; DROP INDEX public.treenode_skeleton_id_index;
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 only a very small difference could be measured. Improved data security and consistency is important and worth a small performance hit. 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. This is especially useful when traversing join tables likes class_instance_class_instancem, since connections between them can now be found with index-only scans alone. 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 98 vs 99 as well as 99 vs (99 -> 98) (i.e. a rollback). These migrations look reasonable and the effective migration (diff) from 98 to 99 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 catmaid/CATMAID#1848 --- Effective migration 99: ALTER SEQUENCE public.catmaid_sampler_id_seq AS bigint MAXVALUE 9223372036854775807; CREATE SEQUENCE public.skeleton_origin_id_seq1 NO MINVALUE NO MAXVALUE; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.cardinality_restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.cardinality_restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_sampler_state_id_80e7961f_fk_catmaid_s; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_skeleton_id_dfc98008_fk_class_instance_id; ALTER TABLE ONLY public.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 public.catmaid_sampler DROP CONSTRAINT catmaid_sampler_user_id_8d1c228f_fk_auth_user_id; ALTER TABLE ONLY public.catmaid_sampler ADD CONSTRAINT catmaid_sampler_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_sampler__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_sampler_id_ed4aa3f0_fk_catmaid_sampler_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_sampler_id_fkey FOREIGN KEY (sampler_id) REFERENCES catmaid_sampler(id); ALTER TABLE ONLY public.catmaid_samplerdomain DROP CONSTRAINT catmaid_samplerdomain_start_node_id_4ae2c16c_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomain ADD CONSTRAINT catmaid_samplerdomain_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerdomainend DROP CONSTRAINT catmaid_samplerdomainend_end_node_id_31859f80_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerdomainend ADD CONSTRAINT catmaid_samplerdomainend_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_end_node_id_c82f43df_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_end_node_id_fkey FOREIGN KEY (end_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_samplerinterval DROP CONSTRAINT catmaid_samplerinterval_start_node_id_ead5c637_fk_treenode_id; ALTER TABLE ONLY public.catmaid_samplerinterval ADD CONSTRAINT catmaid_samplerinterval_start_node_id_fkey FOREIGN KEY (start_node_id) REFERENCES treenode(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.catmaid_skeleton_summary ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_pkey; ALTER TABLE ONLY public.catmaid_skeleton_summary ADD CONSTRAINT catmaid_skeleton_id_pkey PRIMARY KEY (skeleton_id) INCLUDE (num_nodes); ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_sum_skeleton_id_034079eb_fk_class_ins; ALTER TABLE ONLY public.catmaid_skeleton_summary DROP CONSTRAINT catmaid_skeleton_summary_skeleton_id_fk; ALTER TABLE ONLY public.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 public.catmaid_skeleton_summary DROP CONSTRAINT last_editor_id_fkey; ALTER TABLE ONLY public.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 public.change_request ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.change_request ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.change_request DROP CONSTRAINT change_request_connector_id_fkey; ALTER TABLE ONLY public.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 public.change_request DROP CONSTRAINT change_request_treenode_id_fkey; ALTER TABLE ONLY public.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 public.change_request DROP CONSTRAINT change_request_user_id_fkey; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request ADD CONSTRAINT change_request_recipient_id_fkey FOREIGN KEY (recipient_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.change_request DROP CONSTRAINT recipient_id_refs_id; ALTER TABLE ONLY public.change_request__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class DROP CONSTRAINT class_user_id_fkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class DROP CONSTRAINT class_pkey; ALTER TABLE ONLY public.class ADD CONSTRAINT class_id_pkey PRIMARY KEY (id) INCLUDE (project_id, class_name); ALTER TABLE ONLY public.class__history ALTER COLUMN class_name SET DATA TYPE text; ALTER TABLE ONLY public.class__history ALTER COLUMN class_name DROP DEFAULT; ALTER TABLE ONLY public.class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_a SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN class_b SET NOT NULL; ALTER TABLE ONLY public.class_class ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN class_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_class__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.class_instance DROP CONSTRAINT class_instance_pkey; ALTER TABLE ONLY public.class_instance ADD CONSTRAINT class_instance_id_pkey PRIMARY KEY (id) INCLUDE (class_id, project_id); ALTER TABLE ONLY public.class_instance__history ALTER COLUMN class_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_a SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN class_instance_b SET NOT NULL; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.class_instance_class_instance__history ALTER COLUMN class_instance_a SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN class_instance_b SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.class_instance_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.concept ALTER COLUMN id SET DEFAULT nextval('concept_id_seq'::regclass); ALTER TABLE ONLY public.concept ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept ADD CONSTRAINT concept_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.concept__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.connector_class_instance DROP CONSTRAINT connector_class_instance_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.connector_class_instance ADD CONSTRAINT connector_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.connector_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.connector_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.log ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.log ADD CONSTRAINT log_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.log ADD CONSTRAINT log_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_class_instance_class_instance_id_fkey FOREIGN KEY (class_instance_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance ADD CONSTRAINT point_class_instance_point_id_fkey FOREIGN KEY (point_id) REFERENCES point(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.point_class_instance ADD CONSTRAINT point_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_class_instance DROP CONSTRAINT point_class_instance_sa_id; ALTER TABLE ONLY public.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 public.point_class_instance DROP CONSTRAINT point_connector_class_instance_id_fkey; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_connector_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.point_connector ADD CONSTRAINT point_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector DROP CONSTRAINT point_connector_sa_id; ALTER TABLE ONLY public.point_connector ADD CONSTRAINT point_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.point_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN region_of_interest_id SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.region_of_interest_class_instance DROP CONSTRAINT region_of_interest_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.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 public.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 public.region_of_interest_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.region_of_interest_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation DROP CONSTRAINT relation_pkey; ALTER TABLE ONLY public.relation ADD CONSTRAINT relation_id_pkey PRIMARY KEY (id) INCLUDE (project_id, relation_name); ALTER TABLE ONLY public.relation__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.relation_instance ADD CONSTRAINT relation_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance ADD CONSTRAINT relation_instance_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.relation_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.restriction DROP CONSTRAINT restricted_link_fkey; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_restricted_link_id_fkey FOREIGN KEY (restricted_link_id) REFERENCES class_class(id); ALTER TABLE ONLY public.restriction ADD CONSTRAINT restriction_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.restriction__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.restriction__history ALTER COLUMN restricted_link_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN review_time SET DEFAULT now(); ALTER TABLE ONLY public.review ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.review ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.review DROP CONSTRAINT review_reviewer_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_skeleton_id_fkey FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT review_skeleton_id_refs_id; ALTER TABLE ONLY public.review ADD CONSTRAINT review_treenode_id_fkey FOREIGN KEY (treenode_id) REFERENCES treenode(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review ADD CONSTRAINT review_user_id_fkey FOREIGN KEY (reviewer_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.review DROP CONSTRAINT treenode_id_fkey; ALTER TABLE ONLY public.review__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.review__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_data_source_id_fkey; ALTER TABLE ONLY public.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 public.skeleton_origin DROP CONSTRAINT skeleton_origin_project_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_skeleton_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_skeleton_id_fkey1 FOREIGN KEY (skeleton_id) REFERENCES class_instance(id) ON DELETE CASCADE; ALTER TABLE ONLY public.skeleton_origin DROP CONSTRAINT skeleton_origin_user_id_fkey; ALTER TABLE ONLY public.skeleton_origin ADD CONSTRAINT skeleton_origin_user_id_fkey1 FOREIGN KEY (user_id) REFERENCES auth_user(id); ALTER TABLE ONLY public.skeleton_origin__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN stack_id SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_class_instance DROP CONSTRAINT stack_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_class_instance DROP CONSTRAINT stack_class_instance_stack_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN class_instance_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN stack_group_id SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.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 public.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 public.stack_group_class_instance DROP CONSTRAINT stack_group_class_instance_stack_group_id_fkey; ALTER TABLE ONLY public.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 public.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 public.stack_group_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.stack_group_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.suppressed_virtual_treenode DROP CONSTRAINT suppressed_vnodes_child_id_refs_id; ALTER TABLE ONLY public.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 public.treenode ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_editor_id_fkey FOREIGN KEY (editor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode ADD CONSTRAINT treenode_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance ADD CONSTRAINT treenode_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_class_instance DROP CONSTRAINT treenode_class_instance_treenode_id_fkey; ALTER TABLE ONLY public.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 public.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 public.treenode_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN skeleton_id SET NOT NULL; ALTER TABLE ONLY public.treenode_connector ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.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 public.treenode_connector ADD CONSTRAINT treenode_connector_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.treenode_connector__history ALTER COLUMN skeleton_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN relation_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance ALTER COLUMN txid SET NOT NULL; ALTER TABLE ONLY public.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 public.volume_class_instance DROP CONSTRAINT volume_class_instance_id_fkey; ALTER TABLE ONLY public.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 public.volume_class_instance ADD CONSTRAINT volume_class_instance_relation_id_fkey FOREIGN KEY (relation_id) REFERENCES relation(id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE ONLY public.volume_class_instance DROP CONSTRAINT volume_class_instance_sa_id; ALTER TABLE ONLY public.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 public.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 public.volume_class_instance__history ALTER COLUMN class_instance_id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN id SET DATA TYPE bigint; ALTER TABLE ONLY public.volume_class_instance__history ALTER COLUMN relation_id SET DATA TYPE bigint; CREATE INDEX catmaid_sampler_project_id_idx ON public.catmaid_sampler USING btree (project_id); CREATE INDEX catmaid_sampler_sampler_state_id_idx ON public.catmaid_sampler USING btree (sampler_state_id); CREATE INDEX catmaid_sampler_skeleton_id_idx ON public.catmaid_sampler USING btree (skeleton_id); CREATE INDEX catmaid_sampler_user_id_idx ON public.catmaid_sampler USING btree (user_id); CREATE INDEX catmaid_skeleton_summary_project_id_idx ON public.catmaid_skeleton_summary USING btree (project_id); CREATE INDEX class_class_name_idx ON public.class USING btree (class_name) INCLUDE (id, project_id); CREATE INDEX guardian_gr_content_ae6aec_idx ON public.guardian_groupobjectpermission USING btree (content_type_id, object_pk); CREATE INDEX guardian_us_content_179ed2_idx ON public.guardian_userobjectpermission USING btree (content_type_id, object_pk); CREATE UNIQUE INDEX point_connector_project_id_point_id_connector_id_relation_id_un ON public.point_connector USING btree (project_id, point_id, connector_id, relation_id); CREATE INDEX review_project_id_idx ON public.review USING btree (project_id); CREATE INDEX review_reviewer_id_idx ON public.review USING btree (reviewer_id); CREATE INDEX review_skeleton_id_idx ON public.review USING btree (skeleton_id); CREATE INDEX review_treenode_id_idx ON public.review USING btree (treenode_id); CREATE INDEX treenode_class_instance_class_instance_id_idx ON public.treenode_class_instance USING btree (class_instance_id); CREATE INDEX treenode_class_instance_project_id_idx ON public.treenode_class_instance USING btree (project_id); CREATE INDEX treenode_class_instance_relation_id_idx ON public.treenode_class_instance USING btree (relation_id); CREATE INDEX treenode_class_instance_treenode_id_idx ON public.treenode_class_instance USING btree (treenode_id); CREATE INDEX treenode_class_instance_user_id_idx ON public.treenode_class_instance USING btree (user_id); CREATE INDEX treenode_connector_connector_id_idx ON public.treenode_connector USING btree (connector_id); CREATE INDEX treenode_connector_creation_time_idx_idx ON public.treenode_connector USING btree (creation_time); CREATE INDEX treenode_connector_project_id_idx ON public.treenode_connector USING btree (project_id); CREATE UNIQUE INDEX treenode_connector_project_id_treenode_id_connector_id_relation ON public.treenode_connector USING btree (project_id, treenode_id, connector_id, relation_id); CREATE INDEX treenode_connector_relation_id_idx ON public.treenode_connector USING btree (relation_id); CREATE INDEX treenode_connector_skeleton_id_idx ON public.treenode_connector USING btree (skeleton_id); CREATE INDEX treenode_connector_treenode_id_idx ON public.treenode_connector USING btree (treenode_id); CREATE INDEX treenode_connector_user_id_idx ON public.treenode_connector USING btree (user_id); CREATE INDEX treenode_creation_time_idx ON public.treenode USING btree (creation_time); CREATE INDEX treenode_edition_time_idx ON public.treenode USING btree (edition_time); CREATE INDEX treenode_parent_id_idx ON public.treenode USING btree (parent_id); CREATE INDEX treenode_project_id_location_x_idx ON public.treenode USING btree (project_id, location_x); CREATE INDEX treenode_project_id_location_y_idx ON public.treenode USING btree (project_id, location_y); CREATE INDEX treenode_project_id_location_z_idx ON public.treenode USING btree (project_id, location_z); CREATE INDEX treenode_project_id_user_id_idx ON public.treenode USING btree (user_id, project_id); CREATE INDEX treenode_skeleton_id_project_id_idx ON public.treenode USING btree (skeleton_id, project_id); CREATE OR REPLACE FUNCTION public.check_treenode_connector_related_reviews(tc treenode_connector) RETURNS void LANGUAGE plpgsql VOLATILE AS $$BEGIN -- Mark linked treenodes as unreviewed. If relation is postsynaptic, -- mark only one, otherwise mark all treenodes related to connector. IF EXISTS (SELECT 1 FROM relation WHERE id = tc.relation_id AND relation_name = 'postsynaptic_to') THEN DELETE FROM review WHERE treenode_id = tc.treenode_id; ELSE DELETE FROM review r USING treenode_connector tc2 WHERE r.treenode_id = tc2.treenode_id AND tc2.connector_id = tc.connector_id; END IF; END; $$; CREATE OR REPLACE FUNCTION public.drop_history_table(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN PERFORM drop_history_table_keep_data(live_table); -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', get_tracking_table_name(live_table)); EXECUTE format('DROP TABLE IF EXISTS %I CASCADE', history_table_name); END; $$; CREATE FUNCTION public.drop_history_table_keep_data(live_table regclass) RETURNS void LANGUAGE plpgsql VOLATILE AS $$ DECLARE -- This will contain the name of the newly created history table. No -- regclass is used, because the implicit table existence check on variable -- assignment can fail if the table has already been removed by an -- cascaded table drop. history_table_name text; BEGIN -- History tables will be named like the live table plus a '__history' suffix history_table_name = get_history_table_name(live_table); -- Cascading deleting is used to also delete child tables and triggers. EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_update_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_tracking_table_truncate_trigger_name(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_regular(), live_table); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_update_trigger_name_tracking(), live_table); EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', get_history_update_fn_name_regular(live_table)); EXECUTE format('DROP TRIGGER IF EXISTS %I ON %s', get_history_truncate_trigger_name(), live_table); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_live_pk_index'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_sys_period'); EXECUTE format('DROP INDEX IF EXISTS %I', history_table_name || '_exec_transaction_id'); -- Remove from created table log DELETE FROM catmaid_history_table cht WHERE cht.live_table = $1; END; $$; CREATE OR REPLACE FUNCTION public.update_history_cardinality_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO cardinality_restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,cardinality_type,value,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id,ot.cardinality_type,ot.value, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_change_request_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO change_request__history (id,user_id,project_id,creation_time,edition_time,txid,type,description,status,recipient_id,location,treenode_id,connector_id,validate_action,approve_action,reject_action,completion_time,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.type,ot.description,ot.status,ot.recipient_id,ot.location,ot.treenode_id,ot.connector_id,ot.validate_action,ot.approve_action,ot.reject_action,ot.completion_time, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_class__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_a,class_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_a,ot.class_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_a,class_instance_b,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_a,ot.class_instance_b, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,class_id,name,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_id,ot.name, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_class_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO class__history (id,user_id,project_id,creation_time,edition_time,txid,class_name,description,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.class_name,ot.description, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_concept_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO concept__history (id,user_id,project_id,creation_time,edition_time,txid,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_connector_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO connector_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,connector_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.connector_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_point_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO point_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,point_id,connector_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.point_id,ot.connector_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_region_of_interest_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO region_of_interest_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,region_of_interest_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.region_of_interest_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_relation_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO relation__history (id,user_id,project_id,creation_time,edition_time,txid,relation_name,uri,description,isreciprocal,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_name,ot.uri,ot.description,ot.isreciprocal, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_restriction_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO restriction__history (id,user_id,project_id,creation_time,edition_time,txid,enabled,restricted_link_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.enabled,ot.restricted_link_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_stack_group_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO stack_group_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,class_instance_id,stack_group_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.class_instance_id,ot.stack_group_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_connector_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode_connector__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,treenode_id,connector_id,skeleton_id,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.treenode_id,ot.connector_id,ot.skeleton_id,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_treenode_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO treenode__history (id,project_id,location_x,location_y,location_z,editor_id,user_id,creation_time,edition_time,txid,skeleton_id,parent_id,radius,confidence,sys_period,exec_transaction_id) SELECT ot.id,ot.project_id,ot.location_x,ot.location_y,ot.location_z,ot.editor_id,ot.user_id,ot.creation_time,ot.edition_time,ot.txid,ot.skeleton_id,ot.parent_id,ot.radius,ot.confidence, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE OR REPLACE FUNCTION public.update_history_volume_class_instance_reg() RETURNS trigger LANGUAGE plpgsql VOLATILE AS $$ BEGIN -- Insert new historic data into history table, based on the -- currently available columns in the updated table. INSERT INTO volume_class_instance__history (id,user_id,project_id,creation_time,edition_time,txid,relation_id,volume_id,class_instance_id,sys_period,exec_transaction_id) SELECT ot.id,ot.user_id,ot.project_id,ot.creation_time,ot.edition_time,ot.txid,ot.relation_id,ot.volume_id,ot.class_instance_id, tstzrange(LEAST(ot.edition_time, current_timestamp), current_timestamp), txid_current() FROM old_treenode ot; RETURN NULL; END; $$; CREATE TRIGGER on_edit_cardinality_restrictions BEFORE UPDATE ON public.cardinality_restriction FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_class_instance BEFORE UPDATE ON public.point_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_point_connector BEFORE UPDATE ON public.point_connector FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_region_of_interest_class_instance BEFORE UPDATE ON public.region_of_interest_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_class_instance BEFORE UPDATE ON public.stack_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_stack_group_class_instance BEFORE UPDATE ON public.stack_group_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); CREATE TRIGGER on_edit_volume_class_instance BEFORE UPDATE ON public.volume_class_instance FOR EACH ROW EXECUTE PROCEDURE on_edit(); DROP SEQUENCE public.skeleton_origin_id_seq; DROP INDEX public.catmaid_sampler_project_id_c93395a7; DROP INDEX public.catmaid_sampler_sampler_state_id_80e7961f; DROP INDEX public.catmaid_sampler_skeleton_id_dfc98008; DROP INDEX public.catmaid_sampler_user_id_8d1c228f; DROP INDEX public.catmaid_skeleton_summary_project_id_7340fa33; DROP INDEX public.point_connector_project_id_uniq; DROP INDEX public.review_project_id; DROP INDEX public.review_reviewer_id; DROP INDEX public.review_skeleton_id; DROP INDEX public.review_treenode_id; DROP INDEX public.treenode_class_instance_class_instance_id; DROP INDEX public.treenode_class_instance_project_id; DROP INDEX public.treenode_class_instance_relation_id; DROP INDEX public.treenode_class_instance_treenode_id; DROP INDEX public.treenode_class_instance_user_id; DROP INDEX public.treenode_connector_connector_id; DROP INDEX public.treenode_connector_creation_time_idx; DROP INDEX public.treenode_connector_project_id; DROP INDEX public.treenode_connector_project_id_uniq; DROP INDEX public.treenode_connector_relation_id; DROP INDEX public.treenode_connector_skeleton_id; DROP INDEX public.treenode_connector_treenode_id; DROP INDEX public.treenode_connector_user_id; DROP INDEX public.treenode_creation_time_index; DROP INDEX public.treenode_edition_time_index; DROP INDEX public.treenode_location_x_index; DROP INDEX public.treenode_location_y_index; DROP INDEX public.treenode_location_z_index; DROP INDEX public.treenode_parent_id; DROP INDEX public.treenode_project_id_skeleton_id_index; DROP INDEX public.treenode_project_id_user_id_index; DROP INDEX public.treenode_skeleton_id_index;
This relevant migration in #1887 is now finally merged. Our database uses now 64 Bit IDs in both the spatial and semantic part, as well as other tables where this seemed to be reasonable. |
According to psql, the treenode_connector table has the skeleton_id as an integer type, whereas other columns such as treenode_id and connector_id are bigint. With datasets becoming larger and larger, particulary when importing many small skeletons resulting from automatic segmentation, there's potential with this becoming an issue rather soon.
treenode_connector.skeleton_id's type should change to bigint.
Similarly, in table treenode, the skeleton_id is also an integer (4 bytes) instead of a bigint (8 bytes).
Other tables where skeleton_id appears should be similarly updated to using bigint.
The text was updated successfully, but these errors were encountered: