Skip to content
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

Draft: Development PR #1

Merged
merged 14 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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: 0 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Docker Image CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

Expand Down
65 changes: 47 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
#building bot
FROM gcc:latest as build

RUN apt-get update && \
apt-get install -y \
libboost-dev libboost-system-dev \
cmake


RUN apt-get install g++ make binutils libboost-system-dev libssl-dev zlib1g-dev libcurl4-openssl-dev

#installing tgbot lib
Hyperb0rean marked this conversation as resolved.
Show resolved Hide resolved
RUN git clone https://github.com/reo7sp/tgbot-cpp
RUN cmake ./tgbot-cpp
RUN cd tgbot-cpp
RUN make -j4
RUN make install
RUN cd ..

RUN apt-get install -y libpq-dev libpqxx-dev

# RUN git clone https://github.com/jtv/libpqxx.git
# RUN cd libpqxx && \
# ./configure --disable-shared && \
# make && \
# make install && \
# cd ..
#installing libpqxx
RUN apt-get install -y libpq-dev libpqxx-dev

RUN git clone https://github.com/jtv/libpqxx.git \
--branch 6.4 --depth 1 \
Expand All @@ -35,25 +33,23 @@ RUN git clone https://github.com/jtv/libpqxx.git \
-DCMAKE_MODULE_PATH=/usr/src/libpqxx-r6.4/cmake .. \
&& make && make install && ldconfig /usr/local/lib


RUN ls /usr/local/lib/

#building sources
ADD ./src /app/src
WORKDIR /app/build

RUN cmake ../src && \
cmake --build .


#run configuration
FROM ubuntu:latest


#installing base dependencies
RUN apt-get -y update && \
apt-get install -y software-properties-common && \
apt-get -y update

RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get -y update && \
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
RUN apt-get -y update && \
apt-get install -y gcc-4.9 && \
apt-get upgrade -y libstdc++6

Expand All @@ -66,6 +62,7 @@ RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git make cmake g++

#installing libpqxx
RUN apt-get install -y libpq-dev libpqxx-dev


Expand All @@ -81,13 +78,45 @@ RUN git clone https://github.com/jtv/libpqxx.git \
-DCMAKE_MODULE_PATH=/usr/src/libpqxx-r6.4/cmake .. \
&& make && make install && ldconfig /usr/local/lib

RUN find / -name libpq.so.5
#installing postgresql
RUN apt-get install -y locales locales-all
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
RUN localedef -i en_GB -c -f UTF-8 -A /usr/share/locale/locale.alias en_GB.UTF-8
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
RUN apt-get -y install wget ca-certificates && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' &&\
apt-get -y update
RUN apt-get -y install postgresql postgresql-contrib

RUN ls -la /etc/init.d/
RUN /etc/init.d/postgresql start
RUN echo "host all all 0.0.0.0/0 md5" >>/etc/postgresql/16/main/pg_hba.conf && \
echo "listen_addresses='*'" >> /etc/postgresql/16/main/postgresql.conf
RUN /etc/init.d/postgresql restart

WORKDIR /app
COPY --from=build /app/build/database .
COPY --from=build /app/src .
RUN ls -la
RUN chmod +x ./run.sh

#changing rights
RUN groupadd -r sample && useradd -r -g sample sample
USER sample
USER postgres
RUN pg_lsclusters
ENV PGPASSWORD=postgres

WORKDIR /app
RUN pg_ctlcluster 16 main start && \
createdb mintdb
RUN pg_lsclusters

COPY --from=build /app/build/database .
#running

EXPOSE 5432

ENTRYPOINT ["./database"]
ENTRYPOINT ["./run.sh"]
# RUN pg_ctlcluster 16 main start
4 changes: 1 addition & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ if (CURL_FOUND)
endif()
set(SOURCES
main.cpp
util.h
ddl.h
ddl.cpp)
util.h)
add_executable(database ${SOURCES})
target_include_directories(database PRIVATE ".")
target_link_libraries(database /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES} libpqxx::pqxx_shared PostgreSQL::PostgreSQL)
25 changes: 3 additions & 22 deletions src/cw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ create table crops (
brain_damage real check (brain_damage > -200 and brain_damage < 200)
);


create table estate (
estate_id serial primary key,
name text not null,
Expand All @@ -16,23 +15,20 @@ create table estate (
rent real not null check (rent > 0)
);


create table plantation (
plantation_id serial primary key,
capacity integer not null,
revenue real not null,
estate_id integer references estate(estate_id)
);


create table crops_plantations (
crop_id integer references crops(crop_id),
plantation_id integer references plantation(plantation_id),
counter integer check (counter >= 0),
primary key(crop_id, plantation_id)
);


create table worker (
worker_id serial primary key,
plantation_id integer references plantation(plantation_id),
Expand All @@ -41,7 +37,6 @@ create table worker (
profession text not null
);


create table worker_family_member (
worker_fm_id serial primary key,
worker_id integer references worker(worker_id),
Expand All @@ -50,31 +45,27 @@ create table worker_family_member (
adress text not null
);


create table landlord (
landlord_id serial primary key,
estate_id integer references estate(estate_id),
name text not null,
capital real check (capital > 0)
);


create table evidence_info (
evidence_info_id serial primary key,
landlord_id integer references landlord(landlord_id),
description text,
worth real check (worth >= 20 AND worth <= 100)
);


create table manager (
manager_id serial primary key,
plantation_id integer references plantation(plantation_id),
name text not null,
salary real check (salary >=100)
);


create table client (
client_id serial primary key,
manager_id integer references manager(manager_id),
Expand All @@ -84,26 +75,21 @@ create table client (
brain_resource real
);


create table client_family_member(
client_fm serial primary key,
client_id integer references client(client_id),
adress text not null,
email text unique check (email ~ '^[a-zA-Z0-9.!#$%&''*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$')
);


create or replace function cell(id_client integer, id_crop integer, amount integer)
create or replace function sell(id_client integer, id_crop integer, amount integer)
returns void as $$
begin
update crops_plantations set counter = counter - amount where crop_id = id_crop and counter >= amount;
update client set brain_resource = brain_resource - (select brain_damage from crops where crop_id = id_crop) where client_id = id_client;
end;
$$ language plpgsql;




create or replace function killer_f()
returns trigger as $$
begin
Expand All @@ -117,13 +103,10 @@ returns trigger as $$
end;
$$ language plpgsql;


create trigger killer_t
before insert or update on client
for each row execute function killer_f();



create or replace function plant_capacity_checker_f()
returns trigger as $$
begin
Expand All @@ -141,12 +124,10 @@ returns trigger as $$
end;
$$ language plpgsql;


create trigger plant_capacity_checker_t
before insert or update on crops_plantations
for each row execute function plant_capacity_checker_f();


create or replace function enum_crops_on_plantation(name text)
returns setof text as $$
begin
Expand All @@ -157,7 +138,6 @@ returns setof text as $$
end;
$$ language plpgsql;


create or replace function get_friends_email(name text)
returns setof text as $$
begin
Expand All @@ -167,6 +147,7 @@ returns setof text as $$
$$ language plpgsql;

create index crop_id_i on crops using hash(crop_id);

create index client_id_i on client using hash(client_id);
create index brain_damage_i on crops using btree(brain_damage);

create index brain_damage_i on crops using btree(brain_damage);
4 changes: 0 additions & 4 deletions src/ddl.cpp

This file was deleted.

4 changes: 0 additions & 4 deletions src/ddl.h

This file was deleted.

Loading