Use a UUID for the TranscriptionEntity primary key
https://redmine.teklia.com/issues/7696
We created TranscriptionEntity
without specifying a primary key field, so Django created an AutoField
(an integer). To be consistent with the other ML results and simplify re-importing exports, we need to replace that field with an UUIDField
.
-
Add the usual
id = UUIDField(...)
onTranscriptionEntity
. -
Just like in
process.0023
, have the migration use aRunSQL
whosestate_operations
include updating the type of theid
field.-
Use
gen_random_uuid()
to generate the new UUIDs to reset the column. -
For databases that were created after Django 4.1, the
id
column will useGENERATED BY DEFAULT AS IDENTITY
, a constraint that must be removed before you can change the type. You can useDROP IDENTITY IF EXISTS
on the column to clean it up. -
For databases that existed before Django 4.1, there will be a
documents_transcriptionentity_id_seq
sequence that you need to drop manually if it exists. -
This migration is reversible, and easier to do using the old method before Django 4.1:
- Create the
documents_transcriptionentity_id_seq
. No need to override any defaults on it. - Reset the field type to
int
, this timeUSING nextval('documents_transcriptionentity_id_seq'::regclass)
. - Set the same
nextval
call as the default value for the column, so that the sequence is used when inserting new rows.
- Create the
-
-
Update the export structure to have
transcription_entity.id
be aVARCHAR(37)
, and bump the export version. -
Update the maximum supported version in
load_export
. Previous versions should still be compatible.