Skip to content

Commit f285538

Browse files
committed
history DB: Add "persistence" column
For rpm-software-management/dnf#2196. The `persistence` column is a TransactionPersistence enum, currently it can either be UNKNOWN, PERSIST, or TRANSIENT.
1 parent 416c6f1 commit f285538

File tree

9 files changed

+35
-2
lines changed

9 files changed

+35
-2
lines changed

libdnf/transaction/Swdb.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ Swdb::setReleasever(std::string value)
385385
transactionInProgress->setReleasever(value);
386386
}
387387

388+
void
389+
Swdb::setPersistence(TransactionPersistence persistence)
390+
{
391+
if (!transactionInProgress) {
392+
throw std::logic_error(_("Not in progress"));
393+
}
394+
transactionInProgress->setPersistence(persistence);
395+
}
388396

389397
void
390398
Swdb::addConsoleOutputLine(int fileDescriptor, std::string line)

libdnf/transaction/Swdb.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct Swdb {
114114

115115
// misc
116116
void setReleasever(std::string value);
117+
void setPersistence(TransactionPersistence value);
117118
void addConsoleOutputLine(int fileDescriptor, std::string line);
118119

119120
/**

libdnf/transaction/Transaction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Transaction::dbSelect(int64_t pk)
8282
" releasever, "
8383
" user_id, "
8484
" cmdline, "
85+
" persistence, "
8586
" state, "
8687
" comment "
8788
"FROM "
@@ -100,6 +101,7 @@ Transaction::dbSelect(int64_t pk)
100101
releasever = query.get< std::string >("releasever");
101102
userId = query.get< uint32_t >("user_id");
102103
cmdline = query.get< std::string >("cmdline");
104+
persistence = static_cast<TransactionPersistence>(query.get<int>("persistence"));
103105
state = static_cast< TransactionState >(query.get< int >("state"));
104106
comment = query.get< std::string >("comment");
105107
}

libdnf/transaction/Transaction.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class Transaction {
5555
const std::string &getReleasever() const noexcept { return releasever; }
5656
uint32_t getUserId() const noexcept { return userId; }
5757
const std::string &getCmdline() const noexcept { return cmdline; }
58+
TransactionPersistence getPersistence() const noexcept { return persistence; }
59+
5860
TransactionState getState() const noexcept { return state; }
5961
const std::string &getComment() const noexcept { return comment; }
6062

@@ -79,6 +81,7 @@ class Transaction {
7981
std::string releasever;
8082
uint32_t userId = 0;
8183
std::string cmdline;
84+
TransactionPersistence persistence = TransactionPersistence::UNKNOWN;
8285
TransactionState state = TransactionState::UNKNOWN;
8386
std::string comment;
8487
};

libdnf/transaction/Transformer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static const char * const sql_migrate_tables_1_2 =
5353
#include "sql/migrate_tables_1_2.sql"
5454
;
5555

56+
static const char * const sql_migrate_tables_1_3 =
57+
#include "sql/migrate_tables_1_3.sql"
58+
;
59+
5660
void
5761
Transformer::createDatabase(SQLite3Ptr conn)
5862
{
@@ -71,6 +75,9 @@ Transformer::migrateSchema(SQLite3Ptr conn)
7175
if (schemaVersion == "1.1") {
7276
conn->exec(sql_migrate_tables_1_2);
7377
}
78+
if (schemaVersion == "1.2") {
79+
conn->exec(sql_migrate_tables_1_3);
80+
}
7481
}
7582
else {
7683
throw Exception(_("Database Corrupted: no row 'version' in table 'config'"));

libdnf/transaction/Types.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ enum class TransactionItemAction : int {
5656
REASON_CHANGE = 11 // a package was kept on the system but it's reason has changed
5757
};
5858

59+
enum class TransactionPersistence : int {
60+
UNKNOWN = 0,
61+
PERSIST = 1,
62+
TRANSIENT = 2,
63+
};
64+
5965
} // namespace libdnf
6066
/*
6167
Install

libdnf/transaction/private/Transaction.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ swdb_private::Transaction::dbInsert()
7676
" releasever, "
7777
" user_id, "
7878
" cmdline, "
79+
" persistence, "
7980
" state, "
8081
" comment, "
8182
" id "
8283
" ) "
8384
"VALUES "
84-
" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
85+
" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
8586
SQLite3::Statement query(*conn.get(), sql);
8687
query.bindv(getDtBegin(),
8788
getDtEnd(),
@@ -90,10 +91,11 @@ swdb_private::Transaction::dbInsert()
9091
getReleasever(),
9192
getUserId(),
9293
getCmdline(),
94+
static_cast<int>(getPersistence()),
9395
static_cast< int >(getState()),
9496
getComment());
9597
if (getId() > 0) {
96-
query.bind(9, getId());
98+
query.bind(10, getId());
9799
}
98100
query.step();
99101
setId(conn->lastInsertRowID());
@@ -138,6 +140,7 @@ swdb_private::Transaction::dbUpdate()
138140
" releasever=?, "
139141
" user_id=?, "
140142
" cmdline=?, "
143+
" persistence=?, "
141144
" state=?, "
142145
" comment=? "
143146
"WHERE "
@@ -150,6 +153,7 @@ swdb_private::Transaction::dbUpdate()
150153
getReleasever(),
151154
getUserId(),
152155
getCmdline(),
156+
static_cast<int>(getPersistence()),
153157
static_cast< int >(getState()),
154158
getComment(),
155159
getId());

libdnf/transaction/private/Transaction.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Transaction : public libdnf::Transaction {
4242
void setReleasever(const std::string &value) { releasever = value; }
4343
void setUserId(uint32_t value) { userId = value; }
4444
void setCmdline(const std::string &value) { cmdline = value; }
45+
void setPersistence(TransactionPersistence value) { persistence = value; }
4546
void setState(TransactionState value) { state = value; }
4647
void setComment(const std::string &value) { comment = value; }
4748

libdnf/transaction/sql/create_tables.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ R"**(
88
releasever TEXT NOT NULL, /* var: $releasever */
99
user_id INTEGER NOT NULL, /* user ID (UID) */
1010
cmdline TEXT, /* recorded command line (program, options, arguments) */
11+
persistence INTEGER DEFAULT 0 /* transaction persistence: unknown, persist, or transient
1112
state INTEGER NOT NULL /* (enum) */
1213
);
1314
CREATE TABLE repo (

0 commit comments

Comments
 (0)