-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration: Change connector_geom id to bigint
- Loading branch information
1 parent
6ebe988
commit 65b4044
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
django/applications/catmaid/migrations/0088_connector_geom_fix_bigint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 2.2.5 on 2019-10-28 11:32 | ||
|
||
from django.db import migrations | ||
|
||
forward = """ | ||
ALTER TABLE connector_geom ALTER COLUMN id TYPE bigint; | ||
""" | ||
|
||
backward = """ | ||
ALTER TABLE connector_geom ALTER COLUMN id TYPE integer; | ||
""" | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('catmaid', '0087_add_nblast_normalization_mode'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL(forward, backward) | ||
] |
65b4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but this is also part of the migration in PR #1887, which I haven't merged yet. It would be good if we can merge this first, before we do additional int/bigint changes. In order to do so, I have to review it one more time though and test again. The goal is to do that in the next two weeks, because I'd like to cut a new release.
65b4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, doing an
ALTER TABLE … ALTER COLUMN …
will rewrite the complete table. On large instances, especially with automatically generated connector nodes, this table will be large. Generally, space is only reclaimed in these situations ifVACUUM FULL
is run, which is expensive and causes yet another table rewrite. To avoid this, the migration I referenced above create a completely new table for bothconnector_geom
andtreenode_connector_edge
, copies the data over (making the IDs 64 bit), updates all references and indices, and finally deleted the old table. This reclaims space immediately (i.e. noVACUUM FULL
needed) and is therefore more friendly to large setups. All this happens in the referenced PR in file0076_fix_treenode_connector_edge_foreign_key_types.py
.Therefore I feel it would be better if you could revert this change and I will go through the PR #1887 in the next two days and merge it. This isn't ideal, because your migration might be in use already, but I also don't think it will be really problematic, because the new migration will essentially do the same.
65b4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about how to change this migration a bit more, I think the best way to go about this is the following: I will split up migration
0076_fix_treenode_connector_edge_foreign_key_types.py
in #1887 into one that runs forconnector_geom
and one that runs fortreenode_connector_edge
(it handles both in one transaction). I will replace your migration code above (65b4044) with theconnector_geom
part of #1887 and add thetreenode_connector_edge
part as a separate migration. This way you don't have to update your local database (I assume you have this migration applied already), because the outcome would be the same.Also as a general point, I believe it is is useful to mention aspects like table rewrites, space constraints, etc. in the comments/documentation of migration like this.
65b4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, splitting this into two migration sounds good to me. I reverted my commit. I was not aware of the pull request #1887, and thanks for the explanation of how to make such migrations more efficient.
65b4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, thanks for the quick fix! I will merge this first part of the #1887 including the changes you wanted to make as soon as possible and try to have a look at the remaining schema changes too.
65b4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed and moved the 64 Bit migrations dealing with
connector_geom
andtreenode_connector_edge
as well aschange_request
intodev
now. I kep theconnector_geom
migration name you chose for your implementation and since the outcome of this migration is the same, you should be able to just--fake
migration0088_connector_geom_fix_bigint
. Of course only this migration and only if you have your migration already applied. The remaining 64 Bit changes for theconcept
based tables will hopefully make it intodev
soon as well.65b4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tomka, I'll get to it next week, its looking good.