Skip to content
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

Make database dumps work with the partitioned version_downloads table. #1

Open
wants to merge 2 commits into
base: sg-partition-version-downloads
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ hyper-tls = "0.3"
lazy_static = "1.0"
tokio-core = "0.1"
diesel_migrations = { version = "1.3.0", features = ["postgres"] }
glob = "0.3"

[build-dependencies]
dotenv = "0.15"
Expand Down
168 changes: 63 additions & 105 deletions src/tasks/dump_db/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,49 @@
# database table, we set which columns are included in the dump, and optionally
# how to filter the rows.
#
# <table_name>.columns - a TOML dictionary determining what columns to include.
# possible values are "private" (not included) and "public" (included).
# tables.<table_name>.columns - a TOML dictionary determining what columns to
# include. possible values are "private" (not included) and "public"
# (included).
#
# <table_name>.filter - a string that is a valid SQL expression, which is used
# in a WHERE clause to filter the rows of the table.
# tables.<table_name>.filter - a string that is a valid SQL expression, which
# is used in a WHERE clause to filter the rows of the table.
#
# <table_name>.dependencies - an array of table names, used to determine the
# order of the tables in the generated import script. All tables referred
# to by public columns in the current table should be listed, to make sure
# they are imported before this table.
# tables.<table_name>.dependencies - an array of table names, used to determine
# the order of the tables in the generated import script. All tables
# referred to by public columns in the current table should be listed, to
# make sure they are imported before this table.
#
# <table_name>.columns_defaults - a TOML dictionary mapping column names to a
# raw SQL expression that is used as the default value for the column on
# import. This is useful for private columns that are not nullable and do
# not have a default.

[api_tokens.columns]
id = "private"
user_id = "private"
token = "private"
name = "private"
created_at = "private"
last_used_at = "private"
revoked = "private"

[background_jobs.columns]
id = "private"
job_type = "private"
data = "private"
retries = "private"
last_retry = "private"
created_at = "private"

[badges]
# tables.<table_name>.columns_defaults - a TOML dictionary mapping column names
# to a raw SQL expression that is used as the default value for the column
# on import. This is useful for private columns that are not nullable and
# do not have a default.
#
# private_table - an array of tables to consider as completely private. This is
# a shortcut for marking all columns of a table as private.

private_tables = [
"__diesel_schema_migrations",
"api_tokens",
"background_jobs",
"crate_owner_invitations",
"emails",
"follows",
"publish_limit_buckets",
"publish_rate_overrides",
"readme_renderings",
"version_owner_actions",
"versions_published_by",
"version_downloads_*",
]

[tables.badges]
dependencies = ["crates"]
[badges.columns]
[tables.badges.columns]
crate_id = "public"
badge_type = "public"
attributes = "public"

[categories.columns]
[tables.categories.columns]
id = "public"
category = "public"
slug = "public"
Expand All @@ -51,18 +53,10 @@ crates_cnt = "public"
created_at = "public"
path = "public"

[crate_owner_invitations.columns]
invited_user_id = "private"
invited_by_user_id = "private"
crate_id = "private"
created_at = "private"
token = "private"
token_generated_at = "private"

[crate_owners]
[tables.crate_owners]
dependencies = ["crates", "users"]
filter = "NOT deleted"
[crate_owners.columns]
[tables.crate_owners.columns]
crate_id = "public"
owner_id = "public"
created_at = "public"
Expand All @@ -72,7 +66,7 @@ updated_at = "private"
owner_kind = "public"
email_notifications = "private"

[crates.columns]
[tables.crates.columns]
id = "public"
name = "public"
updated_at = "public"
Expand All @@ -86,21 +80,21 @@ textsearchable_index_col = "public"
repository = "public"
max_upload_size = "public"

[crates_categories]
[tables.crates_categories]
dependencies = ["categories", "crates"]
[crates_categories.columns]
[tables.crates_categories.columns]
crate_id = "public"
category_id = "public"

[crates_keywords]
[tables.crates_keywords]
dependencies = ["crates", "keywords"]
[crates_keywords.columns]
[tables.crates_keywords.columns]
crate_id = "public"
keyword_id = "public"

[dependencies]
[tables.dependencies]
dependencies = ["crates", "versions"]
[dependencies.columns]
[tables.dependencies.columns]
id = "public"
version_id = "public"
crate_id = "public"
Expand All @@ -111,99 +105,67 @@ features = "public"
target = "public"
kind = "public"

[__diesel_schema_migrations.columns]
version = "private"
run_on = "private"

[emails.columns]
id = "private"
user_id = "private"
email = "private"
verified = "private"
token = "private"
token_generated_at = "private"

[follows.columns]
user_id = "private"
crate_id = "private"

[keywords.columns]
[tables.keywords.columns]
id = "public"
keyword = "public"
crates_cnt = "public"
created_at = "public"

[metadata.columns]
[tables.metadata.columns]
total_downloads = "public"

[publish_limit_buckets.columns]
user_id = "private"
tokens = "private"
last_refill = "private"

[publish_rate_overrides.columns]
user_id = "private"
burst = "private"

[readme_renderings.columns]
version_id = "private"
rendered_at = "private"

[reserved_crate_names.columns]
[tables.reserved_crate_names.columns]
name = "public"

[teams.columns]
[tables.teams.columns]
id = "public"
login = "public"
github_id = "public"
name = "public"
avatar = "public"

[users]
[tables.users]
filter = """
id in (
SELECT owner_id AS user_id FROM crate_owners WHERE NOT deleted AND owner_kind = 0
UNION
SELECT published_by as user_id FROM versions
)"""
[users.columns]
[tables.users.columns]
id = "public"
gh_access_token = "private"
gh_login = "public"
name = "public"
gh_avatar = "public"
gh_id = "public"
[users.column_defaults]
[tables.users.column_defaults]
gh_access_token = "''"

[version_authors]
[tables.version_authors]
dependencies = ["versions"]
[version_authors.columns]
[tables.version_authors.columns]
id = "public"
version_id = "public"
user_id = "private"
name = "public"

[version_downloads]
[tables.version_downloads]
# The version_downloads table is partitioned, so the COPY statements used for
# other tables does not work for this table. By using a filter of "TRUE", we
# trigger the use of a subquery in the COPY statement:
#
# \copy (SELECT ... FROM "version_downloads" WHERE TRUE) TO ...
filter = "TRUE"
dependencies = ["versions"]
[version_downloads.columns]
[tables.version_downloads.columns]
version_id = "public"
downloads = "public"
counted = "private"
date = "public"
processed = "private"

[version_owner_actions.columns]
id = "private"
version_id = "private"
user_id = "private"
api_token_id = "private"
action = "private"
time = "private"

[versions]
[tables.versions]
dependencies = ["crates", "users"]
[versions.columns]
[tables.versions.columns]
id = "public"
crate_id = "public"
num = "public"
Expand All @@ -215,7 +177,3 @@ yanked = "public"
license = "public"
crate_size = "public"
published_by = "public"

[versions_published_by.columns]
version_id = "private"
email = "private"
Loading