Skip to content

[Feature] Add MIT license #2

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

Merged
merged 26 commits into from
Jan 10, 2025
Merged
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
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=

PGADMIN_DEFAULT_EMAIL=
PGADMIN_DEFAULT_PASSWORD=

POSTGRESQL_HOST=postgres
POSTGRESQL_PORT=5432
10 changes: 10 additions & 0 deletions .github/workflows/lint-yaml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Run yaml linter
on: [push] # yamllint disable-line rule:truthy
jobs:
lintAllTheThings:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024-2025 Kyrylo Kotelevets

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
132 changes: 131 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,131 @@
# postgres-worksheet
[![Docker](https://img.shields.io/badge/Docker-%230db7ed.svg?logo=docker&logoColor=white)](https://www.docker.com/)
[![Docker Compose](https://img.shields.io/badge/Docker%20Compose-%230db7ed.svg?logo=docker&logoColor=white)](https://docs.docker.com/compose/)
[![PostgreSQL](https://img.shields.io/badge/PostgreSQL-%23316192.svg?logo=postgresql&logoColor=white)](https://www.postgresql.org/)
[![PgBouncer](https://img.shields.io/badge/PgBouncer-%23316192.svg?logo=postgresql&logoColor=white)](https://www.pgbouncer.org/)
[![pgAdmin](https://img.shields.io/badge/pgAdmin-%23316192.svg?logo=postgresql&logoColor=white)](https://www.pgadmin.org/)
<br>
![OS](https://img.shields.io/badge/OS-Linux%2C%20Windows%2C%20MacOS-0078D4)
![CPU](https://img.shields.io/badge/CPU-x86%2C%20x64%2C%20ARM%2C%20ARM64-FF8C00)
![GitHub last commit](https://img.shields.io/github/last-commit/Kyrylo-Ktl/advent-of-code)

# Postgres worksheet

This project provides a preconfigured environment for working with PostgreSQL database infrastructure using Docker Compose.
It includes the following services:

+ [PostgreSQL](https://www.postgresql.org/) - the primary database service with custom configuration;
+ [PgBouncer](https://www.pgbouncer.org/) - a lightweight connection pooler for PostgreSQL;
+ [pgAdmin](https://www.pgadmin.org/) - a web-based PostgreSQL database management tool.


## Architecture

### Components

![Architecture diagram](https://github.com/user-attachments/assets/d20e472b-6c2d-4561-b31c-f8cd13c6a020)

### Features

This preconfigured project environment provides the following features:

+ **PostgreSQL**
+ Custom configuration through a mounted `postgresql.conf` file;
+ Automated data model creation with scripts from mounted `docker-entrypoint-initdb.d` folder;
+ Persistent data model storage via volumes;
+ Resources optimal setup - CPU (2) and memory (4G);
+ Health checks to ensure the database is ready before other services start;
+ Isolated in the internal Docker network;


+ **PgBouncer**;
+ Connection pooling for database to optimize resource usage;
+ SCRAM-SHA-256 authentication for secure connections;
+ Resources optimal setup - CPU (0.5) and memory (1G);
+ Accessible via the external Docker network;


+ **pgAdmin**;
+ Persistent configurations storage via volumes;
+ Resources optimal setup - CPU (0.5) and memory (1G);

### Data model

In this project, an e-commerce data model is implemented by default to manage customers, products and related orders.
The data model is created automatically when the database is first started and is populated with synthetic records:

+ Customers - [table](config/postgresql/scripts/01-create-0001-customers-table.sql) with information about 10,000 [randomly generated](config/postgresql/scripts/02-fill-0001-customers-table.sql) customers;
+ Products - [table](config/postgresql/scripts/01-create-0002-products-table.sql) with information about 100,000 [randomly generated](config/postgresql/scripts/02-fill-0002-products-table.sql) products;
+ Orders - [table](config/postgresql/scripts/01-create-0003-orders-table.sql) with information about 1,000,000 [randomly generated](config/postgresql/scripts/02-fill-0003-orders-table.sql) orders;

![postgres-worksheet-er](https://github.com/user-attachments/assets/dd8c7574-8d83-4bc8-b134-2d17b6686fa3)


## Usage

### Prerequisites

Make sure you have [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed on your machine.

### Setup

Project uses an `.env` file with environment variables to manage configurations and tool settings.
The file should be created using the `.env.example` file provided in the root directory using the following command:


```shell
cp .env.example .env
```

And then filled with the corresponding values:

```dotenv
POSTGRES_DB=<database-name>
POSTGRES_USER=<postgres-user>
POSTGRES_PASSWORD=<postgres-password>

PGADMIN_DEFAULT_EMAIL=<pgadmin-email>
PGADMIN_DEFAULT_PASSWORD=<pgadmin-password>

POSTGRESQL_HOST=postgres
POSTGRESQL_PORT=5432
```

### Run

Build and start the database services infrastructure by running:

```shell
docker compose up -d --build
```

> [!NOTE]
> First run will take some time, as all necessary docker images will be loaded and the data model will be created and populated with synthetic records.

Check that all services are successfully started by running:

```shell
docker compose ps
```

To stop all running services, execute:

```shell
docker compose down
```

> [!NOTE]
> After stopping the services, the data will not be deleted and will be available when the services are restarted.

If you want to stop the services and remove all associated data use:

```shell
docker compose down --volumes
```

> [!WARNING]
> This command deletes all service data (e.g. data model, stored passwords and configurations).


## License

This project is licensed under the [MIT License](LICENSE).
Loading
Loading