Skip to content

Commit

Permalink
improve migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvic-dev committed Mar 12, 2024
1 parent be84013 commit 72c515d
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions bob/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,38 @@ async def start_migration():

from bob.qna.json import json_to_questions

logger.info("migrating qna data (this will take a while)...")
logger.info("migrating qna data (this might take a while)...")
questions = json_to_questions(data)

for question in tqdm(questions, unit="questions"):
dbQuestion = await db.Question.create(
text=question.text,
guild=question.guild,
channel=question.channel,
message=question.message,
author=question.author,
)
await db.Response.bulk_create(
[
db.Response(
text=resp.text,
count=resp.count,
message=resp.message,
author=resp.author,
question=dbQuestion,
)
for resp in question.responses
]
)
logger.info("migrating questions...")
await db.Question.bulk_create(
[
db.Question(
id=idx + 1,
text=q.text,
guild=q.guild,
channel=q.channel,
message=q.message,
author=q.author,
)
for idx, q in enumerate(questions)
]
)

logger.info("...and responses...")
await db.Response.bulk_create(
[
db.Response(
question_id=q_idx + 1,
text=r.text,
count=r.count,
message=r.message,
author=r.author,
)
for q_idx, q in enumerate(questions)
for r in q.responses
]
)

logger.info("cleaning up, we're done")
os.remove("config.json")
Expand Down

0 comments on commit 72c515d

Please sign in to comment.