Browse Source

Rename pkg db tables, and fix logging typo

default_compile_flags
vector-of-bool 3 years ago
parent
commit
5a8b5eac7e
3 changed files with 29 additions and 31 deletions
  1. +19
    -21
      src/dds/pkg/db.cpp
  2. +9
    -9
      src/dds/pkg/remote.cpp
  3. +1
    -1
      src/dds/util/http/pool.cpp

+ 19
- 21
src/dds/pkg/db.cpp View File

@@ -78,7 +78,7 @@ void migrate_repodb_2(nsql::database& db) {

void migrate_repodb_3(nsql::database& db) {
db.exec(R"(
CREATE TABLE dds_cat_remotes (
CREATE TABLE dds_pkg_remotes (
remote_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
remote_url TEXT NOT NULL,
@@ -86,23 +86,23 @@ void migrate_repodb_3(nsql::database& db) {
db_mtime TEXT
);

CREATE TABLE dds_cat_pkgs_new (
CREATE TABLE dds_pkgs (
pkg_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
version TEXT NOT NULL,
description TEXT NOT NULL,
remote_url TEXT NOT NULL,
remote_id INTEGER
REFERENCES dds_cat_remotes
REFERENCES dds_pkg_remotes
ON DELETE CASCADE,
UNIQUE (name, version, remote_id)
);

INSERT INTO dds_cat_pkgs_new(pkg_id,
name,
version,
description,
remote_url)
INSERT INTO dds_pkgs(pkg_id,
name,
version,
description,
remote_url)
SELECT pkg_id,
name,
version,
@@ -115,11 +115,11 @@ void migrate_repodb_3(nsql::database& db) {
) || '#' || git_ref
FROM dds_cat_pkgs;

CREATE TABLE dds_cat_pkg_deps_new (
CREATE TABLE dds_pkg_deps (
dep_id INTEGER PRIMARY KEY AUTOINCREMENT,
pkg_id INTEGER
NOT NULL
REFERENCES dds_cat_pkgs_new(pkg_id)
REFERENCES dds_pkgs(pkg_id)
ON DELETE CASCADE,
dep_name TEXT NOT NULL,
low TEXT NOT NULL,
@@ -127,12 +127,10 @@ void migrate_repodb_3(nsql::database& db) {
UNIQUE(pkg_id, dep_name)
);

INSERT INTO dds_cat_pkg_deps_new SELECT * FROM dds_cat_pkg_deps;
INSERT INTO dds_pkg_deps SELECT * FROM dds_cat_pkg_deps;

DROP TABLE dds_cat_pkg_deps;
DROP TABLE dds_cat_pkgs;
ALTER TABLE dds_cat_pkgs_new RENAME TO dds_cat_pkgs;
ALTER TABLE dds_cat_pkg_deps_new RENAME TO dds_cat_pkg_deps;
)");
}

@@ -150,7 +148,7 @@ void store_with_remote(neo::sqlite3::statement_cache& stmts,
const http_remote_listing& http) {
nsql::exec( //
stmts(R"(
INSERT OR REPLACE INTO dds_cat_pkgs (
INSERT OR REPLACE INTO dds_pkgs (
name,
version,
remote_url,
@@ -177,7 +175,7 @@ void store_with_remote(neo::sqlite3::statement_cache& stmts,

nsql::exec( //
stmts(R"(
INSERT OR REPLACE INTO dds_cat_pkgs (
INSERT OR REPLACE INTO dds_pkgs (
name,
version,
remote_url,
@@ -202,7 +200,7 @@ void do_store_pkg(neo::sqlite3::database& db,
std::visit([&](auto&& remote) { store_with_remote(st_cache, pkg, remote); }, pkg.remote);
auto db_pkg_id = db.last_insert_rowid();
auto& new_dep_st = st_cache(R"(
INSERT INTO dds_cat_pkg_deps (
INSERT INTO dds_pkg_deps (
pkg_id,
dep_name,
low,
@@ -319,7 +317,7 @@ std::optional<pkg_info> pkg_db::get(const pkg_id& pk_id) const noexcept {
version,
remote_url,
description
FROM dds_cat_pkgs
FROM dds_pkgs
WHERE name = ?1 AND version = ?2
ORDER BY pkg_id DESC
)"_sql);
@@ -379,7 +377,7 @@ auto pair_to_pkg_id = [](auto&& pair) {

std::vector<pkg_id> pkg_db::all() const noexcept {
return nsql::exec_tuples<std::string, std::string>(
_stmt_cache("SELECT name, version FROM dds_cat_pkgs"_sql))
_stmt_cache("SELECT name, version FROM dds_pkgs"_sql))
| neo::lref //
| ranges::views::transform(pair_to_pkg_id) //
| ranges::to_vector;
@@ -390,7 +388,7 @@ std::vector<pkg_id> pkg_db::by_name(std::string_view sv) const noexcept {
_stmt_cache(
R"(
SELECT name, version
FROM dds_cat_pkgs
FROM dds_pkgs
WHERE name = ?
ORDER BY pkg_id DESC
)"_sql),
@@ -409,11 +407,11 @@ std::vector<dependency> pkg_db::dependencies_of(const pkg_id& pkg) const noexcep
R"(
WITH this_pkg_id AS (
SELECT pkg_id
FROM dds_cat_pkgs
FROM dds_pkgs
WHERE name = ? AND version = ?
)
SELECT dep_name, low, high
FROM dds_cat_pkg_deps
FROM dds_pkg_deps
WHERE pkg_id IN this_pkg_id
ORDER BY dep_name
)"_sql),

+ 9
- 9
src/dds/pkg/remote.cpp View File

@@ -62,7 +62,7 @@ pkg_remote pkg_remote::connect(std::string_view url_str) {

void pkg_remote::store(nsql::database_ref db) {
auto st = db.prepare(R"(
INSERT INTO dds_cat_remotes (name, remote_url)
INSERT INTO dds_pkg_remotes (name, remote_url)
VALUES (?, ?)
ON CONFLICT (name) DO
UPDATE SET remote_url = ?2
@@ -103,7 +103,7 @@ void pkg_remote::update_pkg_db(nsql::database_ref db,

auto db_path = rdb._tempdir.path() / "repo.db";

auto rid_st = db.prepare("SELECT remote_id FROM dds_cat_remotes WHERE name = ?");
auto rid_st = db.prepare("SELECT remote_id FROM dds_pkg_remotes WHERE name = ?");
rid_st.bindings()[1] = _name;
auto [remote_id] = nsql::unpack_single<std::int64_t>(rid_st);
rid_st.reset();
@@ -115,14 +115,14 @@ void pkg_remote::update_pkg_db(nsql::database_ref db,
dds_log(trace, "Clearing prior contents");
nsql::exec( //
db.prepare(R"(
DELETE FROM dds_cat_pkgs
DELETE FROM dds_pkgs
WHERE remote_id = ?
)"),
remote_id);
dds_log(trace, "Importing packages");
nsql::exec( //
db.prepare(R"(
INSERT INTO dds_cat_pkgs
INSERT INTO dds_pkgs
(name, version, description, remote_url, remote_id)
SELECT
name,
@@ -144,7 +144,7 @@ void pkg_remote::update_pkg_db(nsql::database_ref db,
base_url_str);
dds_log(trace, "Importing dependencies");
db.exec(R"(
INSERT OR REPLACE INTO dds_cat_pkg_deps (pkg_id, dep_name, low, high)
INSERT OR REPLACE INTO dds_pkg_deps (pkg_id, dep_name, low, high)
SELECT
local_pkgs.pkg_id AS pkg_id,
dep_name,
@@ -152,7 +152,7 @@ void pkg_remote::update_pkg_db(nsql::database_ref db,
high
FROM remote.dds_repo_package_deps AS deps,
remote.dds_repo_packages AS pkgs USING(package_id),
dds_cat_pkgs AS local_pkgs USING(name, version)
dds_pkgs AS local_pkgs USING(name, version)
)");
// Validate our database
dds_log(trace, "Running integrity check");
@@ -184,12 +184,12 @@ void pkg_remote::update_pkg_db(nsql::database_ref db,

// Save the cache info for the remote
if (auto new_etag = resp.etag()) {
nsql::exec(db.prepare("UPDATE dds_cat_remotes SET db_etag = ? WHERE name = ?"),
nsql::exec(db.prepare("UPDATE dds_pkg_remotes SET db_etag = ? WHERE name = ?"),
*new_etag,
_name);
}
if (auto mtime = resp.last_modified()) {
nsql::exec(db.prepare("UPDATE dds_cat_remotes SET db_mtime = ? WHERE name = ?"),
nsql::exec(db.prepare("UPDATE dds_pkg_remotes SET db_mtime = ? WHERE name = ?"),
*mtime,
_name);
}
@@ -197,7 +197,7 @@ void pkg_remote::update_pkg_db(nsql::database_ref db,

void dds::update_all_remotes(nsql::database_ref db) {
dds_log(info, "Updating catalog from all remotes");
auto repos_st = db.prepare("SELECT name, remote_url, db_etag, db_mtime FROM dds_cat_remotes");
auto repos_st = db.prepare("SELECT name, remote_url, db_etag, db_mtime FROM dds_pkg_remotes");
auto tups = nsql::iter_tuples<std::string,
std::string,
std::optional<std::string>,

+ 1
- 1
src/dds/util/http/pool.cpp View File

@@ -99,8 +99,8 @@ struct http_client_impl {

dds_log(trace,
" --> HTTP {} {}://{}:{}{}",
origin.protocol,
params.method,
origin.protocol,
origin.hostname,
origin.port,
params.path);

Loading…
Cancel
Save