Skip to content

Commit

Permalink
chore: upgrade test environment to Postgres 14
Browse files Browse the repository at this point in the history
* bump test environment image to Postgres 14
* simplify install of pglogical in the test image
* lint README.md
* format .github/workflows/workflow.yml
* bump wntrblm/nox GitHub action to version 2025.02.09
* bump actions/upload-artifact v3 -> v4 to fix CI
  * v3 is "deprecated" and breaks when you try to run it
  • Loading branch information
ryboe committed Feb 20, 2025
1 parent 3bc0fa7 commit 9b42262
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 98 deletions.
138 changes: 69 additions & 69 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: build
"on":
"on":
- push
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: wntrblm/nox@2023.04.22
- uses: wntrblm/nox@2025.02.09
- uses: Gr1N/setup-poetry@v8
- run: nox -s ci_lint
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: wntrblm/nox@2023.04.22
- uses: wntrblm/nox@2025.02.09
- uses: Gr1N/setup-poetry@v8
- run: nox -s unit
build:
Expand All @@ -23,58 +23,58 @@ jobs:
- lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- uses: Gr1N/setup-poetry@v8
- name: Make version unique for non-pypi builds
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
run: poetry version $(poetry version -s).dev${{ github.run_id }}
- name: Build the distribution
run: poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
- uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- uses: Gr1N/setup-poetry@v8
- name: Make version unique for non-pypi builds
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
run: poetry version $(poetry version -s).dev${{ github.run_id }}
- name: Build the distribution
run: poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/sqlalchemy-pglogical

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/sqlalchemy_pglogical # Replace <package-name> with your PyPI project name
url: https://pypi.org/p/sqlalchemy_pglogical # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
Expand All @@ -89,38 +89,38 @@ jobs:
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--notes-from-tag
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--notes-from-tag
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
# sqlalchemy-pglogical

`sqlalchemy-pglogical` is a sqlalchemy extension to automatically send DDL through
`sqlalchemy-pglogical` is a sqlalchemy extension to automatically send DDL through
`pglogical.replicate_ddl_command`

## Who's this for?

`sqlalchemy-pglogical` may be for you if:
- you use `sqlalchemy` and/or `alembic` for DDL, and

- you use `sqlalchemy` and/or `alembic` for DDL, and
- you use `pglogical` for logical replication

## How do I use it?

There are two keys to using `sqlalchemy-pglogical`:

1. `import sqlalchemy_pglogical` - because of the way extending
`sqlalchemy` works, you can do this in pretty much any file that
`sqlalchemy` works, you can do this in pretty much any file that
is loaded before DDL is called
2. Explicitly define your schema. If you're using `sqlalchemy`'s declaritive
syntax, you define your schema by adding `__table_args__` to each table:

```python
Base = declarative_base()


class User(Base):
__tablename__ = "users"
__table_args__ = {"schema": "public"}
```
if you're using `sqlalchemy` core and using `MetaData` to define your tables,

If you're using `sqlalchemy` core and using `MetaData` to define your tables,
add `schema` as a keyword arg to your `MetaData` initialization:

```python
metadata = Metadata(schema="public")
```

It probably makes the most sense to import it wherever you create your engine
to be sure it's always applied. For most apps, this is probably most important
for your migration toolchain (e.g. `alembic`), and less likely to be needed
for your running application. If you're relying on `alembic` to build your
for your migration toolchain (e.g. `alembic`), and less likely to be needed
for your running application. If you're relying on `alembic` to build your
`sqlalchemy.engine` (e.g, it's only defined in your alembic.ini), then you
should probably add this to your migration mako template.

Expand All @@ -55,7 +59,6 @@ We currently assume you're using the `default_ddl` publication and only publish
`pglogical` can't propagate `{CREATE, DROP} INDEX CONCURRENTLY` statements. `sqlachemy-pglogical` makes
no attempt to catch the `CONCURRENTLY` keyword in `INDEX` statements, so they will likely fail.


## How does it work?

DDL operations are represented in SQLAlchemy 1.x with a subclass of `DDLElement`. To
Expand All @@ -73,4 +76,3 @@ def visit_create_table(element, compiler, **kwargs) -> str:
```

We use this to extend _all_ subclasses of `DDLElement` and wrap them in `pglogical.replicate_ddl_command`

12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3.7'
services:
primary:
build:
primary:
build:
context: ./pg
args:
DOCKER_IMAGE: ${PG_DOCKER_IMAGE}
Expand All @@ -10,7 +9,8 @@ services:
- POSTGRES_USER=${PG_USER}
- POSTGRES_DB=${PG_DB}
command:
- "-c"
- "config_file=/etc/postgresql/postgresql.conf"
- -c
- config_file=/etc/postgresql/postgresql.conf
ports:
- "5432:5432"
- 5432:5432
platform: linux/amd64
13 changes: 3 additions & 10 deletions pg/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# dockerfile for pglogical container for integration tests
FROM postgres:13.10-bullseye
FROM postgres:14-bullseye

RUN apt update && apt install postgresql-14-pglogical

# we have to do a source install because pglogical isn't published for arm64
RUN apt update && \
apt install -y curl make build-essential postgresql-server-dev-13 libkrb5-dev libxslt1-dev libselinux1-dev libpam0g-dev zlib1g-dev && \
curl -LO https://github.com/2ndQuadrant/pglogical/archive/refs/tags/REL2_4_2.tar.gz && \
tar xzf REL2_4_2.tar.gz && \
cd pglogical-REL2_4_2 && \
make clean && make install

COPY postgresql.conf /etc/postgresql/postgresql.conf
COPY postgresql.conf /etc/postgresql/postgresql.conf
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = ""
authors = ["Ben Berry <[email protected]>"]
readme = "README.md"
packages = [{include = "sqlalchemy_pglogical"}]
packages = [{ include = "sqlalchemy_pglogical" }]
license = "MIT"

homepage = "https://github.com/brandfolder/sqlalchemy-pglogical"
Expand All @@ -17,7 +17,7 @@ classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"Topic :: Database :: Front-Ends"
"Topic :: Database :: Front-Ends",
]
[tool.poetry.urls]
"Bug Tracker" = "https://github.com/brandfolder/sqlalchemy-pglogical/issues"
Expand Down Expand Up @@ -45,4 +45,3 @@ build-backend = "poetry.core.masonry.api"
line-length = 88
target-version = ['py39']
include = '\.pyi?$'

0 comments on commit 9b42262

Please sign in to comment.