forked from retoor/devplacepy
Quiiz system
This commit is contained in:
@@ -404,6 +404,23 @@ def init_db():
|
||||
"idx_devii_turns_owner_time",
|
||||
["owner_kind", "owner_id", "started_at"],
|
||||
)
|
||||
if "devii_tasks" in db.tables:
|
||||
tasks = get_table("devii_tasks")
|
||||
for column, example in (
|
||||
("expires_at", ""),
|
||||
("failure_count", 0),
|
||||
("notify", 0),
|
||||
("tz", ""),
|
||||
):
|
||||
if not tasks.has_column(column):
|
||||
tasks.create_column_by_example(column, example)
|
||||
try:
|
||||
with db:
|
||||
db.query(
|
||||
"UPDATE devii_tasks SET failure_count = 0 WHERE failure_count IS NULL"
|
||||
)
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.warning(f"Could not backfill devii_tasks.failure_count: {e}")
|
||||
_index(db, "devii_tasks", "idx_devii_tasks_owner", ["owner_kind", "owner_id"])
|
||||
_index(
|
||||
db, "devii_tasks", "idx_devii_tasks_due", ["enabled", "status", "next_run_at"]
|
||||
@@ -1058,6 +1075,7 @@ def init_db():
|
||||
("infra_observability", 0),
|
||||
("defense_level", 0),
|
||||
("defense_last_upkeep_at", ""),
|
||||
("upkeep_amnesty", 0),
|
||||
("active_title", ""),
|
||||
("underdog_boost_until", ""),
|
||||
("contract_boost_until", ""),
|
||||
@@ -1092,6 +1110,7 @@ def init_db():
|
||||
_index(
|
||||
db, "game_steals", "idx_game_steals_pair", ["thief_uid", "owner_uid", "stolen_at"]
|
||||
)
|
||||
_index(db, "game_steals", "idx_game_steals_owner_time", ["owner_uid", "stolen_at"])
|
||||
|
||||
game_quests = get_table("game_quests")
|
||||
for column, example in (
|
||||
@@ -1129,6 +1148,7 @@ def init_db():
|
||||
("planted_at", ""),
|
||||
("ready_at", ""),
|
||||
("watered_by", "[]"),
|
||||
("raided_fraction", 0.0),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
):
|
||||
@@ -1205,6 +1225,7 @@ def init_db():
|
||||
("rank", 0),
|
||||
("era_score", 0),
|
||||
("era_coins_final", 0),
|
||||
("joined_at", ""),
|
||||
("reward_stars", 0),
|
||||
("reward_cosmetic_key", ""),
|
||||
("created_at", ""),
|
||||
@@ -1213,6 +1234,149 @@ def init_db():
|
||||
game_era_results.create_column_by_example(column, example)
|
||||
_index(db, "game_era_results", "idx_game_era_results_era", ["era_number", "rank"])
|
||||
|
||||
quizzes = get_table("quizzes")
|
||||
for column, example in (
|
||||
("uid", ""),
|
||||
("user_uid", ""),
|
||||
("slug", ""),
|
||||
("title", ""),
|
||||
("description", ""),
|
||||
("status", "draft"),
|
||||
("published_at", ""),
|
||||
("shuffle_questions", 0),
|
||||
("shuffle_options", 0),
|
||||
("reveal_answers", 0),
|
||||
("allow_review", 0),
|
||||
("time_limit_seconds", 0),
|
||||
("pass_percent", 0),
|
||||
("question_count", 0),
|
||||
("total_points", 0),
|
||||
("attempt_count", 0),
|
||||
("stars", 0),
|
||||
("content_version", 0),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
("deleted_at", ""),
|
||||
("deleted_by", ""),
|
||||
):
|
||||
if not quizzes.has_column(column):
|
||||
quizzes.create_column_by_example(column, example)
|
||||
_index(db, "quizzes", "idx_quizzes_slug", ["slug"], unique=True)
|
||||
_index(db, "quizzes", "idx_quizzes_user_created", ["user_uid", "created_at"])
|
||||
_index(db, "quizzes", "idx_quizzes_status_created", ["status", "created_at"])
|
||||
_index(
|
||||
db,
|
||||
"quizzes",
|
||||
"idx_quizzes_live_created",
|
||||
["created_at"],
|
||||
where="deleted_at IS NULL",
|
||||
)
|
||||
|
||||
quiz_questions = get_table("quiz_questions")
|
||||
for column, example in (
|
||||
("uid", ""),
|
||||
("quiz_uid", ""),
|
||||
("position", 0),
|
||||
("kind", ""),
|
||||
("prompt", ""),
|
||||
("explanation", ""),
|
||||
("points", 1),
|
||||
("media_attachment_uid", ""),
|
||||
("correct_boolean", 0),
|
||||
("expected_answer", ""),
|
||||
("grading_criteria", ""),
|
||||
("numeric_value", 0.0),
|
||||
("numeric_tolerance", 0.0),
|
||||
("case_sensitive", 0),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
("deleted_at", ""),
|
||||
("deleted_by", ""),
|
||||
):
|
||||
if not quiz_questions.has_column(column):
|
||||
quiz_questions.create_column_by_example(column, example)
|
||||
_index(
|
||||
db, "quiz_questions", "idx_quiz_questions_quiz_position", ["quiz_uid", "position"]
|
||||
)
|
||||
|
||||
quiz_options = get_table("quiz_options")
|
||||
for column, example in (
|
||||
("uid", ""),
|
||||
("question_uid", ""),
|
||||
("quiz_uid", ""),
|
||||
("position", 0),
|
||||
("label", ""),
|
||||
("match_value", ""),
|
||||
("is_correct", 0),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
("deleted_at", ""),
|
||||
("deleted_by", ""),
|
||||
):
|
||||
if not quiz_options.has_column(column):
|
||||
quiz_options.create_column_by_example(column, example)
|
||||
_index(
|
||||
db,
|
||||
"quiz_options",
|
||||
"idx_quiz_options_question_position",
|
||||
["question_uid", "position"],
|
||||
)
|
||||
_index(db, "quiz_options", "idx_quiz_options_quiz", ["quiz_uid"])
|
||||
|
||||
quiz_attempts = get_table("quiz_attempts")
|
||||
for column, example in (
|
||||
("uid", ""),
|
||||
("quiz_uid", ""),
|
||||
("user_uid", ""),
|
||||
("status", "in_progress"),
|
||||
("question_order", "[]"),
|
||||
("started_at", ""),
|
||||
("expires_at", ""),
|
||||
("completed_at", ""),
|
||||
("answered_count", 0),
|
||||
("score_points", 0.0),
|
||||
("max_points", 0),
|
||||
("score_percent", 0.0),
|
||||
("passed", 0),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
("deleted_at", ""),
|
||||
("deleted_by", ""),
|
||||
):
|
||||
if not quiz_attempts.has_column(column):
|
||||
quiz_attempts.create_column_by_example(column, example)
|
||||
_index(db, "quiz_attempts", "idx_quiz_attempts_user_created", ["user_uid", "created_at"])
|
||||
_index(db, "quiz_attempts", "idx_quiz_attempts_quiz_status", ["quiz_uid", "status"])
|
||||
_index(db, "quiz_attempts", "idx_quiz_attempts_user_quiz", ["user_uid", "quiz_uid"])
|
||||
_index(db, "quiz_attempts", "idx_quiz_attempts_status_user", ["status", "user_uid"])
|
||||
|
||||
quiz_answers = get_table("quiz_answers")
|
||||
for column, example in (
|
||||
("uid", ""),
|
||||
("attempt_uid", ""),
|
||||
("question_uid", ""),
|
||||
("quiz_uid", ""),
|
||||
("position", 0),
|
||||
("answer_text", ""),
|
||||
("option_uids", "[]"),
|
||||
("answered_at", ""),
|
||||
("is_correct", 0),
|
||||
("awarded_points", 0.0),
|
||||
("feedback", ""),
|
||||
("graded_by", ""),
|
||||
("confidence", 0.0),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
("deleted_at", ""),
|
||||
("deleted_by", ""),
|
||||
):
|
||||
if not quiz_answers.has_column(column):
|
||||
quiz_answers.create_column_by_example(column, example)
|
||||
_index(
|
||||
db, "quiz_answers", "idx_quiz_answers_attempt_position", ["attempt_uid", "position"]
|
||||
)
|
||||
_index(db, "quiz_answers", "idx_quiz_answers_quiz", ["quiz_uid"])
|
||||
|
||||
_index(db, "posts", "idx_posts_user_created", ["user_uid", "created_at"])
|
||||
_index(
|
||||
db,
|
||||
|
||||
Reference in New Issue
Block a user