Skip to content

Commit 7269c8f

Browse files
committed
Add scripts to control dev environment
1 parent c796160 commit 7269c8f

File tree

14 files changed

+369
-4
lines changed

14 files changed

+369
-4
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203, W503, E731, E722
4+
per-file-ignores = __init__.py:F401

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ poetry build pypgstac
2020
pip install dist/pypgstac-[version]-py3-none-any.whl
2121
```
2222

23-
# Migrations
23+
## Migrations
2424
To install the latest version of pgstac on an empty database, you can directly load the primary source code.
2525
```
2626
psql -f pgstac.sql
@@ -33,20 +33,20 @@ For each new version of PGStac, two migrations should be added to pypgstac/pypgs
3333
- pgstac.[version].sql (equivalent to `cat sql/*.sql > migration.sql && echo "insert into migrations (versions) VALUES ('[version]')" >> migration.sql)
3434
- pgstac.[version].[fromversion].sql (Migration to move from existing version to new version, can be created by hand or using the makemigration.sh tool below)
3535

36-
## Running Migrations
36+
### Running Migrations
3737
Migrations can be installed by either directly running the appropriate migration sql file for from and target PGStac versions:
3838
`psql -f pypgstac/pypgstac/migrations/pgstac.0.1.8.sql`
3939

4040
Or by using pypgstac:
4141
`pypgstac migrate`
4242

43-
## Creating Migrations Using Schema Diff
43+
### Creating Migrations Using Schema Diff
4444
To create a migration from a previous version of pgstac you can calculate the migration from the running instance of pgstac using the makemigration.sh command. This will use docker to copy the schema of the existing database and the new sql into new docker databases and create/test the migration between the two.
4545
```
4646
makemigration.sh postgresql://myuser:mypassword@myhost:myport/mydatabase
4747
```
4848

49-
# Bulk Data Loading
49+
## Bulk Data Loading
5050
A python utility is included which allows to load data from any source openable by smart-open using python in a memory efficient streaming manner using PostgreSQL copy. There are options for collections and items and can be used either as a command line or a library.
5151

5252
To load an ndjson of items directly using copy (will fail on any duplicate ids but is the fastest option to load new data you know will not conflict)
@@ -63,3 +63,41 @@ To upsert any records, adding anything new and replacing anything with the same
6363
```
6464
pypgstac load items --method upsert
6565
```
66+
67+
## Development
68+
69+
PGStac uses a dockerized development environment. You can set this up using:
70+
71+
```bash
72+
scripts/setup
73+
```
74+
75+
To bring up the development database:
76+
```
77+
scripts/server
78+
```
79+
80+
To run tests, use:
81+
```bash
82+
scripts/test
83+
```
84+
85+
To rebuild docker images:
86+
```bash
87+
scripts/update
88+
```
89+
90+
To drop into a console, use
91+
```bash
92+
scripts/console
93+
```
94+
95+
To drop into a psql console on the database container, use:
96+
```bash
97+
scripts/console --db
98+
```
99+
100+
To run migrations on the development database, use
101+
```bash
102+
scripts/migrate
103+
```

mypy.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[mypy]
2+
ignore_missing_imports = True
3+
disallow_untyped_defs = True
4+
namespace_packages = True

scripts/bin/format

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ "${CI}" ]]; then
6+
set -x
7+
fi
8+
9+
function usage() {
10+
echo -n \
11+
"Usage: $(basename "$0")
12+
Format code.
13+
14+
This scripts is meant to be run inside the dev container.
15+
16+
"
17+
}
18+
19+
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
20+
echo "Formatting pypgstac..."
21+
black pypgstac/pypgstac
22+
black pypgstac/tests
23+
fi

scripts/bin/test

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ "${CI}" ]]; then
6+
set -x
7+
fi
8+
9+
function usage() {
10+
echo -n \
11+
"Usage: $(basename "$0")
12+
Runs tests for the project.
13+
14+
This scripts is meant to be run inside the dev container.
15+
16+
"
17+
}
18+
19+
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
20+
21+
echo "Running mypy..."
22+
mypy pypgstac/pypgstac pypgstac/tests
23+
24+
echo "Running black..."
25+
black --check pypgstac/pypgstac pypgstac/tests
26+
27+
echo "Running flake8..."
28+
flake8 pypgstac/pypgstac pypgstac/tests
29+
30+
echo "Running unit tests..."
31+
python -m unittest discover pypgstac/tests
32+
33+
fi

scripts/cibuild

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ "${CI}" ]]; then
6+
set -x
7+
fi
8+
9+
function usage() {
10+
echo -n \
11+
"Usage: $(basename "$0")
12+
CI build for this project.
13+
"
14+
}
15+
16+
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
17+
scripts/setup
18+
scripts/test
19+
fi

scripts/cipublish

Whitespace-only changes.

scripts/console

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ "${CI}" ]]; then
6+
set -x
7+
fi
8+
9+
function usage() {
10+
echo -n \
11+
"Usage: $(basename "$0") [--db]
12+
Start a console in the dev container
13+
14+
--db: Instead, start a psql console in the database container.
15+
"
16+
}
17+
18+
while [[ "$#" > 0 ]]; do case $1 in
19+
--db)
20+
DB_CONSOLE=1
21+
shift
22+
;;
23+
*)
24+
usage "Unknown parameter passed: $1"
25+
shift
26+
shift
27+
;;
28+
esac; done
29+
30+
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
31+
32+
if [[ "${DB_CONSOLE}" ]]; then
33+
scripts/server --detach
34+
35+
docker-compose \
36+
-f docker-compose.yml \
37+
run --rm \
38+
database \
39+
psql postgres://username:password@database:5432/postgis
40+
41+
exit 0
42+
fi
43+
44+
# Run database migrations
45+
docker-compose \
46+
-f docker-compose.yml \
47+
run --rm dev \
48+
/bin/bash
49+
50+
fi

scripts/format

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ "${CI}" ]]; then
6+
set -x
7+
fi
8+
9+
function usage() {
10+
echo -n \
11+
"Usage: $(basename "$0")
12+
Format code in this project
13+
14+
"
15+
}
16+
17+
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
18+
docker-compose \
19+
run --rm \
20+
dev scripts/bin/format;
21+
fi

scripts/migrate

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ "${CI}" ]]; then
6+
set -x
7+
fi
8+
9+
function usage() {
10+
echo -n \
11+
"Usage: $(basename "$0")
12+
Run migrations against the development database.
13+
"
14+
}
15+
16+
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
17+
18+
# Run database migrations
19+
docker-compose \
20+
-f docker-compose.yml \
21+
run --rm dev \
22+
bash -c "pypgstac pgready && pypgstac migrate"
23+
24+
fi

0 commit comments

Comments
 (0)