DB migration version 20210714173022 fails when having skipped post deployment migrations before

Was updating to stable (v2.7.8) in the first container having SKIP_POST_DEPLOYMENT_MIGRATIONS enabled.
When running the second time in the other container with the skip-option disabled the migration task CorrectlyMoveAssignmentsFromCustomFieldsToATable failed:

PG::NotNullViolation: ERROR:  null value in column "assigned_to_type"
of relation "assignments" violates not-null constraint

As far I can see the upgrade task AddAssignedToTypeToAssignments (creating the not-null constraint) should not be performed until CorrectlyMoveAssignmentsFromCustomFieldsToATable has been finished.

As workaround I was doing:

INSERT INTO assignments
(assigned_to_id, assigned_by_user_id, topic_id, created_at, updated_at,assigned_to_type)
SELECT
  assigned_to.value::integer,
  assigned_by.value::integer,
  assigned_by.topic_id,
  assigned_by.created_at,
  assigned_by.updated_at,
  'User'
FROM topic_custom_fields assigned_by
INNER JOIN topic_custom_fields assigned_to
ON assigned_to.topic_id = assigned_by.topic_id
WHERE assigned_by.name = 'assigned_by_id'
AND assigned_to.name = 'assigned_to_id'
ORDER BY assigned_by.created_at DESC
ON CONFLICT DO NOTHING;

INSERT INTO schema_migration_details
(version,
name,
hostname,
git_version,
rails_version,
duration,
direction,
created_at)
values(
'20210714173022',
'CorrectlyMoveAssignmentsFromCustomFieldsToATable',
'ce4fb45daf62',
'98b0621d538fa4e8a53e1e74127c24c384be9b58',
'6.1.3.2',
0,
'up',
'2021-09-28 15:20:00.123456'
);

INSERT INTO schema_migrations values('20210714173022');

Afterwords I was able to rebuild the container.

2 Likes

Thank you for your investigation, we fixed that migration with PR:

3 Likes

That was fast. Thank you :slight_smile:

2 Likes