Repository: debrief/pepys-import (language: python)

Issue:
Need to increase size of Track Number in PG
@mew-nsc 's PR for WECDIS Importer (#1086 ) is failing because of a long Track Number (well, name):
https://github.com/debrief/pepys-import/runs/4396329479?check_suite_focus=true#step:7:1250

For WECDIS data it appears users can use free text to name tracks, and can end up with quite long descriptors.

We should increase the size of the `Contacts`.`TrackNumber` field from 20 characters to 40 characters, please.

Note: the PR also appears to fail the performance test, though small failures in this don't normally bother us.

It would be good to resolve this before I try to test WECDIS against bulk _real_ datasets.


Discussion / hints:

Fix patch:
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/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-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/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 36f50a4e6..b1246764d 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,
     )
@@ -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 0c01d9d02..aa1d58468 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,
     )
@@ -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")
     )


Test patch:
diff --git a/migrations/latest_revisions.json b/migrations/latest_revisions.json
index 176c42968..5edb492b3 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": "fddfa70f811b",
+    "LATEST_POSTGRES_VERSION": "a5a4bc1f7156"
 }
\ No newline at end of file