From 2b63ad273f0038e2ec5e7c5321f4777ba3e935d4 Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Thu, 2 Dec 2021 20:33:51 +0000 Subject: [PATCH 1/2] Add migration to extend length of platform identifier field --- migrations/latest_revisions.json | 4 +- ...e_extend_length_of_platform_identifier_.py | 41 +++++++++++++++++++ ...2_extend_length_of_platform_identifier_.py | 40 ++++++++++++++++++ pepys_import/core/store/postgres_db.py | 2 +- pepys_import/core/store/sqlite_db.py | 2 +- 5 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 migrations/postgres_versions/2021-12-01_39b90ad3675e_extend_length_of_platform_identifier_.py create mode 100644 migrations/sqlite_versions/2021-12-01_eb8a93498c02_extend_length_of_platform_identifier_.py diff --git a/migrations/latest_revisions.json b/migrations/latest_revisions.json index 176c42968..178ea8185 100644 --- a/migrations/latest_revisions.json +++ b/migrations/latest_revisions.json @@ -1,4 +1,4 @@ { - "LATEST_SQLITE_VERSION": "cebecb0b77a1", - "LATEST_POSTGRES_VERSION": "2bc85b76a38b" + "LATEST_SQLITE_VERSION": "eb8a93498c02", + "LATEST_POSTGRES_VERSION": "39b90ad3675e" } \ No newline at end of file diff --git a/migrations/postgres_versions/2021-12-01_39b90ad3675e_extend_length_of_platform_identifier_.py b/migrations/postgres_versions/2021-12-01_39b90ad3675e_extend_length_of_platform_identifier_.py new file mode 100644 index 000000000..73666cdd4 --- /dev/null +++ b/migrations/postgres_versions/2021-12-01_39b90ad3675e_extend_length_of_platform_identifier_.py @@ -0,0 +1,41 @@ +"""Extend length of Platform.identifier field + +Revision ID: 39b90ad3675e +Revises: 2bc85b76a38b +Create Date: 2021-12-01 21:08:52.761161+00:00 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "39b90ad3675e" +down_revision = "2bc85b76a38b" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "Platforms", + "identifier", + existing_type=sa.VARCHAR(length=30), + type_=sa.String(length=50), + existing_nullable=False, + schema="pepys", + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "Platforms", + "identifier", + existing_type=sa.String(length=50), + type_=sa.VARCHAR(length=30), + existing_nullable=False, + schema="pepys", + ) + # ### end Alembic commands ### diff --git a/migrations/sqlite_versions/2021-12-01_eb8a93498c02_extend_length_of_platform_identifier_.py b/migrations/sqlite_versions/2021-12-01_eb8a93498c02_extend_length_of_platform_identifier_.py new file mode 100644 index 000000000..c75644612 --- /dev/null +++ b/migrations/sqlite_versions/2021-12-01_eb8a93498c02_extend_length_of_platform_identifier_.py @@ -0,0 +1,40 @@ +"""Extend length of Platform.identifier field + +Revision ID: eb8a93498c02 +Revises: cebecb0b77a1 +Create Date: 2021-12-01 21:10:36.015159+00:00 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "eb8a93498c02" +down_revision = "cebecb0b77a1" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("Platforms", schema=None) as batch_op: + batch_op.alter_column( + "identifier", + existing_type=sa.VARCHAR(length=30), + type_=sa.String(length=50), + existing_nullable=False, + ) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("Platforms", schema=None) as batch_op: + batch_op.alter_column( + "identifier", + existing_type=sa.String(length=50), + type_=sa.VARCHAR(length=30), + existing_nullable=False, + ) + # ### end Alembic commands ### diff --git a/pepys_import/core/store/postgres_db.py b/pepys_import/core/store/postgres_db.py index 36f50a4e6..bbe9e09bc 100644 --- a/pepys_import/core/store/postgres_db.py +++ b/pepys_import/core/store/postgres_db.py @@ -132,7 +132,7 @@ class Platform(BasePostGIS, PlatformMixin): String(150), CheckConstraint("name <> ''", name="ck_Platforms_name"), nullable=False ) identifier = Column( - String(30), + String(50), CheckConstraint("identifier <> ''", name="ck_Platforms_identifier"), nullable=False, ) diff --git a/pepys_import/core/store/sqlite_db.py b/pepys_import/core/store/sqlite_db.py index 0c01d9d02..a761d0ebf 100644 --- a/pepys_import/core/store/sqlite_db.py +++ b/pepys_import/core/store/sqlite_db.py @@ -129,7 +129,7 @@ class Platform(BaseSpatiaLite, PlatformMixin): String(150), CheckConstraint("name <> ''", name="ck_Platforms_name"), nullable=False ) identifier = Column( - String(30), + String(50), CheckConstraint("identifier <> ''", name="ck_Platforms_identifier"), nullable=False, ) From a5380921967cb3284ae5153be7e4779b68060d90 Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Fri, 3 Dec 2021 16:50:51 +0000 Subject: [PATCH 2/2] Add migration to extend length of Contacts.track_number field --- migrations/latest_revisions.json | 4 +- ..._extend_length_of_contact_track_number_.py | 41 +++++++++++++++++++ ..._extend_length_of_contact_track_number_.py | 40 ++++++++++++++++++ pepys_import/core/store/postgres_db.py | 2 +- pepys_import/core/store/sqlite_db.py | 2 +- 5 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 migrations/postgres_versions/2021-12-03_a5a4bc1f7156_extend_length_of_contact_track_number_.py create mode 100644 migrations/sqlite_versions/2021-12-03_fddfa70f811b_extend_length_of_contact_track_number_.py diff --git a/migrations/latest_revisions.json b/migrations/latest_revisions.json index 178ea8185..5edb492b3 100644 --- a/migrations/latest_revisions.json +++ b/migrations/latest_revisions.json @@ -1,4 +1,4 @@ { - "LATEST_SQLITE_VERSION": "eb8a93498c02", - "LATEST_POSTGRES_VERSION": "39b90ad3675e" + "LATEST_SQLITE_VERSION": "fddfa70f811b", + "LATEST_POSTGRES_VERSION": "a5a4bc1f7156" } \ No newline at end of file diff --git a/migrations/postgres_versions/2021-12-03_a5a4bc1f7156_extend_length_of_contact_track_number_.py b/migrations/postgres_versions/2021-12-03_a5a4bc1f7156_extend_length_of_contact_track_number_.py new file mode 100644 index 000000000..cdf1263bb --- /dev/null +++ b/migrations/postgres_versions/2021-12-03_a5a4bc1f7156_extend_length_of_contact_track_number_.py @@ -0,0 +1,41 @@ +"""Extend length of Contact.track_number field + +Revision ID: a5a4bc1f7156 +Revises: 39b90ad3675e +Create Date: 2021-12-03 16:48:18.324573+00:00 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "a5a4bc1f7156" +down_revision = "39b90ad3675e" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "Contacts", + "track_number", + existing_type=sa.VARCHAR(length=20), + type_=sa.String(length=40), + existing_nullable=True, + schema="pepys", + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "Contacts", + "track_number", + existing_type=sa.String(length=40), + type_=sa.VARCHAR(length=20), + existing_nullable=True, + schema="pepys", + ) + # ### end Alembic commands ### diff --git a/migrations/sqlite_versions/2021-12-03_fddfa70f811b_extend_length_of_contact_track_number_.py b/migrations/sqlite_versions/2021-12-03_fddfa70f811b_extend_length_of_contact_track_number_.py new file mode 100644 index 000000000..409bd9a97 --- /dev/null +++ b/migrations/sqlite_versions/2021-12-03_fddfa70f811b_extend_length_of_contact_track_number_.py @@ -0,0 +1,40 @@ +"""Extend length of Contact.track_number field + +Revision ID: fddfa70f811b +Revises: eb8a93498c02 +Create Date: 2021-12-03 16:49:33.809704+00:00 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "fddfa70f811b" +down_revision = "eb8a93498c02" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("Contacts", schema=None) as batch_op: + batch_op.alter_column( + "track_number", + existing_type=sa.VARCHAR(length=20), + type_=sa.String(length=40), + existing_nullable=True, + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("Contacts", schema=None) as batch_op: + batch_op.alter_column( + "track_number", + existing_type=sa.String(length=40), + type_=sa.VARCHAR(length=20), + existing_nullable=True, + ) + + # ### end Alembic commands ### diff --git a/pepys_import/core/store/postgres_db.py b/pepys_import/core/store/postgres_db.py index bbe9e09bc..b1246764d 100644 --- a/pepys_import/core/store/postgres_db.py +++ b/pepys_import/core/store/postgres_db.py @@ -766,7 +766,7 @@ class Contact(BasePostGIS, ContactMixin, LocationPropertyMixin, ElevationPropert ) _mla = deferred(Column("mla", DOUBLE_PRECISION)) _soa = deferred(Column("soa", DOUBLE_PRECISION)) - track_number = Column(String(20)) + track_number = Column(String(40)) subject_id = Column( UUID(as_uuid=True), ForeignKey("pepys.Platforms.platform_id", onupdate="cascade", ondelete="cascade"), diff --git a/pepys_import/core/store/sqlite_db.py b/pepys_import/core/store/sqlite_db.py index a761d0ebf..aa1d58468 100644 --- a/pepys_import/core/store/sqlite_db.py +++ b/pepys_import/core/store/sqlite_db.py @@ -772,7 +772,7 @@ class Contact(BaseSpatiaLite, ContactMixin, LocationPropertyMixin, ElevationProp contact_type = deferred(Column(UUIDType, ForeignKey("ContactTypes.contact_type_id"))) _mla = deferred(Column("mla", REAL)) _soa = deferred(Column("soa", REAL)) - track_number = Column(String(20)) + track_number = Column(String(40)) subject_id = Column( UUIDType, ForeignKey("Platforms.platform_id", onupdate="cascade", ondelete="cascade") )