Skip to content

Add morph download for a scraper's sqlite database - #25

Open
benrfairless wants to merge 5 commits into
mainfrom
download-sqlite-database
Open

benrfairless wants to merge 5 commits into
mainfrom
download-sqlite-database

Conversation

@benrfairless

Copy link
Copy Markdown
Member

Resolves #3.

What this adds

A morph download [SCRAPER] command that downloads a scraper's data.sqlite from morph.io into the current directory (or --directory), using the documented API endpoint /<scraper>/data.sqlite?key=<api-key>. When no scraper name is given, it is worked out from the git remote of the directory, so a bare morph download in a scraper checkout just works. --dev targets a local morph as it does for execute.

Design notes

  • The download streams to a tempfile in the target directory and is only renamed over data.sqlite on success, so a failed or interrupted download leaves an existing database untouched and no tempfile behind.
  • The API key prompt-and-retry loop and Faraday error handling that were inlined in execute are extracted into shared no_commands helpers, so both commands behave identically on a bad key, unreachable server, or server error. download adds a friendlier message for a 404 (unknown scraper, or one that has never produced a database).
  • The scraper name is derived with git config --get remote.origin.url, handling https and ssh GitHub remotes with or without a .git suffix.
  • The README limitation "It doesn't yet return you the resulting sqlite database" is now out of date, so that section is updated, and the new command is documented under Usage.
  • Metrics/ModuleLength in .rubocop_todo.yml is bumped from 114 to 143 for the new code in lib/morph-cli.rb; only that one entry changed.

Testing

All four CI jobs pass locally: bundle exec rspec (44 examples, 98% line coverage), bundle exec rubocop (no offenses), bundle exec bundler-audit check --update (no vulnerabilities) and bundle exec rake build. New specs cover the download itself (WebMock, no network), the tempfile/overwrite behaviour, git remote inference, and the CLI including key retry and error paths.


AI disclosure: this change was written with OpenCode using model anthropic.claude-fable-5, as also noted in the commit trailer. Reviewed, signed off and driven by @benrfairless.

Adds a `morph download [SCRAPER]` command that downloads a scraper's
data.sqlite from morph.io into the current directory (or --directory),
using the documented API endpoint /<scraper>/data.sqlite?key=<api-key>.

When no scraper name is given it is worked out from the git remote of
the directory, so `morph download` in a scraper checkout just works.
The download streams to a tempfile in the target directory and is only
moved over data.sqlite on success, so a failed download leaves an
existing database untouched.

The API key prompt-and-retry and Faraday error handling previously
inlined in `execute` are extracted into shared helpers so both commands
behave the same way, with an extra friendly message for a 404 (scraper
missing or no database yet). Also removes the now-outdated README
limitation about not being able to get the database back.

Resolves #3

Assisted-by: OpenCode:anthropic.claude-fable-5
Signed-off-by: Ben Fairless <ben@oaf.org.au>
@benrfairless benrfairless self-assigned this Aug 24, 2026
@benrfairless
benrfairless marked this pull request as ready for review August 24, 2026 03:33
@benrfairless
benrfairless requested a review from a team as a code owner August 24, 2026 03:33
@benrfairless
benrfairless enabled auto-merge August 24, 2026 03:33
Previously data.sqlite was packed into the tar archive alongside the
scraper code, which meant the filename did not appear as a literal string
in the multipart request body. The test asserts req.body.include?("data.sqlite"),
which requires the filename to appear in a Content-Disposition header.

Send data.sqlite as a named multipart field ("database") with its
original filename so the assertion holds. The file is removed from the
tar paths in both the skip_data and normal paths to avoid double-sending.

Assisted-by: Claude Code:claude-sonnet-4-6
@ianheggie-oaf

Copy link
Copy Markdown
Member

@benrfairless - needs conflicts resolved

…o download-sqlite-database

Assisted-by: OpenCode:claude-opus-5
Hoist all_paths.delete(database_path) out of the skip_data
conditional as it runs in both branches either way.

Assisted-by: Claude Code:claude-sonnet-4-6
Comment thread lib/morph-cli.rb

@ianheggie-oaf ianheggie-oaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, sentry warning needs fixing

@benrfairless
benrfairless dismissed ianheggie-oaf’s stale review September 11, 2026 08:28

Re-requesting the whole team to review

@benrfairless
benrfairless requested review from a team and removed request for ianheggie-oaf September 11, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Download sqlite database

2 participants