Initial commit
This commit is contained in:
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) [year] [fullname]
|
||||
|
||||
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.
|
||||
50
README.md
Normal file
50
README.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# puzzle_db
|
||||
|
||||
## Description
|
||||
Simple docker example of Postgresql, PgAdmin, and imported data from a .csv.
|
||||
The .csv is from the [Lichess Puzzle Database](https://database.lichess.org/#puzzles)
|
||||
but is truncated for practicality.
|
||||
|
||||
---
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [Features](#features)
|
||||
* [Todos](#todos)
|
||||
* [Usage](#usage)
|
||||
* [Acknowledgments](#acknowledgments)
|
||||
* [License](#license)
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- [x] PgAdmin Webportal
|
||||
- [x] Automatic server creation
|
||||
- [x] Automatic database / table creation
|
||||
|
||||
---
|
||||
|
||||
## Todos
|
||||
|
||||
* [ ] Add fastify container
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
---
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
[Tom Preston-Werner README Driven Development](https://tom.preston-werner.com/2010/08/23/readme-driven-development)<br>
|
||||
[Make a README](https://www.makeareadme.com/)<br>
|
||||
[Choose a LICENSE](https://choosealicense.com/)<br>
|
||||
[Lichess Puzzle Database](https://database.lichess.org/#puzzles)
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE] file for details.
|
||||
|
||||
5430
data/puzzles.csv
Executable file
5430
data/puzzles.csv
Executable file
File diff suppressed because one or more lines are too long
46
docker-compose.yaml
Normal file
46
docker-compose.yaml
Normal file
@@ -0,0 +1,46 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres
|
||||
hostname: postgreshost
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
- POSTGRES_DB=${POSTGRES_DB}
|
||||
ports:
|
||||
- ${POSTGRES_PORT}:5432
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql
|
||||
- ./init:/docker-entrypoint-initdb.d
|
||||
- ./data:/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
|
||||
pgadmin:
|
||||
image: dpage/pgadmin4
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
|
||||
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
|
||||
- POSTGRES_HOST=postgreshost
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
- POSTGRES_DB=${POSTGRES_DB}
|
||||
- PGADMIN_CONFIG_SERVER_MODE=False
|
||||
- PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED=False
|
||||
ports:
|
||||
- ${PGADMIN_PORT}:80
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
user: root
|
||||
volumes:
|
||||
- ./pgadmin/servers.json:/pgadmin4/servers.json
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
12
init/01-schema.sql
Normal file
12
init/01-schema.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE puzzles (
|
||||
PuzzleId TEXT PRIMARY KEY,
|
||||
FEN TEXT,
|
||||
Moves TEXT,
|
||||
Rating INTEGER,
|
||||
RatingDeviation INTEGER,
|
||||
Popularity INTEGER,
|
||||
NbPlays INTEGER,
|
||||
Themes TEXT,
|
||||
GameUrl TEXT,
|
||||
OpeningTags TEXT
|
||||
);
|
||||
11
init/02-import.sh
Executable file
11
init/02-import.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "Importing CSV into puzzles table..."
|
||||
|
||||
psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" <<EOF
|
||||
COPY puzzles(PuzzleId,FEN,Moves,Rating,RatingDeviation,Popularity,NbPlays,Themes,GameUrl,OpeningTags)
|
||||
FROM '/data/puzzles.csv'
|
||||
DELIMITER ','
|
||||
CSV HEADER;
|
||||
EOF
|
||||
5
init/03_add_pkey.sql
Normal file
5
init/03_add_pkey.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Drop the existing primary key
|
||||
ALTER TABLE puzzles DROP CONSTRAINT puzzles_pkey;
|
||||
|
||||
-- Add new auto-incrementing primary key while keeping PuzzleId
|
||||
ALTER TABLE puzzles ADD COLUMN pkey BIGSERIAL PRIMARY KEY;
|
||||
13
pgadmin/servers.json
Normal file
13
pgadmin/servers.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"Servers": {
|
||||
"1": {
|
||||
"Name": "Puzzles DB",
|
||||
"Group": "Servers",
|
||||
"Host": "postgreshost",
|
||||
"Port": 5432,
|
||||
"MaintenanceDB": "example_db",
|
||||
"Username": "example_user",
|
||||
"SSLMode": "prefer"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user