Skip to content

Commit 8d85be7

Browse files
authored
Migration Tooling / Release Process (#27)
* use poetry * add push to github docker registry * fix release.yml formatting error * add .dockerignore file * remove docker/make files that are not used anymore * split pypgstac code to migrate.py load.py to help organize, add migration path logic for multi-step incremental migrations * add pydocstyle comments * add new scripts to enable a staging process for sql migrations * use scripts/stageversion to add steps between all versions * use scripts/stageversion to add steps between all versions * Add documentation on release process to README
1 parent d89589e commit 8d85be7

23 files changed

+738
-667
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.envrc*
2+
*/dist/*
3+
*.pyc
4+
*.egg-info
5+
*.eggs
6+
venv/*
7+
*/.direnv/*

Makefile

Lines changed: 0 additions & 54 deletions
This file was deleted.

README.md

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,46 @@ cd pypgstac
1919
poetry build pypgstac
2020
pip install dist/pypgstac-[version]-py3-none-any.whl
2121
```
22+
PyPGStac will get the database connection settings from the standard PG environment variables. It can also take a DSN database url "postgresql://..." via the --dsn flag.
23+
- PGHOST
24+
- PGPORT
25+
- PGUSER
26+
- PGDATABASE
27+
- PGPASSWORD
28+
29+
## Making Changes to SQL
30+
All changes to SQL should only be made in the sql directory. SQL Files will be run in alphabetical order.
31+
32+
## Adding Tests
33+
PGStac uses PGTap to test SQL. Tests can be found in tests/pgtap.sql and are run using `scripts/test`
34+
2235

2336
## Migrations
24-
To install the latest version of pgstac on an empty database, you can directly load the primary source code.
25-
```
26-
psql -f pgstac.sql
27-
```
28-
Which calls the main SQL files in the sql directory.
37+
PyPGStac has a utility to help apply migrations to an existing PGStac instance to bring it up to date.
2938

30-
All development should take place on these files.
39+
Migrations are stored in pypgstac/pypgstac/migrations and are distributed with the PyPGStac package. There are two types of migrations.
40+
- Base migrations install PGStac into a database with no current PGStac installation. These migrations follow the file pattern "pgstac.[version].sql"
41+
- Incremental migrations are used to move PGStac from one version to the next. These migrations follow the file pattern "pgstac.[version].[fromversion].sql"
3142

32-
For each new version of PGStac, two migrations should be added to pypgstac/pypgstac/migrations/
33-
- pgstac.[version].sql (equivalent to `cat sql/*.sql > migration.sql && echo "insert into migrations (versions) VALUES ('[version]')" >> migration.sql)
34-
- 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)
43+
These migrations can be created when releasing a new version of PGStac using"
44+
```
45+
scripts/stageversion [version or increment type]
46+
```
47+
Examples:
48+
```
49+
scripts/stageversion 0.2.8
50+
scripts/stageversion patch # if current version is 0.2.7 will bump to 0.2.8
51+
scripts/stageversion minor # if current version is 0.2.7 will bump to 0.3.0
52+
scripts/stageversion major # if current version is 0.2.7 will bump to 1.0.0
53+
```
54+
This will create a base migration for the new version and will create incremental migrations between any existing base migrations. The incremental migrations that are automatically generated by this script will have the extension ".staged" on the file. You must manually review (and make any modifications necessary) this file and remove the ".staged" extension to enable the migration.
3555

3656
### Running Migrations
37-
Migrations can be installed by either directly running the appropriate migration sql file for from and target PGStac versions:
38-
`psql -f pypgstac/pypgstac/migrations/pgstac.0.1.8.sql`
39-
40-
Or by using pypgstac:
41-
`pypgstac migrate`
57+
PyPGStac has a utility for checking the version of an existing PGStac database and applying the appropriate migrations in the correct order. It can also be used to setup a database from scratch.
4258

43-
### Creating Migrations Using Schema Diff
44-
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.
59+
To create an initial PGStac database or bring an existing one up to date:
4560
```
46-
makemigration.sh postgresql://myuser:mypassword@myhost:myport/mydatabase
61+
pypgstac migrate
4762
```
4863

4964
## Bulk Data Loading
@@ -100,4 +115,21 @@ scripts/console --db
100115
To run migrations on the development database, use
101116
```bash
102117
scripts/migrate
103-
```
118+
```
119+
120+
To stage code and configurations and create template migrations for a version release, use
121+
```bash
122+
scripts/stageversion
123+
```
124+
125+
## Release Process
126+
1) Make sure all your code is added and committed
127+
2) Create a PR against the main branch
128+
3) Once the PR has been merged, start the release process.
129+
4) Use `scripts/stagerelease` as documented in migrations section above making sure to rename any files ending in ".staged" in the migrations section
130+
5) Add details for release to the CHANGELOG
131+
6) Add/Commit any changes
132+
7) Run tests `scripts/test`
133+
8) Create a git tag `git tag v0.2.8` using new version number
134+
9) Push the git tag `git push origin v0.2.8`
135+
10) The CI process will push pypgstac to PyPi, create a docker image on ghcr.io, and create a release on github.

docker/dockermigra.sh

Lines changed: 0 additions & 75 deletions
This file was deleted.

docker/initpgstac.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

makemigration.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

pypgstac/pypgstac/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
"""PyPGStac Version."""
12
__version__ = "0.2.8"

0 commit comments

Comments
 (0)