Skip to content

Commit

Permalink
Address missing UUIDs in pre-existing users (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
michplunkett authored Aug 25, 2023
1 parent c55454a commit 9264bd7
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
Create Date: 2023-07-24 16:19:01.375427
"""
import uuid

import sqlalchemy as sa
from alembic import op
from sqlalchemy.orm import Session

from OpenOversight.app.models.database import User


revision = "52d3f6a21dd9"
Expand All @@ -19,10 +24,17 @@ def upgrade():
sa.Column(
"_uuid",
sa.String(36),
nullable=False,
),
)

bind = op.get_bind()
session = Session(bind=bind)
for user in session.query(User).all():
user._uuid = str(uuid.uuid4())
session.commit()

op.create_index(op.f("ix_users__uuid"), "users", ["_uuid"], unique=True)
op.alter_column("users", "_uuid", nullable=False)


def downgrade():
Expand Down

0 comments on commit 9264bd7

Please sign in to comment.