datadouble-postgres 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datadouble_postgres-0.0.3/.gitignore +21 -0
- datadouble_postgres-0.0.3/LICENSE +21 -0
- datadouble_postgres-0.0.3/PKG-INFO +249 -0
- datadouble_postgres-0.0.3/README.md +228 -0
- datadouble_postgres-0.0.3/pyproject.toml +38 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/__init__.py +192 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/cluster.py +229 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/errors.py +107 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/introspect.py +542 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/py.typed +0 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/render.py +212 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/source.py +380 -0
- datadouble_postgres-0.0.3/src/datadouble_postgres/working.py +1003 -0
- datadouble_postgres-0.0.3/tests/test_cluster.py +161 -0
- datadouble_postgres-0.0.3/tests/test_conformance.py +340 -0
- datadouble_postgres-0.0.3/tests/test_postgres.py +877 -0
- datadouble_postgres-0.0.3/tests/test_render.py +347 -0
- datadouble_postgres-0.0.3/tests/test_sources.py +184 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.py[cod]
|
|
6
|
+
.venv/
|
|
7
|
+
.env
|
|
8
|
+
.coverage
|
|
9
|
+
.coverage.*
|
|
10
|
+
coverage.xml
|
|
11
|
+
.reports/
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.mypy_cache/
|
|
14
|
+
.ruff_cache/
|
|
15
|
+
dist/
|
|
16
|
+
site/
|
|
17
|
+
.cache/
|
|
18
|
+
|
|
19
|
+
# The default work directory of `datadouble run`.
|
|
20
|
+
.datadouble/
|
|
21
|
+
node_modules/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026- Tight Line LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datadouble-postgres
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: PostgreSQL engine adapter for Datadouble
|
|
5
|
+
Project-URL: Homepage, https://datadouble.tightlinesoftware.com/
|
|
6
|
+
Project-URL: Source, https://github.com/datadouble/datadouble
|
|
7
|
+
Author: Tight Line LLC
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Classifier: Topic :: Database
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Requires-Dist: datadouble
|
|
19
|
+
Requires-Dist: psycopg[binary]>=3.3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# datadouble-postgres
|
|
23
|
+
|
|
24
|
+
The PostgreSQL engine adapter for [Datadouble](https://datadouble.tightlinesoftware.com/).
|
|
25
|
+
|
|
26
|
+
It reads one or more databases, each under an exported snapshot, builds
|
|
27
|
+
working databases as throwaway PostgreSQL clusters in scratch space, and
|
|
28
|
+
packages golden images as a data directory (`physical`) or `pg_dump` archives
|
|
29
|
+
(`logical`). Clusters, restores and `pg_dump` run in the official
|
|
30
|
+
PostgreSQL image of the source's exact version, through the spec's container
|
|
31
|
+
runtime; a source that uses extensions names an image that has them in
|
|
32
|
+
`sources.<name>.image`.
|
|
33
|
+
|
|
34
|
+
## Accounts
|
|
35
|
+
|
|
36
|
+
A physical image carries no account that logs in over the network, so a
|
|
37
|
+
server started on a copy with the official image accepts only local
|
|
38
|
+
connections. `package.accounts` adds some:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
package:
|
|
42
|
+
accounts:
|
|
43
|
+
- user: app # privileges: all
|
|
44
|
+
password: app-password
|
|
45
|
+
- user: reporting
|
|
46
|
+
password:
|
|
47
|
+
env: REPORTING_PW
|
|
48
|
+
privileges: read
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Each becomes a role that logs in. `all` is a superuser. `read` is a plain
|
|
52
|
+
role with `CONNECT` on each database and, in every schema but the system
|
|
53
|
+
ones, `USAGE` and `SELECT` on every table, view and sequence; it can't read
|
|
54
|
+
`pg_authid` or its password hashes. It also keeps what `PUBLIC` has, which
|
|
55
|
+
Datadouble doesn't change: temporary tables, running functions, changing its
|
|
56
|
+
own password, and before PostgreSQL 15 creating objects in `public`.
|
|
57
|
+
|
|
58
|
+
The image's `pg_hba.conf` gains `host all all all scram-sha-256`. An existing
|
|
59
|
+
role of that name gets the password and attributes reset. Datadouble computes
|
|
60
|
+
a SCRAM verifier and sends only that, so no statement the server could log
|
|
61
|
+
holds a password. The build checks each role in `pg_authid` and logs in with
|
|
62
|
+
it over TCP before storing the image.
|
|
63
|
+
|
|
64
|
+
The image's `pg_hba.conf` still trusts local and loopback connections, as
|
|
65
|
+
`initdb` wrote it, ahead of that rule, so anything inside the consumer's
|
|
66
|
+
container, a sidecar sharing its network, or a `kubectl port-forward` to it
|
|
67
|
+
logs in as `postgres` without a password.
|
|
68
|
+
|
|
69
|
+
An instance copy's server sets the copy's generated password on `postgres`
|
|
70
|
+
when it starts, so a declared `postgres` account's password holds on volume
|
|
71
|
+
copies only.
|
|
72
|
+
|
|
73
|
+
The plan refuses names longer than 63 bytes, names starting with `pg_`, the
|
|
74
|
+
names PostgreSQL reserves (`public`, `none`, `current_user`, `session_user`,
|
|
75
|
+
`current_role`), and `postgres` with `privileges: read`, since the bootstrap
|
|
76
|
+
superuser can't stop being one.
|
|
77
|
+
|
|
78
|
+
## Databases
|
|
79
|
+
|
|
80
|
+
The connection string's database is the one read, unless
|
|
81
|
+
`connection.databases` lists others. Tables are named `database.schema.table`
|
|
82
|
+
even when only one database is read, and a spec may leave out leading parts
|
|
83
|
+
wherever only one table fits: `public.users` or `users` for
|
|
84
|
+
`shop.public.users`. A name that fits tables in several databases fails the
|
|
85
|
+
plan, naming each; write enough of it to choose one.
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
sources:
|
|
89
|
+
app:
|
|
90
|
+
engine: postgres
|
|
91
|
+
connection:
|
|
92
|
+
dsn: # which database it names matters only as the default
|
|
93
|
+
env: SHOP_DSN
|
|
94
|
+
databases: [shop, "billing_*"] # names or globs; ["*"] for every database
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- **Choosing databases.** Each entry is a name or a glob. A name must exist
|
|
98
|
+
and a glob must match at least one database the user may connect to, so a
|
|
99
|
+
typing mistake fails instead of quietly reading less. `["*"]` reads every
|
|
100
|
+
database the user can connect to except templates; `postgres` is an
|
|
101
|
+
ordinary database here, since some services keep an application's data in
|
|
102
|
+
it. With a glob, a database created later is read too, and strict mode
|
|
103
|
+
stops the build at its tables until they are locked.
|
|
104
|
+
- **A snapshot per database.** PostgreSQL cannot share a snapshot between
|
|
105
|
+
databases, so each is read under its own, all opened together as the
|
|
106
|
+
extract starts. PostgreSQL has no references between databases, so each
|
|
107
|
+
database is consistent on its own; a virtual reference between two
|
|
108
|
+
databases fails the plan, since no query could follow it. The manifest
|
|
109
|
+
records each database's snapshot under `snapshots`.
|
|
110
|
+
- **The copies hold every database,** under its own name, in one cluster:
|
|
111
|
+
working databases, physical images, and logical images (one `pg_dump`
|
|
112
|
+
archive per database).
|
|
113
|
+
Excluding every table of a database (`shop.*.*`) still reads it under its
|
|
114
|
+
snapshot and leaves it empty in the copies; leave it out of `databases` to
|
|
115
|
+
leave it out altogether.
|
|
116
|
+
- **The default database.** Spec SQL that names no table (hooks and
|
|
117
|
+
assertions) runs in a default database: the connection string's, when it
|
|
118
|
+
is read, or else the first database read in name order. Copies announce it
|
|
119
|
+
as their `database`. Seeds, `when` clauses and expression rules run in their
|
|
120
|
+
own table's database.
|
|
121
|
+
- **Extensions are per database.** Each database's extensions are created in
|
|
122
|
+
its copy at its versions, and the lock lists every one.
|
|
123
|
+
Sources must be PostgreSQL 13 or later: reading which triggers a partition
|
|
124
|
+
inherits from its parent needs `pg_trigger.tgparentid`.
|
|
125
|
+
|
|
126
|
+
## Several servers
|
|
127
|
+
|
|
128
|
+
A spec can read databases from several PostgreSQL servers, one source per
|
|
129
|
+
server, into one image (see
|
|
130
|
+
[several sources](../../docs/architecture.md#several-sources)):
|
|
131
|
+
|
|
132
|
+
```yaml
|
|
133
|
+
sources:
|
|
134
|
+
app:
|
|
135
|
+
engine: postgres
|
|
136
|
+
connection:
|
|
137
|
+
dsn:
|
|
138
|
+
env: APP_DSN
|
|
139
|
+
databases: [orders, billing]
|
|
140
|
+
warehouse:
|
|
141
|
+
engine: postgres
|
|
142
|
+
connection:
|
|
143
|
+
dsn:
|
|
144
|
+
env: WAREHOUSE_DSN
|
|
145
|
+
databases: [warehouse]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- **Every database once.** A database name read from two servers fails the
|
|
149
|
+
plan, naming it; the working cluster holds every source's databases under
|
|
150
|
+
their own names.
|
|
151
|
+
- **One version line.** The servers must share a major version (`17`),
|
|
152
|
+
PostgreSQL's compatibility line; the working cluster runs the newest of
|
|
153
|
+
their versions, and each server's schema is dumped by `pg_dump` from the
|
|
154
|
+
image of its own version. Every source gives
|
|
155
|
+
the same `image` and `server` settings, or none.
|
|
156
|
+
- **Snapshots per database, per server.** Each database is still read under
|
|
157
|
+
its own snapshot, and the image's manifest records them by source
|
|
158
|
+
(`sources.<name>.snapshots`, with the time each source's snapshots were
|
|
159
|
+
opened). A virtual reference between sources joins two databases, which
|
|
160
|
+
PostgreSQL refuses as it does within one server.
|
|
161
|
+
- **The default database** for hooks and assertions is the first source's.
|
|
162
|
+
|
|
163
|
+
## Extensions
|
|
164
|
+
|
|
165
|
+
Every extension installed in a database read, except `plpgsql`, is a
|
|
166
|
+
requirement at the version the source runs (`pg_extension.extversion`).
|
|
167
|
+
|
|
168
|
+
- **The image must have it.** Before reading the snapshot, a build lists the
|
|
169
|
+
extension versions the working image offers
|
|
170
|
+
(`pg_available_extension_versions`) and fails with `requirement_unmet` if
|
|
171
|
+
one is missing. The official image has everything in contrib (`hstore`,
|
|
172
|
+
`pg_trgm`, `citext`, `pgcrypto`, `uuid-ossp`, `postgres_fdw` and the rest).
|
|
173
|
+
Other extensions need an image that adds them, such as
|
|
174
|
+
`pgvector/pgvector:0.8.7-pg18-trixie` for `vector`,
|
|
175
|
+
`postgis/postgis:18-3.6` for PostGIS or `timescale/timescaledb:latest-pg18`
|
|
176
|
+
(pin a release) for TimescaleDB. Pick one built on the source's PostgreSQL
|
|
177
|
+
release.
|
|
178
|
+
- **The working database runs the source's version.** `load` creates each
|
|
179
|
+
extension at the source's version, so a source on `hstore` 1.4 gets 1.4
|
|
180
|
+
even when the image's default is 1.8. Many third-party extensions install
|
|
181
|
+
only their newest version (pgvector 0.8.7 cannot create 0.8.2), so pick
|
|
182
|
+
the image release that matches the source's extension version.
|
|
183
|
+
- **Some extensions load at server start.** Name them in
|
|
184
|
+
`sources.<name>.server.shared_preload_libraries`. Working clusters start with the
|
|
185
|
+
setting, and a physical image keeps it in `postgresql.conf`, so its copies
|
|
186
|
+
load the libraries too.
|
|
187
|
+
- **A managed service's own extensions** (`aws_s3`, `aws_commons`,
|
|
188
|
+
`rds_tools`, `google_ml_integration`, `azure`) are in no public image.
|
|
189
|
+
Leave them out with `sources.<name>.omit`, and exclude whatever uses them.
|
|
190
|
+
- **Logical images** restore with `pg_restore`, which creates extensions at
|
|
191
|
+
the restoring server's default version.
|
|
192
|
+
|
|
193
|
+
```yaml
|
|
194
|
+
sources:
|
|
195
|
+
app:
|
|
196
|
+
engine: postgres
|
|
197
|
+
connection:
|
|
198
|
+
dsn:
|
|
199
|
+
env: SHOP_DSN
|
|
200
|
+
image: postgis/postgis:18-3.6 # the source uses PostGIS
|
|
201
|
+
server:
|
|
202
|
+
shared_preload_libraries: [pg_stat_statements]
|
|
203
|
+
omit: [aws_s3, aws_commons] # RDS-only; nothing kept uses them
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Server settings
|
|
207
|
+
|
|
208
|
+
`sources.<name>.server` takes `shared_preload_libraries`, a list of library names.
|
|
209
|
+
Nothing else.
|
|
210
|
+
|
|
211
|
+
## Objects
|
|
212
|
+
|
|
213
|
+
The catalog lists functions and procedures (by name and argument types),
|
|
214
|
+
views and materialized views, triggers, enum, domain, composite and range
|
|
215
|
+
types, and sequences, outside the system schemas and not owned by an
|
|
216
|
+
extension, in every database read. Objects are named like tables,
|
|
217
|
+
`database.schema.object`; a trigger's last part is `table.trigger`
|
|
218
|
+
(`shop.public.users.audit`), since trigger names are only unique per table.
|
|
219
|
+
Each database's objects are read under its own snapshot, and since
|
|
220
|
+
PostgreSQL has nothing that refers across databases, their edges stay within
|
|
221
|
+
it. Dependencies come from `pg_depend`, which is
|
|
222
|
+
exact for views, materialized views, triggers, types, sequences and
|
|
223
|
+
routines with SQL-standard bodies (`BEGIN ATOMIC`). Other routine bodies,
|
|
224
|
+
such as PL/pgSQL, are parsed for the tables and objects they name, and those
|
|
225
|
+
edges are marked inferred: a statement built with `EXECUTE` at run time is
|
|
226
|
+
not seen.
|
|
227
|
+
|
|
228
|
+
Tables list what they need too, exactly from `pg_depend`: the sequences and
|
|
229
|
+
functions their column defaults and generated columns use, the functions
|
|
230
|
+
their check constraints, index expressions and predicates call, the
|
|
231
|
+
functions and tables their row-level security policies use, their columns'
|
|
232
|
+
enum, domain, composite and range types, a typed table's type and an
|
|
233
|
+
inheriting table's parent. A table only a policy reads comes into a
|
|
234
|
+
standalone image without rows unless `rows` asks for some; one copies leave
|
|
235
|
+
out (excluded) only warns, and the policy goes with it. Package planning follows these edges to work out what an
|
|
236
|
+
image needs.
|
|
237
|
+
|
|
238
|
+
A standalone group's database holds exactly its closure. The schema is
|
|
239
|
+
restored as for any group, the pulled-in tables are kept with the rows of
|
|
240
|
+
the group's own extract, and then every object the closure lacks is
|
|
241
|
+
dropped, dependents first and without `CASCADE`: a dependency `pg_depend`
|
|
242
|
+
records but the catalog missed stops the load with PostgreSQL's error
|
|
243
|
+
rather than removing more. Aggregates, operators and casts are not in the
|
|
244
|
+
catalog, so a function only they use is not in any closure: dropping it
|
|
245
|
+
fails with PostgreSQL's detail of what depends on it, and declaring the
|
|
246
|
+
function in the group's `objects` keeps it. A trigger is dropped on the
|
|
247
|
+
table or view the database says it is on, and one already gone with its
|
|
248
|
+
table or view is skipped. Foreign keys into a pulled-in table without rows are
|
|
249
|
+
left out. Schemas stay, even when nothing in them is kept.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# datadouble-postgres
|
|
2
|
+
|
|
3
|
+
The PostgreSQL engine adapter for [Datadouble](https://datadouble.tightlinesoftware.com/).
|
|
4
|
+
|
|
5
|
+
It reads one or more databases, each under an exported snapshot, builds
|
|
6
|
+
working databases as throwaway PostgreSQL clusters in scratch space, and
|
|
7
|
+
packages golden images as a data directory (`physical`) or `pg_dump` archives
|
|
8
|
+
(`logical`). Clusters, restores and `pg_dump` run in the official
|
|
9
|
+
PostgreSQL image of the source's exact version, through the spec's container
|
|
10
|
+
runtime; a source that uses extensions names an image that has them in
|
|
11
|
+
`sources.<name>.image`.
|
|
12
|
+
|
|
13
|
+
## Accounts
|
|
14
|
+
|
|
15
|
+
A physical image carries no account that logs in over the network, so a
|
|
16
|
+
server started on a copy with the official image accepts only local
|
|
17
|
+
connections. `package.accounts` adds some:
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
package:
|
|
21
|
+
accounts:
|
|
22
|
+
- user: app # privileges: all
|
|
23
|
+
password: app-password
|
|
24
|
+
- user: reporting
|
|
25
|
+
password:
|
|
26
|
+
env: REPORTING_PW
|
|
27
|
+
privileges: read
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Each becomes a role that logs in. `all` is a superuser. `read` is a plain
|
|
31
|
+
role with `CONNECT` on each database and, in every schema but the system
|
|
32
|
+
ones, `USAGE` and `SELECT` on every table, view and sequence; it can't read
|
|
33
|
+
`pg_authid` or its password hashes. It also keeps what `PUBLIC` has, which
|
|
34
|
+
Datadouble doesn't change: temporary tables, running functions, changing its
|
|
35
|
+
own password, and before PostgreSQL 15 creating objects in `public`.
|
|
36
|
+
|
|
37
|
+
The image's `pg_hba.conf` gains `host all all all scram-sha-256`. An existing
|
|
38
|
+
role of that name gets the password and attributes reset. Datadouble computes
|
|
39
|
+
a SCRAM verifier and sends only that, so no statement the server could log
|
|
40
|
+
holds a password. The build checks each role in `pg_authid` and logs in with
|
|
41
|
+
it over TCP before storing the image.
|
|
42
|
+
|
|
43
|
+
The image's `pg_hba.conf` still trusts local and loopback connections, as
|
|
44
|
+
`initdb` wrote it, ahead of that rule, so anything inside the consumer's
|
|
45
|
+
container, a sidecar sharing its network, or a `kubectl port-forward` to it
|
|
46
|
+
logs in as `postgres` without a password.
|
|
47
|
+
|
|
48
|
+
An instance copy's server sets the copy's generated password on `postgres`
|
|
49
|
+
when it starts, so a declared `postgres` account's password holds on volume
|
|
50
|
+
copies only.
|
|
51
|
+
|
|
52
|
+
The plan refuses names longer than 63 bytes, names starting with `pg_`, the
|
|
53
|
+
names PostgreSQL reserves (`public`, `none`, `current_user`, `session_user`,
|
|
54
|
+
`current_role`), and `postgres` with `privileges: read`, since the bootstrap
|
|
55
|
+
superuser can't stop being one.
|
|
56
|
+
|
|
57
|
+
## Databases
|
|
58
|
+
|
|
59
|
+
The connection string's database is the one read, unless
|
|
60
|
+
`connection.databases` lists others. Tables are named `database.schema.table`
|
|
61
|
+
even when only one database is read, and a spec may leave out leading parts
|
|
62
|
+
wherever only one table fits: `public.users` or `users` for
|
|
63
|
+
`shop.public.users`. A name that fits tables in several databases fails the
|
|
64
|
+
plan, naming each; write enough of it to choose one.
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
sources:
|
|
68
|
+
app:
|
|
69
|
+
engine: postgres
|
|
70
|
+
connection:
|
|
71
|
+
dsn: # which database it names matters only as the default
|
|
72
|
+
env: SHOP_DSN
|
|
73
|
+
databases: [shop, "billing_*"] # names or globs; ["*"] for every database
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- **Choosing databases.** Each entry is a name or a glob. A name must exist
|
|
77
|
+
and a glob must match at least one database the user may connect to, so a
|
|
78
|
+
typing mistake fails instead of quietly reading less. `["*"]` reads every
|
|
79
|
+
database the user can connect to except templates; `postgres` is an
|
|
80
|
+
ordinary database here, since some services keep an application's data in
|
|
81
|
+
it. With a glob, a database created later is read too, and strict mode
|
|
82
|
+
stops the build at its tables until they are locked.
|
|
83
|
+
- **A snapshot per database.** PostgreSQL cannot share a snapshot between
|
|
84
|
+
databases, so each is read under its own, all opened together as the
|
|
85
|
+
extract starts. PostgreSQL has no references between databases, so each
|
|
86
|
+
database is consistent on its own; a virtual reference between two
|
|
87
|
+
databases fails the plan, since no query could follow it. The manifest
|
|
88
|
+
records each database's snapshot under `snapshots`.
|
|
89
|
+
- **The copies hold every database,** under its own name, in one cluster:
|
|
90
|
+
working databases, physical images, and logical images (one `pg_dump`
|
|
91
|
+
archive per database).
|
|
92
|
+
Excluding every table of a database (`shop.*.*`) still reads it under its
|
|
93
|
+
snapshot and leaves it empty in the copies; leave it out of `databases` to
|
|
94
|
+
leave it out altogether.
|
|
95
|
+
- **The default database.** Spec SQL that names no table (hooks and
|
|
96
|
+
assertions) runs in a default database: the connection string's, when it
|
|
97
|
+
is read, or else the first database read in name order. Copies announce it
|
|
98
|
+
as their `database`. Seeds, `when` clauses and expression rules run in their
|
|
99
|
+
own table's database.
|
|
100
|
+
- **Extensions are per database.** Each database's extensions are created in
|
|
101
|
+
its copy at its versions, and the lock lists every one.
|
|
102
|
+
Sources must be PostgreSQL 13 or later: reading which triggers a partition
|
|
103
|
+
inherits from its parent needs `pg_trigger.tgparentid`.
|
|
104
|
+
|
|
105
|
+
## Several servers
|
|
106
|
+
|
|
107
|
+
A spec can read databases from several PostgreSQL servers, one source per
|
|
108
|
+
server, into one image (see
|
|
109
|
+
[several sources](../../docs/architecture.md#several-sources)):
|
|
110
|
+
|
|
111
|
+
```yaml
|
|
112
|
+
sources:
|
|
113
|
+
app:
|
|
114
|
+
engine: postgres
|
|
115
|
+
connection:
|
|
116
|
+
dsn:
|
|
117
|
+
env: APP_DSN
|
|
118
|
+
databases: [orders, billing]
|
|
119
|
+
warehouse:
|
|
120
|
+
engine: postgres
|
|
121
|
+
connection:
|
|
122
|
+
dsn:
|
|
123
|
+
env: WAREHOUSE_DSN
|
|
124
|
+
databases: [warehouse]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- **Every database once.** A database name read from two servers fails the
|
|
128
|
+
plan, naming it; the working cluster holds every source's databases under
|
|
129
|
+
their own names.
|
|
130
|
+
- **One version line.** The servers must share a major version (`17`),
|
|
131
|
+
PostgreSQL's compatibility line; the working cluster runs the newest of
|
|
132
|
+
their versions, and each server's schema is dumped by `pg_dump` from the
|
|
133
|
+
image of its own version. Every source gives
|
|
134
|
+
the same `image` and `server` settings, or none.
|
|
135
|
+
- **Snapshots per database, per server.** Each database is still read under
|
|
136
|
+
its own snapshot, and the image's manifest records them by source
|
|
137
|
+
(`sources.<name>.snapshots`, with the time each source's snapshots were
|
|
138
|
+
opened). A virtual reference between sources joins two databases, which
|
|
139
|
+
PostgreSQL refuses as it does within one server.
|
|
140
|
+
- **The default database** for hooks and assertions is the first source's.
|
|
141
|
+
|
|
142
|
+
## Extensions
|
|
143
|
+
|
|
144
|
+
Every extension installed in a database read, except `plpgsql`, is a
|
|
145
|
+
requirement at the version the source runs (`pg_extension.extversion`).
|
|
146
|
+
|
|
147
|
+
- **The image must have it.** Before reading the snapshot, a build lists the
|
|
148
|
+
extension versions the working image offers
|
|
149
|
+
(`pg_available_extension_versions`) and fails with `requirement_unmet` if
|
|
150
|
+
one is missing. The official image has everything in contrib (`hstore`,
|
|
151
|
+
`pg_trgm`, `citext`, `pgcrypto`, `uuid-ossp`, `postgres_fdw` and the rest).
|
|
152
|
+
Other extensions need an image that adds them, such as
|
|
153
|
+
`pgvector/pgvector:0.8.7-pg18-trixie` for `vector`,
|
|
154
|
+
`postgis/postgis:18-3.6` for PostGIS or `timescale/timescaledb:latest-pg18`
|
|
155
|
+
(pin a release) for TimescaleDB. Pick one built on the source's PostgreSQL
|
|
156
|
+
release.
|
|
157
|
+
- **The working database runs the source's version.** `load` creates each
|
|
158
|
+
extension at the source's version, so a source on `hstore` 1.4 gets 1.4
|
|
159
|
+
even when the image's default is 1.8. Many third-party extensions install
|
|
160
|
+
only their newest version (pgvector 0.8.7 cannot create 0.8.2), so pick
|
|
161
|
+
the image release that matches the source's extension version.
|
|
162
|
+
- **Some extensions load at server start.** Name them in
|
|
163
|
+
`sources.<name>.server.shared_preload_libraries`. Working clusters start with the
|
|
164
|
+
setting, and a physical image keeps it in `postgresql.conf`, so its copies
|
|
165
|
+
load the libraries too.
|
|
166
|
+
- **A managed service's own extensions** (`aws_s3`, `aws_commons`,
|
|
167
|
+
`rds_tools`, `google_ml_integration`, `azure`) are in no public image.
|
|
168
|
+
Leave them out with `sources.<name>.omit`, and exclude whatever uses them.
|
|
169
|
+
- **Logical images** restore with `pg_restore`, which creates extensions at
|
|
170
|
+
the restoring server's default version.
|
|
171
|
+
|
|
172
|
+
```yaml
|
|
173
|
+
sources:
|
|
174
|
+
app:
|
|
175
|
+
engine: postgres
|
|
176
|
+
connection:
|
|
177
|
+
dsn:
|
|
178
|
+
env: SHOP_DSN
|
|
179
|
+
image: postgis/postgis:18-3.6 # the source uses PostGIS
|
|
180
|
+
server:
|
|
181
|
+
shared_preload_libraries: [pg_stat_statements]
|
|
182
|
+
omit: [aws_s3, aws_commons] # RDS-only; nothing kept uses them
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Server settings
|
|
186
|
+
|
|
187
|
+
`sources.<name>.server` takes `shared_preload_libraries`, a list of library names.
|
|
188
|
+
Nothing else.
|
|
189
|
+
|
|
190
|
+
## Objects
|
|
191
|
+
|
|
192
|
+
The catalog lists functions and procedures (by name and argument types),
|
|
193
|
+
views and materialized views, triggers, enum, domain, composite and range
|
|
194
|
+
types, and sequences, outside the system schemas and not owned by an
|
|
195
|
+
extension, in every database read. Objects are named like tables,
|
|
196
|
+
`database.schema.object`; a trigger's last part is `table.trigger`
|
|
197
|
+
(`shop.public.users.audit`), since trigger names are only unique per table.
|
|
198
|
+
Each database's objects are read under its own snapshot, and since
|
|
199
|
+
PostgreSQL has nothing that refers across databases, their edges stay within
|
|
200
|
+
it. Dependencies come from `pg_depend`, which is
|
|
201
|
+
exact for views, materialized views, triggers, types, sequences and
|
|
202
|
+
routines with SQL-standard bodies (`BEGIN ATOMIC`). Other routine bodies,
|
|
203
|
+
such as PL/pgSQL, are parsed for the tables and objects they name, and those
|
|
204
|
+
edges are marked inferred: a statement built with `EXECUTE` at run time is
|
|
205
|
+
not seen.
|
|
206
|
+
|
|
207
|
+
Tables list what they need too, exactly from `pg_depend`: the sequences and
|
|
208
|
+
functions their column defaults and generated columns use, the functions
|
|
209
|
+
their check constraints, index expressions and predicates call, the
|
|
210
|
+
functions and tables their row-level security policies use, their columns'
|
|
211
|
+
enum, domain, composite and range types, a typed table's type and an
|
|
212
|
+
inheriting table's parent. A table only a policy reads comes into a
|
|
213
|
+
standalone image without rows unless `rows` asks for some; one copies leave
|
|
214
|
+
out (excluded) only warns, and the policy goes with it. Package planning follows these edges to work out what an
|
|
215
|
+
image needs.
|
|
216
|
+
|
|
217
|
+
A standalone group's database holds exactly its closure. The schema is
|
|
218
|
+
restored as for any group, the pulled-in tables are kept with the rows of
|
|
219
|
+
the group's own extract, and then every object the closure lacks is
|
|
220
|
+
dropped, dependents first and without `CASCADE`: a dependency `pg_depend`
|
|
221
|
+
records but the catalog missed stops the load with PostgreSQL's error
|
|
222
|
+
rather than removing more. Aggregates, operators and casts are not in the
|
|
223
|
+
catalog, so a function only they use is not in any closure: dropping it
|
|
224
|
+
fails with PostgreSQL's detail of what depends on it, and declaring the
|
|
225
|
+
function in the group's `objects` keeps it. A trigger is dropped on the
|
|
226
|
+
table or view the database says it is on, and one already gone with its
|
|
227
|
+
table or view is skipped. Foreign keys into a pulled-in table without rows are
|
|
228
|
+
left out. Schemas stay, even when nothing in them is kept.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
[project]
|
|
5
|
+
name = "datadouble-postgres"
|
|
6
|
+
# All packages share one version until 1.0 (decision 38); scripts/make_tag.py
|
|
7
|
+
# sets it at release time.
|
|
8
|
+
version = "0.0.3"
|
|
9
|
+
description = "PostgreSQL engine adapter for Datadouble"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Tight Line LLC" }]
|
|
14
|
+
requires-python = ">=3.13"
|
|
15
|
+
dependencies = ["datadouble", "psycopg[binary]>=3.3.9"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Programming Language :: Python :: 3.15",
|
|
22
|
+
"Topic :: Database",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://datadouble.tightlinesoftware.com/"
|
|
28
|
+
Source = "https://github.com/datadouble/datadouble"
|
|
29
|
+
|
|
30
|
+
[project.entry-points."datadouble.engines"]
|
|
31
|
+
postgres = "datadouble_postgres:engine"
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["hatchling>=1.33.0"]
|
|
35
|
+
build-backend = "hatchling.build"
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.wheel]
|
|
38
|
+
packages = ["src/datadouble_postgres"]
|