Skip to content

Commit

Permalink
Merge pull request #6 from sartim/develop
Browse files Browse the repository at this point in the history
Update tables & add docker-compose.yaml
  • Loading branch information
sartim authored Aug 5, 2024
2 parents 6479021 + 1ceae80 commit c863ece
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
15 changes: 15 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
web-server:
build:
context: .
dockerfile: Dockerfile
container_name: user-service:latest
environment:
- SECRET_KEY=${SECRET_KEY}
- DB_HOST=${DB_HOST}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
image: ragnarok:latest
command: /build/drogon_user_service --action=run-server
1 change: 0 additions & 1 deletion tables/BaseTable.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <drogon/drogon.h>
#include <pqxx/pqxx>

class BaseTable {

Expand Down
10 changes: 6 additions & 4 deletions tables/PermissionTable.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "PermissionTable.h"
#include <drogon/drogon.h>
#include <iostream>
#include <pqxx/pqxx>

using namespace pqxx;
using namespace std;
using namespace drogon;
using namespace drogon::orm;
Expand All @@ -21,8 +23,8 @@ void PermissionTable::create(const string &connectionString) {
"updated_at timestamp with time zone,"
"deleted_at timestamp with time zone"
")";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Created table " << PERMISSION_TABLE_NAME;
Expand All @@ -39,8 +41,8 @@ void PermissionTable::alter(const string &connectionString) {
void PermissionTable::_delete(const string &connectionString) {
try {
auto sql = "DROP TABLE IF EXISTS $1";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Dropped table " << PERMISSION_TABLE_NAME;
Expand Down
10 changes: 6 additions & 4 deletions tables/RolePermissionTable.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "RolePermissionTable.h"
#include <drogon/drogon.h>
#include <iostream>
#include <pqxx/pqxx>

using namespace pqxx;
using namespace std;
using namespace drogon;
using namespace drogon::orm;
Expand All @@ -19,8 +21,8 @@ void RolePermissionTable::create(const string &connectionString) {
"updated_at timestamp with time zone,"
"PRIMARY KEY (user_id, role_id)"
")";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Created table " << ROLE_PERMISSION_TABLE_NAME;
Expand All @@ -37,8 +39,8 @@ void RolePermissionTable::alter(const string &connectionString) {
void RolePermissionTable::_delete(const string &connectionString) {
try {
auto sql = "DROP TABLE IF EXISTS $1";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Dropped table " << ROLE_PERMISSION_TABLE_NAME;
Expand Down
10 changes: 6 additions & 4 deletions tables/RoleTable.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "RoleTable.h"
#include <drogon/drogon.h>
#include <iostream>
#include <pqxx/pqxx>

using namespace pqxx;
using namespace std;
using namespace drogon;
using namespace drogon::orm;
Expand All @@ -21,8 +23,8 @@ void RoleTable::create(const string &connectionString) {
"updated_at timestamp with time zone,"
"deleted_at timestamp with time zone"
")";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Created table " << ROLE_TABLE_NAME;
Expand All @@ -39,8 +41,8 @@ void RoleTable::alter(const string &connectionString) {
void RoleTable::_delete(const string &connectionString) {
try {
auto sql = "DROP TABLE IF EXISTS $1";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Dropped table " << ROLE_TABLE_NAME;
Expand Down
10 changes: 6 additions & 4 deletions tables/UserPermissionTable.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "UserPermissionTable.h"
#include <drogon/drogon.h>
#include <iostream>
#include <pqxx/pqxx>

using namespace pqxx;
using namespace std;
using namespace drogon;
using namespace drogon::orm;
Expand All @@ -19,8 +21,8 @@ void UserPermissionTable::create(const string &connectionString) {
"updated_at timestamp with time zone,"
"PRIMARY KEY (user_id, permission_id)"
")";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Created table " << USER_PERMISSION_TABLE_NAME;
Expand All @@ -37,8 +39,8 @@ void UserPermissionTable::alter(const string &connectionString) {
void UserPermissionTable::_delete(const string &connectionString) {
try {
auto sql = "DROP TABLE IF EXISTS $1";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Dropped table " << USER_PERMISSION_TABLE_NAME;
Expand Down
9 changes: 5 additions & 4 deletions tables/UserTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <pqxx/pqxx>

using namespace pqxx;
using namespace std;

const string USER_TABLE_NAME = "users";
Expand All @@ -20,8 +21,8 @@ void UserTable::create(const string &connectionString) {
"updated_at timestamp with time zone,"
"deleted_at timestamp with time zone"
")";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Created table " << USER_TABLE_NAME;
Expand All @@ -38,8 +39,8 @@ void UserTable::alter(const string &connectionString) {
void UserTable::_delete(const string &connectionString) {
try {
auto sql = "DROP TABLE IF EXISTS $1";
pqxx::connection client{connectionString};
pqxx::work txn{client};
connection client{connectionString};
work txn{client};
txn.exec(sql);
txn.commit();
LOG_DEBUG << "Dropped table " << USER_TABLE_NAME;
Expand Down

0 comments on commit c863ece

Please sign in to comment.