Create and discard an archive database file

未关闭
#378 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
django, python, sqlite
领域
backend, database

调研方向

Start with morango/sync/archive.py and morango/errors.py, then read the SyncDatabase pattern from #365 and the alias and migration notes in #362. Use the acceptance criteria and router override requirement to guide tests for creation, migration failure cleanup, and discard; done means the full test suite passes and all listed archive behaviors hold.

由索引模型根据 Issue 内容生成。

描述

DEV: backend DEV: distributions P0 - critical TAG: new feature

Overview

Morango can create a new SQLite archive file with only the morango tables, and it can discard that file cleanly. This work is part of milestone M5.

Background & Motivation

The archive is a second Django database. Morango must open it at run time, add the morango tables with the normal migrations, and remove every trace of it after a failure. The work happens in a partial file, and only a completed export gets the final name.

Design: spec. Plan: implementation plan, Task 17.

Description & Expected Outcomes

Archive.create(path) refuses a path that exists. It writes to <path>.partial and replaces a stale partial file. It registers an archive alias with the prefix morango_archive_, and it turns on incremental auto-vacuum before the tables exist. Then it runs the morango migrations on the archive alias and makes sure that every morango table exists.

If a table is missing, a host router blocked the migration. In that case, create raises MorangoArchiveError with a message about the router requirement. Archive.discard() closes the connection, removes the archive alias, and deletes the partial file.

An ArchiveDatabase handle gives the archive alias to other code. Every query through this handle goes to the archive.

Deliverables & Contracts

The change delivers these capabilities:

  • ARCHIVE_ALIAS_PREFIX, with the value "morango_archive_".
  • ArchiveDatabase, a subclass of SyncDatabase with a fixed alias.
  • Archive.create(path) and Archive.discard().
  • The errors MorangoArchiveError and MorangoArchiveExists.
Acceptance Criteria
  • create on a new path makes <path>.partial with a table for every morango model.
  • PRAGMA auto_vacuum on the new file returns 2 (incremental).
  • create on an existing path raises MorangoArchiveExists.
  • create replaces a stale <path>.partial.
  • If a router denies morango migrations on the prefix, create raises MorangoArchiveError, and no archive alias and no partial file remain.
  • discard removes the partial file and the archive alias, and a second discard does nothing.
  • The full test suite passes.

Technical Pointers & Architecture

  • Target Components / Context: morango/sync/archive.py, morango/errors.py.
  • Related Patterns: SyncDatabase from #365. The spike in #362 records how alias registration and migrations work on Django 3.2.
  • Data Model & Schema Considerations: The archive uses the normal morango migrations, so its django_migrations table records its schema version.
  • Resilience & Failure Modes: Every failure after the alias registration must remove the archive alias and the partial file. Errors must propagate. A router that denies migration makes Django skip every table, record the migrations as applied, and raise no error (#362). The table check is what detects it. Django connections are thread-local, so register, use and remove the alias on one thread.

Notes & Tradeoffs

  • Dependencies: Blocked by: #362 (spike), #365 (SyncDatabase), #377 (ArchiveManifest). Blocks: #379, #380, #381, #382.
  • Testing Requirements: Use override_settings(DATABASE_ROUTERS=[...]) for the router case.
  • Tradeoffs & Alternatives Considered: The migrate command sends post_migrate to all apps, and the contenttypes app then needs its table in the archive. A direct call to the migration executor prevents this.
  • Compatibility & Migrations: Kolibri routers must allow morango migrations on aliases with the prefix.

Metadata

  • Complexity: Medium
  • Target Branch: release-v0.9.x

AI Usage

Drafted with Claude (Claude Code) from the approved design spec and implementation plan. The author reviewed the requirements, and the code references were checked against the release-v0.9.x codebase.

主要语言
Python
星标
15
派生
27
平均合并
6 天 44 分钟
30 天内合并 PR
13

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

learningequality/morango 的其他 Issue

查看 learningequality/morango 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。