Skip to content

Prototype: Public database dumps #1800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8487e80
Add dump_db task.
smarnach Aug 27, 2019
32ec944
Add documentation to dump-db.toml.
smarnach Aug 17, 2019
4bfd40c
Refactor enqueue helper in the enqueue-job binary.
smarnach Aug 17, 2019
1d50084
Reduce global state in dump_db task.
smarnach Aug 17, 2019
0ed2929
Address review comments by @carols10cents.
smarnach Aug 21, 2019
c2dce7c
Make database URL and upload target of DB dumps configurable.
smarnach Aug 24, 2019
a648dbd
Make cleanup of old database files more robust.
smarnach Aug 26, 2019
29a86e9
Adapt dump_db to new uploader interface.
smarnach Aug 27, 2019
ec06f10
Correct error handling for the psql call.
smarnach Aug 26, 2019
d4b9f8c
Use Handlebars template to generate psql script.
smarnach Aug 29, 2019
ee888f8
Add code to generate import script for dumps.
smarnach Aug 29, 2019
bcbccd6
Include import and export scripts in the database dump.
smarnach Aug 29, 2019
3eff6dc
Set default value for gh_access_token in import script.
smarnach Sep 2, 2019
b085a78
Simplify topological sort implementation.
smarnach Sep 3, 2019
b4ad1f1
Move psql script generation code to submodule.
smarnach Sep 3, 2019
3b477c9
Refactor dump_db code to use Drop for cleanup.
smarnach Sep 3, 2019
4448ca8
Refactor schema check unit test.
smarnach Sep 3, 2019
ede4fe0
Allow specifying column defaults in the DB dump config.
smarnach Sep 5, 2019
1c4737b
Add basic unit tests for topological sorting.
smarnach Sep 5, 2019
c373f4b
Add prototype for dump_db integration test.
smarnach Sep 8, 2019
44a995a
Use cloned() instead of copied().
smarnach Sep 8, 2019
f5f536a
Suppress migrations output in dump_db test.
smarnach Sep 8, 2019
cacbc4f
Merge remote-tracking branch 'origin' into dump-db-new
smarnach Sep 8, 2019
200d99f
Remove crates.licence column from dump_db configuration.
smarnach Sep 8, 2019
db89e77
Merge remote-tracking branch 'origin' into dump-db-new
smarnach Sep 12, 2019
e760a53
Move data in dump tarbal into subdirectory.
smarnach Sep 12, 2019
3beeb38
Add README and metadata to database dump.
smarnach Sep 12, 2019
d8b45d9
Remove redundant dependency in dump-db.toml.
smarnach Sep 14, 2019
cc8f22e
Inlcude schema dump in database dump.
smarnach Sep 14, 2019
620bb51
Remove format version from dump metadata.
smarnach Sep 16, 2019
ba3709b
Document the database dumps in the frontend.
smarnach Sep 17, 2019
4e479cf
Merge remote-tracking branch 'origin' into dump-db-new
smarnach Sep 18, 2019
c142880
Add dependency for badges on crates to db dump configuration.
smarnach Sep 18, 2019
a57fed2
Small edits to the data access documentation
carols10cents Sep 28, 2019
01a4e98
Take new clippy suggestions that came with 1.38
carols10cents Sep 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ tokio = "0.1"
hyper = "0.12"
ctrlc = { version = "3.0", features = ["termination"] }
indexmap = "1.0.2"
handlebars = "2.0.1"

[dev-dependencies]
conduit-test = "0.8"
hyper-tls = "0.3"
lazy_static = "1.0"
tokio-core = "0.1"
diesel_migrations = { version = "1.3.0", features = ["postgres"] }

