Skip to content

Commit b12c5c9

Browse files
committed
Fix the database on Postgres
1 parent 074a1b9 commit b12c5c9

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

libs/limhamn

src/database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void ff::setup_database(database& database) {
7373
// id: the post id
7474
// identifier: the post identifier
7575
// json: the json of the post (including content, author, etc.)
76-
if (!database.exec("CREATE TABLE IF NOT EXISTS posts (" + primary + ", identifier INTEGER NOT NULL, json TEXT NOT NULL);")) {
76+
if (!database.exec("CREATE TABLE IF NOT EXISTS posts (" + primary + ", identifier TEXT NOT NULL, json TEXT NOT NULL);")) {
7777
throw std::runtime_error{"Error creating the posts table."};
7878
}
7979

src/ff.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ void ff::start_server() {
216216
settings.psql_password,
217217
settings.psql_database,
218218
settings.psql_port);
219+
220+
#ifdef FF_DEBUG
221+
ff::logger.write_to_log(limhamn::logger::type::notice, "PostgreSQL database opened with host: " + settings.psql_host + ", username: " + settings.psql_username + ", password: " + settings.psql_password + ", database: " + settings.psql_database + "\n");
222+
#endif
219223
#endif
220224
} else {
221225
#ifdef FF_ENABLE_SQLITE
@@ -453,6 +457,10 @@ void ff::start_server() {
453457
ff::fatal = true;
454458
}
455459

460+
if (std::string(e.what()).find("Error creating the ") != std::string::npos) {
461+
ff::fatal = true;
462+
}
463+
456464
if (ff::fatal) {
457465
ff::logger.write_to_log(limhamn::logger::type::error, "The last error was too severe to recover, and the server will now halt.\n");
458466
std::exit(EXIT_FAILURE);

src/post_handlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ limhamn::http::server::response ff::try_upload_post(const limhamn::http::server:
253253

254254
ff::logger.write_to_log(limhamn::logger::type::notice, "Inserting post with ID: " + post_id + " into the database.\n");
255255

256-
db.exec("INSERT INTO posts (identifier, json) VALUES (?, ?)", post_id, db_json.dump());
256+
db.exec("INSERT INTO posts (identifier, json) VALUES (?, ?);", post_id, db_json.dump());
257257

258258
ff::logger.write_to_log(limhamn::logger::type::notice, "Post with ID: " + post_id + " inserted into the database.\n");
259259

0 commit comments

Comments
 (0)