Skip to content

Commit

Permalink
Ensure patron uuid are set in the migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Oct 31, 2024
1 parent ebd6826 commit 0d0c94e
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)


Expand Down

0 comments on commit 0d0c94e

Please sign in to comment.