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.dm
  • Loading branch information
ryboe committed Feb 20, 2025
1 parent 3bc0fa7 commit f000a1d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
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 f000a1d

Please sign in to comment.