datadouble-postgres 0.0.3__py3-none-any.whl

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.
@@ -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,13 @@
1
+ datadouble_postgres/__init__.py,sha256=_B_kIVyFoYLm7KMfxIuPr8iKFuC95T7ANNX8dIzoE8k,7763
2
+ datadouble_postgres/cluster.py,sha256=Ro5rFnzfybKGQcXAp59DG56SB6s_PRT0TzlD7IuQo1g,8784
3
+ datadouble_postgres/errors.py,sha256=2UT6mu_H9uNwE-iHNa0jyeBOZxGRR7lx-hxtHuC91HI,4893
4
+ datadouble_postgres/introspect.py,sha256=Td6jXZorP9zdztK0-_ll_DUtTWT0hEGnXoPmjOM90ao,23035
5
+ datadouble_postgres/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ datadouble_postgres/render.py,sha256=ZDbiQxJ2MVSzA97Buw-poA-ZOG0gSp5rmxkt5TcLhDU,7978
7
+ datadouble_postgres/source.py,sha256=mKwioZO2ZTcrd9WqyRhg9tlqSAwVP7JjKIauNmzdGMQ,15270
8
+ datadouble_postgres/working.py,sha256=2-1NOpEcMtdytRJoQUDSnki4qxSx_y1_OmKiHTCl-cY,41963
9
+ datadouble_postgres-0.0.3.dist-info/METADATA,sha256=guMU3hgUh-G_USn3fakjT79nZQQBgyQbC128Gy4mJxo,11693
10
+ datadouble_postgres-0.0.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ datadouble_postgres-0.0.3.dist-info/entry_points.txt,sha256=hoydJq3OmzoPkXkoGb3Fhs7XFvsTInI7OABd44nD8NY,59
12
+ datadouble_postgres-0.0.3.dist-info/licenses/LICENSE,sha256=2LcT-SSMiSa7vrHsdC41sUWNmkcwZqIYdYBaSVmqqT8,1072
13
+ datadouble_postgres-0.0.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [datadouble.engines]
2
+ postgres = datadouble_postgres:engine
@@ -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.