|
|
|
|
|
|
|
|
|
|
|
|
|
|
void migrate_repodb_3(nsql::database& db) { |
|
|
void migrate_repodb_3(nsql::database& db) { |
|
|
db.exec(R"( |
|
|
db.exec(R"( |
|
|
CREATE TABLE dds_cat_remotes ( |
|
|
|
|
|
|
|
|
CREATE TABLE dds_pkg_remotes ( |
|
|
remote_id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
|
remote_id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
|
name TEXT NOT NULL UNIQUE, |
|
|
name TEXT NOT NULL UNIQUE, |
|
|
remote_url TEXT NOT NULL, |
|
|
remote_url TEXT NOT NULL, |
|
|
|
|
|
|
|
|
db_mtime TEXT |
|
|
db_mtime TEXT |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
CREATE TABLE dds_cat_pkgs_new ( |
|
|
|
|
|
|
|
|
CREATE TABLE dds_pkgs ( |
|
|
pkg_id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
|
pkg_id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
|
name TEXT NOT NULL, |
|
|
name TEXT NOT NULL, |
|
|
version TEXT NOT NULL, |
|
|
version TEXT NOT NULL, |
|
|
description TEXT NOT NULL, |
|
|
description TEXT NOT NULL, |
|
|
remote_url TEXT NOT NULL, |
|
|
remote_url TEXT NOT NULL, |
|
|
remote_id INTEGER |
|
|
remote_id INTEGER |
|
|
REFERENCES dds_cat_remotes |
|
|
|
|
|
|
|
|
REFERENCES dds_pkg_remotes |
|
|
ON DELETE CASCADE, |
|
|
ON DELETE CASCADE, |
|
|
UNIQUE (name, version, remote_id) |
|
|
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, |
|
|
SELECT pkg_id, |
|
|
name, |
|
|
name, |
|
|
version, |
|
|
version, |
|
|
|
|
|
|
|
|
) || '#' || git_ref |
|
|
) || '#' || git_ref |
|
|
FROM dds_cat_pkgs; |
|
|
FROM dds_cat_pkgs; |
|
|
|
|
|
|
|
|
CREATE TABLE dds_cat_pkg_deps_new ( |
|
|
|
|
|
|
|
|
CREATE TABLE dds_pkg_deps ( |
|
|
dep_id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
|
dep_id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
|
pkg_id INTEGER |
|
|
pkg_id INTEGER |
|
|
NOT NULL |
|
|
NOT NULL |
|
|
REFERENCES dds_cat_pkgs_new(pkg_id) |
|
|
|
|
|
|
|
|
REFERENCES dds_pkgs(pkg_id) |
|
|
ON DELETE CASCADE, |
|
|
ON DELETE CASCADE, |
|
|
dep_name TEXT NOT NULL, |
|
|
dep_name TEXT NOT NULL, |
|
|
low TEXT NOT NULL, |
|
|
low TEXT NOT NULL, |
|
|
|
|
|
|
|
|
UNIQUE(pkg_id, dep_name) |
|
|
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_pkg_deps; |
|
|
DROP TABLE dds_cat_pkgs; |
|
|
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; |
|
|
|
|
|
)"); |
|
|
)"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const http_remote_listing& http) { |
|
|
const http_remote_listing& http) { |
|
|
nsql::exec( // |
|
|
nsql::exec( // |
|
|
stmts(R"( |
|
|
stmts(R"( |
|
|
INSERT OR REPLACE INTO dds_cat_pkgs ( |
|
|
|
|
|
|
|
|
INSERT OR REPLACE INTO dds_pkgs ( |
|
|
name, |
|
|
name, |
|
|
version, |
|
|
version, |
|
|
remote_url, |
|
|
remote_url, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsql::exec( // |
|
|
nsql::exec( // |
|
|
stmts(R"( |
|
|
stmts(R"( |
|
|
INSERT OR REPLACE INTO dds_cat_pkgs ( |
|
|
|
|
|
|
|
|
INSERT OR REPLACE INTO dds_pkgs ( |
|
|
name, |
|
|
name, |
|
|
version, |
|
|
version, |
|
|
remote_url, |
|
|
remote_url, |
|
|
|
|
|
|
|
|
std::visit([&](auto&& remote) { store_with_remote(st_cache, pkg, remote); }, pkg.remote); |
|
|
std::visit([&](auto&& remote) { store_with_remote(st_cache, pkg, remote); }, pkg.remote); |
|
|
auto db_pkg_id = db.last_insert_rowid(); |
|
|
auto db_pkg_id = db.last_insert_rowid(); |
|
|
auto& new_dep_st = st_cache(R"( |
|
|
auto& new_dep_st = st_cache(R"( |
|
|
INSERT INTO dds_cat_pkg_deps ( |
|
|
|
|
|
|
|
|
INSERT INTO dds_pkg_deps ( |
|
|
pkg_id, |
|
|
pkg_id, |
|
|
dep_name, |
|
|
dep_name, |
|
|
low, |
|
|
low, |
|
|
|
|
|
|
|
|
version, |
|
|
version, |
|
|
remote_url, |
|
|
remote_url, |
|
|
description |
|
|
description |
|
|
FROM dds_cat_pkgs |
|
|
|
|
|
|
|
|
FROM dds_pkgs |
|
|
WHERE name = ?1 AND version = ?2 |
|
|
WHERE name = ?1 AND version = ?2 |
|
|
ORDER BY pkg_id DESC |
|
|
ORDER BY pkg_id DESC |
|
|
)"_sql); |
|
|
)"_sql); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<pkg_id> pkg_db::all() const noexcept { |
|
|
std::vector<pkg_id> pkg_db::all() const noexcept { |
|
|
return nsql::exec_tuples<std::string, std::string>( |
|
|
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 // |
|
|
| neo::lref // |
|
|
| ranges::views::transform(pair_to_pkg_id) // |
|
|
| ranges::views::transform(pair_to_pkg_id) // |
|
|
| ranges::to_vector; |
|
|
| ranges::to_vector; |
|
|
|
|
|
|
|
|
_stmt_cache( |
|
|
_stmt_cache( |
|
|
R"( |
|
|
R"( |
|
|
SELECT name, version |
|
|
SELECT name, version |
|
|
FROM dds_cat_pkgs |
|
|
|
|
|
|
|
|
FROM dds_pkgs |
|
|
WHERE name = ? |
|
|
WHERE name = ? |
|
|
ORDER BY pkg_id DESC |
|
|
ORDER BY pkg_id DESC |
|
|
)"_sql), |
|
|
)"_sql), |
|
|
|
|
|
|
|
|
R"( |
|
|
R"( |
|
|
WITH this_pkg_id AS ( |
|
|
WITH this_pkg_id AS ( |
|
|
SELECT pkg_id |
|
|
SELECT pkg_id |
|
|
FROM dds_cat_pkgs |
|
|
|
|
|
|
|
|
FROM dds_pkgs |
|
|
WHERE name = ? AND version = ? |
|
|
WHERE name = ? AND version = ? |
|
|
) |
|
|
) |
|
|
SELECT dep_name, low, high |
|
|
SELECT dep_name, low, high |
|
|
FROM dds_cat_pkg_deps |
|
|
|
|
|
|
|
|
FROM dds_pkg_deps |
|
|
WHERE pkg_id IN this_pkg_id |
|
|
WHERE pkg_id IN this_pkg_id |
|
|
ORDER BY dep_name |
|
|
ORDER BY dep_name |
|
|
)"_sql), |
|
|
)"_sql), |