diff --git a/alembic/versions/20241030_272da5f400de_add_uuid_to_patron_table.py b/alembic/versions/20241030_272da5f400de_add_uuid_to_patron_table.py index df35a58c8..6c88e16d1 100644 --- a/alembic/versions/20241030_272da5f400de_add_uuid_to_patron_table.py +++ b/alembic/versions/20241030_272da5f400de_add_uuid_to_patron_table.py @@ -22,7 +22,28 @@ def upgrade() -> None: op.add_column( "patrons", - sa.Column("uuid", UUID(as_uuid=True), nullable=False, default=uuid.uuid4), + sa.Column("uuid", UUID(as_uuid=True), nullable=True, default=uuid.uuid4), + ) + + conn = op.get_bind() + rows = conn.execute("SELECT id from patrons").all() + + for row in rows: + conn.execute( + """ + UPDATE patrons + SET uuid = %(uuid)s + WHERE id = %(id)s + """, + { + "id": row.id, + "uuid": uuid.uuid4(), + }, + ) + + op.alter_column( + "patrons", + sa.Column("uuid", nullable=False), )