[build-dependencies]
dotenv = "0.11"
Expand Down
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Router.map(function() {
this.route('category-slugs', { path: 'category_slugs' });
this.route('team', { path: '/teams/:team_id' });
this.route('policies');
this.route('data-access');
this.route('confirm', { path: '/confirm/:email_token' });

this.route('catch-all', { path: '*path' });
Expand Down
34 changes: 34 additions & 0 deletions app/templates/data-access.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div id='crates-heading'>
{{svg-jar 'circle-with-i'}}
<h1>Accessing the Crates.io Data</h1>
</div>

<p>
There are several ways of accessing the Crates.io data. You should try the
options in the order listed.
</p>

<ol>
<li>
<b>
The <a href='https://github.com/rust-lang/crates.io-index'>crates.io index</a>.
</b>
This git repository is updated by crates.io, and it is used
by Cargo to speed up local dependency resolution. It contains the majority
of the data exposed by crates.io and is cheap to clone and get updates.
</li>
<li>
<b>The database dumps (experimental).</b> The dump contains all information
exposed by the API in a single download. It is updated every 24 hours.
The latest dump is available at the address
<a href='https://static.crates.io/db-dump.tar.gz'>https://static.crates.io/db-dump.tar.gz</a>.
Information on using the dump is contained in the tarball.
</li>
<li>
<b>Crawl the crates.io API.</b> This should be used as a last resort, and
doing so is subject to our {{#link-to 'policies'}}crawling policy{{/link-to}}.
If the index and the database dumps do not satisfy your needs, we're happy to
discuss solutions that don't require you to crawl the registry.
You can email us at <a href="mailto:[email protected]">[email protected]</a>.
</li>
</ol>
11 changes: 2 additions & 9 deletions app/templates/policies.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,8 @@
<h2 id='crawlers'><a href='#crawlers'>Crawlers</a></h2>

<p>
Before resorting to crawling crates.io, you should first see if you are able to
gather the information you need from the
<a href='https://github.com/rust-lang/crates.io-index'>crates.io index</a>,
which is a public git repository containing the majority
of the information availble through our API.

If the index does not have the information you need, we're also happy to
discuss solutions to your needs that don't require you to crawl the registry.
You can email us at <a href="mailto:[email protected]">[email protected]</a>.
Before resorting to crawling crates.io, please read
{{#link-to 'data-access'}}Accessing the Crates.io Data{{/link-to}}.
</p>

<p>
Expand Down
3 changes: 1 addition & 2 deletions migrations/2017-10-08-193512_category_trees/up.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- Your SQL goes here
CREATE EXTENSION ltree;
CREATE EXTENSION IF NOT EXISTS ltree;

-- Create the new column which will represent our category tree.
-- Fill it with values from `slug` column and then set to non-null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CREATE EXTENSION pg_trgm;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX index_crates_name_tgrm ON crates USING gin (canon_crate_name(name) gin_trgm_ops);
36 changes: 24 additions & 12 deletions src/bin/enqueue-job.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
use cargo_registry::util::{CargoError, CargoResult};
use cargo_registry::{db, tasks};
use std::env::args;
use swirl::Job;
use cargo_registry::util::{human, CargoError, CargoResult};
use cargo_registry::{db, env, tasks};
use diesel::PgConnection;

fn main() -> CargoResult<()> {
let conn = db::connect_now()?;
let mut args = std::env::args().skip(1);
match &*args.next().unwrap_or_default() {
"update_downloads" => tasks::update_downloads().enqueue(&conn),
"dump_db" => {
let database_url = args.next().unwrap_or_else(|| env("DATABASE_URL"));
let target_name = args
.next()
.unwrap_or_else(|| String::from("db-dump.tar.gz"));
tasks::dump_db(database_url, target_name).enqueue(&conn)
}
other => Err(human(&format!("Unrecognized job type `{}`", other))),
}
}

match &*args().nth(1).unwrap_or_default() {
"update_downloads" => tasks::update_downloads()
.enqueue(&conn)
.map_err(|e| CargoError::from_std_error(e))?,
other => panic!("Unrecognized job type `{}`", other),
};

Ok(())
/// Helper to map the `PerformError` returned by `swirl::Job::enqueue()` to a
/// `CargoError`. Can be removed once `map_err()` isn't needed any more.
trait Enqueue: swirl::Job {
fn enqueue(self, conn: &PgConnection) -> CargoResult<()> {
<Self as swirl::Job>::enqueue(self, conn).map_err(|e| CargoError::from_std_error(e))
}
}

impl<J: swirl::Job> Enqueue for J {}
2 changes: 2 additions & 0 deletions src/tasks.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod dump_db;
mod update_downloads;

pub use dump_db::dump_db;
pub use update_downloads::update_downloads;
Loading