Skip to content

history DB: Add "persistence" column #1706

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

Open
wants to merge 3 commits into
base: dnf-4-master
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
2 changes: 1 addition & 1 deletion VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set (DEFAULT_LIBDNF_MAJOR_VERSION 0)
set (DEFAULT_LIBDNF_MINOR_VERSION 74)
set (DEFAULT_LIBDNF_MINOR_VERSION 75)
set (DEFAULT_LIBDNF_MICRO_VERSION 0)

if(DEFINED LIBDNF_MAJOR_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion libdnf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%global dnf_conflict 4.11.0
%global swig_version 3.0.12
%global libdnf_major_version 0
%global libdnf_minor_version 74
%global libdnf_minor_version 75
%global libdnf_micro_version 0

%define __cmake_in_source_build 1
Expand Down
10 changes: 10 additions & 0 deletions libdnf/transaction/MergedTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ MergedTransaction::listCmdlines() const
return cmdLines;
}

std::vector< TransactionPersistence >
MergedTransaction::listPersistences() const
{
std::vector< TransactionPersistence > persistences;
for (auto t : transactions) {
persistences.push_back(t->getPersistence());
}
return persistences;
}

std::vector< TransactionState >
MergedTransaction::listStates() const
{
Expand Down
1 change: 1 addition & 0 deletions libdnf/transaction/MergedTransaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MergedTransaction {
std::vector< int64_t > listIds() const;
std::vector< uint32_t > listUserIds() const;
std::vector< std::string > listCmdlines() const;
std::vector< TransactionPersistence > listPersistences() const;
std::vector< TransactionState > listStates() const;
std::vector< std::string > listReleasevers() const;
std::vector< std::string > listComments() const;
Expand Down
8 changes: 8 additions & 0 deletions libdnf/transaction/Swdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ Swdb::setReleasever(std::string value)
transactionInProgress->setReleasever(value);
}

void
Swdb::setPersistence(TransactionPersistence persistence)
{
if (!transactionInProgress) {
throw std::logic_error(_("Not in progress"));
}
transactionInProgress->setPersistence(persistence);
}

void
Swdb::addConsoleOutputLine(int fileDescriptor, std::string line)
Expand Down
1 change: 1 addition & 0 deletions libdnf/transaction/Swdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct Swdb {

// misc
void setReleasever(std::string value);
void setPersistence(TransactionPersistence value);
void addConsoleOutputLine(int fileDescriptor, std::string line);

/**
Expand Down
2 changes: 2 additions & 0 deletions libdnf/transaction/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Transaction::dbSelect(int64_t pk)
" releasever, "
" user_id, "
" cmdline, "
" persistence, "
" state, "
" comment "
"FROM "
Expand All @@ -100,6 +101,7 @@ Transaction::dbSelect(int64_t pk)
releasever = query.get< std::string >("releasever");
userId = query.get< uint32_t >("user_id");
cmdline = query.get< std::string >("cmdline");
persistence = static_cast<TransactionPersistence>(query.get<int>("persistence"));
state = static_cast< TransactionState >(query.get< int >("state"));
comment = query.get< std::string >("comment");
}
Expand Down
3 changes: 3 additions & 0 deletions libdnf/transaction/Transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Transaction {
const std::string &getReleasever() const noexcept { return releasever; }
uint32_t getUserId() const noexcept { return userId; }
const std::string &getCmdline() const noexcept { return cmdline; }
TransactionPersistence getPersistence() const noexcept { return persistence; }

TransactionState getState() const noexcept { return state; }
const std::string &getComment() const noexcept { return comment; }

Expand All @@ -79,6 +81,7 @@ class Transaction {
std::string releasever;
uint32_t userId = 0;
std::string cmdline;
TransactionPersistence persistence = TransactionPersistence::UNKNOWN;
TransactionState state = TransactionState::UNKNOWN;
std::string comment;
};
Expand Down
7 changes: 7 additions & 0 deletions libdnf/transaction/Transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ static const char * const sql_migrate_tables_1_2 =
#include "sql/migrate_tables_1_2.sql"
;

static const char * const sql_migrate_tables_1_3 =
#include "sql/migrate_tables_1_3.sql"
;

void
Transformer::createDatabase(SQLite3Ptr conn)
{
Expand All @@ -70,6 +74,9 @@ Transformer::migrateSchema(SQLite3Ptr conn)

if (schemaVersion == "1.1") {
conn->exec(sql_migrate_tables_1_2);
conn->exec(sql_migrate_tables_1_3);
} else if (schemaVersion == "1.2") {
conn->exec(sql_migrate_tables_1_3);
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion libdnf/transaction/Transformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Transformer {
static void migrateSchema(SQLite3Ptr conn);

static TransactionItemReason getReason(const std::string &reason);
static const char *getVersion() noexcept { return "1.2"; }
static const char *getVersion() noexcept { return "1.3"; }

protected:
void transformTrans(SQLite3Ptr swdb, SQLite3Ptr history);
Expand Down
6 changes: 6 additions & 0 deletions libdnf/transaction/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ enum class TransactionItemAction : int {
REASON_CHANGE = 11 // a package was kept on the system but it's reason has changed
};

enum class TransactionPersistence : int {
UNKNOWN = 0,
PERSIST = 1,
TRANSIENT = 2,
};

} // namespace libdnf
/*
Install
Expand Down
8 changes: 6 additions & 2 deletions libdnf/transaction/private/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ swdb_private::Transaction::dbInsert()
" releasever, "
" user_id, "
" cmdline, "
" persistence, "
" state, "
" comment, "
" id "
" ) "
"VALUES "
" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
SQLite3::Statement query(*conn.get(), sql);
query.bindv(getDtBegin(),
getDtEnd(),
Expand All @@ -90,10 +91,11 @@ swdb_private::Transaction::dbInsert()
getReleasever(),
getUserId(),
getCmdline(),
static_cast<int>(getPersistence()),
static_cast< int >(getState()),
getComment());
if (getId() > 0) {
query.bind(9, getId());
query.bind(10, getId());
}
query.step();
setId(conn->lastInsertRowID());
Expand Down Expand Up @@ -138,6 +140,7 @@ swdb_private::Transaction::dbUpdate()
" releasever=?, "
" user_id=?, "
" cmdline=?, "
" persistence=?, "
" state=?, "
" comment=? "
"WHERE "
Expand All @@ -150,6 +153,7 @@ swdb_private::Transaction::dbUpdate()
getReleasever(),
getUserId(),
getCmdline(),
static_cast<int>(getPersistence()),
static_cast< int >(getState()),
getComment(),
getId());
Expand Down
1 change: 1 addition & 0 deletions libdnf/transaction/private/Transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Transaction : public libdnf::Transaction {
void setReleasever(const std::string &value) { releasever = value; }
void setUserId(uint32_t value) { userId = value; }
void setCmdline(const std::string &value) { cmdline = value; }
void setPersistence(TransactionPersistence value) { persistence = value; }
void setState(TransactionState value) { state = value; }
void setComment(const std::string &value) { comment = value; }

Expand Down
9 changes: 9 additions & 0 deletions libdnf/transaction/sql/migrate_tables_1_3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
R"**(
BEGIN TRANSACTION;
ALTER TABLE trans
ADD persistence INTEGER DEFAULT 0;
UPDATE config
SET value = '1.3'
WHERE key = 'version';
COMMIT;
)**"
Loading