sqllocks-shape-databases 0.9.1__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.
Files changed (37) hide show
  1. sqllocks_shape_databases-0.9.1/LICENSE +21 -0
  2. sqllocks_shape_databases-0.9.1/PKG-INFO +349 -0
  3. sqllocks_shape_databases-0.9.1/README.md +316 -0
  4. sqllocks_shape_databases-0.9.1/pyproject.toml +51 -0
  5. sqllocks_shape_databases-0.9.1/setup.cfg +4 -0
  6. sqllocks_shape_databases-0.9.1/src/shape_databases/__init__.py +35 -0
  7. sqllocks_shape_databases-0.9.1/src/shape_databases/_auth.py +136 -0
  8. sqllocks_shape_databases-0.9.1/src/shape_databases/_base.py +444 -0
  9. sqllocks_shape_databases-0.9.1/src/shape_databases/_cloud.py +215 -0
  10. sqllocks_shape_databases-0.9.1/src/shape_databases/_sql.py +282 -0
  11. sqllocks_shape_databases-0.9.1/src/shape_databases/databricks.py +314 -0
  12. sqllocks_shape_databases-0.9.1/src/shape_databases/duckdb_sink.py +404 -0
  13. sqllocks_shape_databases-0.9.1/src/shape_databases/errors.py +24 -0
  14. sqllocks_shape_databases-0.9.1/src/shape_databases/mysql.py +199 -0
  15. sqllocks_shape_databases-0.9.1/src/shape_databases/postgres.py +147 -0
  16. sqllocks_shape_databases-0.9.1/src/shape_databases/snowflake.py +371 -0
  17. sqllocks_shape_databases-0.9.1/src/shape_databases/testing.py +669 -0
  18. sqllocks_shape_databases-0.9.1/src/sqllocks_shape_databases.egg-info/PKG-INFO +349 -0
  19. sqllocks_shape_databases-0.9.1/src/sqllocks_shape_databases.egg-info/SOURCES.txt +35 -0
  20. sqllocks_shape_databases-0.9.1/src/sqllocks_shape_databases.egg-info/dependency_links.txt +1 -0
  21. sqllocks_shape_databases-0.9.1/src/sqllocks_shape_databases.egg-info/entry_points.txt +6 -0
  22. sqllocks_shape_databases-0.9.1/src/sqllocks_shape_databases.egg-info/requires.txt +16 -0
  23. sqllocks_shape_databases-0.9.1/src/sqllocks_shape_databases.egg-info/top_level.txt +1 -0
  24. sqllocks_shape_databases-0.9.1/tests/test_cli.py +175 -0
  25. sqllocks_shape_databases-0.9.1/tests/test_conformance.py +134 -0
  26. sqllocks_shape_databases-0.9.1/tests/test_credentials.py +258 -0
  27. sqllocks_shape_databases-0.9.1/tests/test_databricks.py +576 -0
  28. sqllocks_shape_databases-0.9.1/tests/test_duckdb.py +716 -0
  29. sqllocks_shape_databases-0.9.1/tests/test_emulator.py +294 -0
  30. sqllocks_shape_databases-0.9.1/tests/test_live.py +98 -0
  31. sqllocks_shape_databases-0.9.1/tests/test_names_and_types.py +262 -0
  32. sqllocks_shape_databases-0.9.1/tests/test_seed.py +93 -0
  33. sqllocks_shape_databases-0.9.1/tests/test_seed_emulator.py +123 -0
  34. sqllocks_shape_databases-0.9.1/tests/test_sinks.py +312 -0
  35. sqllocks_shape_databases-0.9.1/tests/test_snowflake.py +711 -0
  36. sqllocks_shape_databases-0.9.1/tests/test_staging_handles.py +44 -0
  37. sqllocks_shape_databases-0.9.1/tests/test_tls_default.py +127 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 SQLLocks (Jonathan Stewart)
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,349 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqllocks-shape-databases
3
+ Version: 0.9.1
4
+ Summary: Shape plugin: live PostgreSQL, MySQL, Snowflake and Databricks sinks, and a DuckDB file writer
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/sqllocks/shape
7
+ Project-URL: Repository, https://github.com/sqllocks/shape
8
+ Project-URL: Issues, https://github.com/sqllocks/shape/issues
9
+ Project-URL: Documentation, https://github.com/sqllocks/shape/tree/main/plugins/shape-databases
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Database
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: sqllocks-shape==0.9.1
22
+ Provides-Extra: postgres
23
+ Requires-Dist: psycopg[binary]<4,>=3.1; extra == "postgres"
24
+ Provides-Extra: mysql
25
+ Requires-Dist: pymysql<2,>=1.1.1; extra == "mysql"
26
+ Provides-Extra: snowflake
27
+ Requires-Dist: snowflake-connector-python<5,>=3.7; extra == "snowflake"
28
+ Provides-Extra: databricks
29
+ Requires-Dist: databricks-sql-connector<5,>=3.1; extra == "databricks"
30
+ Provides-Extra: duckdb
31
+ Requires-Dist: duckdb>=1.2; extra == "duckdb"
32
+ Dynamic: license-file
33
+
34
+ # sqllocks-shape-databases
35
+
36
+ Shape plugin: write generated tables straight into a running database, or a local DuckDB file
37
+ (`shape.sinks`). Five sinks live here. `postgres` and `mysql` match the dialects of the built-in
38
+ `sql` script sink (same quoting, same Arrow-to-database type map); `snowflake` and `databricks`
39
+ have their own type maps (see [Snowflake](#snowflake) and [Databricks](#databricks)); `duckdb`
40
+ writes Arrow batches into a DuckDB file:
41
+
42
+ | sink | URI | how rows are sent |
43
+ |---|---|---|
44
+ | `postgres` | `postgresql://user@host:5432/db?sslmode=require` (also `postgres://`) | `COPY ... FROM STDIN` (psycopg 3) |
45
+ | `mysql` | `mysql://user@host:3306/db?ssl_ca=/path/ca.pem` | batched multi-row `INSERT` through bound parameters (PyMySQL) |
46
+ | `snowflake` | `snowflake://user@account/database/schema?warehouse=WH&role=ROLE` | Parquet files `PUT` to the table stage, then one `COPY INTO` |
47
+ | `databricks` | `databricks://host/http_path?catalog=CAT&schema=SCH` | batched multi-row `INSERT` with bound parameters into Delta tables |
48
+ | `duckdb` | `duckdb:///PATH.duckdb[?schema=main]` | Arrow batches scanned by DuckDB directly, `INSERT ... SELECT` (DuckDB) |
49
+
50
+ ```
51
+ pip install 'sqllocks-shape[postgres]' # psycopg 3
52
+ pip install 'sqllocks-shape[mysql]' # PyMySQL
53
+ pip install 'sqllocks-shape[databases]' # both
54
+ pip install 'sqllocks-shape[duckdb]' # DuckDB
55
+ pip install 'sqllocks-shape-databases[snowflake]' # snowflake-connector-python
56
+ pip install 'sqllocks-shape-databases[databricks]' # databricks-sql-connector
57
+ ```
58
+
59
+ The client libraries are extras of this distribution and are imported only when a connection
60
+ is opened, so core and the rest of Shape never carry them (the Snowflake and Databricks drivers
61
+ are extras of this plugin only, not of core). A sink without its driver fails with the
62
+ `pip install` line above, exit 2 on the command line.
63
+
64
+ ## TLS by default
65
+
66
+ Like the SQL Server sink (`Encrypt=yes`), these sinks verify TLS for a host that is not loopback:
67
+
68
+ - PostgreSQL uses `sslmode=verify-full`. Point `sslrootcert` at your CA file when the system store
69
+ does not hold it.
70
+ - MySQL uses TLS with certificate and host name verification: the system CA store, or `ssl_ca`.
71
+
72
+ `localhost`, `127.0.0.0/8`, `::1` and Unix sockets keep the driver's defaults, so local and emulator
73
+ use is unchanged. Opt out only in the URI: `sslmode=disable` (or `prefer`) for PostgreSQL;
74
+ `ssl=false` or `ssl-mode=DISABLED` for MySQL. Setting `sslmode` yourself, or MySQL's
75
+ `ssl_verify_cert` / `ssl_verify_identity`, is taken as given. A TLS failure raises an error that
76
+ names the host and the opt-out.
77
+
78
+ ## Writing
79
+
80
+ ```python
81
+ from shape_databases import PostgresSink
82
+
83
+ PostgresSink().write(
84
+ "postgresql://shape@db.example:5432/shape?sslmode=verify-full",
85
+ "customer",
86
+ batches, # an iterable of pyarrow RecordBatches
87
+ write_mode="create",
88
+ commit_rows=50_000,
89
+ )
90
+ ```
91
+
92
+ Batches are consumed one at a time and rows go straight to the server, so memory does not grow
93
+ with the length of the stream.
94
+
95
+ | option | meaning |
96
+ |---|---|
97
+ | `write_mode` | `create` (default: create the table, an existing table is an error and is never touched), `append` (add rows, create if missing), `truncate` (empty then add, create if missing), `replace` (drop and create again) |
98
+ | `schema_name` | PostgreSQL schema / MySQL database to write into (created when missing) |
99
+ | `table_prefix` | text put in front of the table name |
100
+ | `batch_size` | rows converted per step (default 5000); for MySQL, rows per `INSERT` |
101
+ | `commit_rows` | commit every N rows so readers see rows while a stream runs (see below) |
102
+ | `columns`, `primary_key`, `schema` | as for the `sql` sink: per-column `{type, nullable, max_length, precision, scale}`, key columns, and the Arrow schema for creating an empty table from no batches |
103
+ | `password`, `credential`, `token_scope` | see Credentials |
104
+
105
+ A missing table is created from the Arrow schema with the `sql` sink's types (`BIGINT`,
106
+ `VARCHAR(n)`, `NUMERIC`/`DECIMAL`, `TIMESTAMP`/`DATETIME(6)`, `BOOLEAN`/`TINYINT(1)`, `BYTEA`/`LONGBLOB`,
107
+ ...). String columns are sized to the first batch (at least 255); more than 4000 characters, and
108
+ nested list/struct values (written as JSON text), become `TEXT` / `LONGTEXT`. A later, longer
109
+ value fails the write instead of being truncated. Timestamps with a zone are stored as UTC.
110
+
111
+ All names (table, schema, columns) are checked and quoted: a hostile name stays one identifier,
112
+ a name the database would truncate (more than 63 bytes in PostgreSQL, 64 characters in MySQL) or
113
+ misread is refused before any connection is made. Values are never part of a statement.
114
+
115
+ ### Transactions
116
+
117
+ * PostgreSQL: by default the table, a `replace`'s drop and all rows are **one transaction**: a
118
+ failure leaves the database as it was. With `commit_rows=N` each N rows are one `COPY` and one
119
+ commit, and the table is committed before the first rows.
120
+ * MySQL commits implicitly at DDL, so creation cannot be rolled back with the rows: by default
121
+ the rows are one transaction and a table this call created is dropped again on failure
122
+ (`replace` has already dropped the old table, `truncate` has already emptied it). `commit_rows`
123
+ commits every N rows.
124
+ * With `commit_rows`, a failure rolls back only the uncommitted rows. The committed rows stay, and
125
+ `WriteError.rows_committed` says how many.
126
+ * MySQL cannot store NaN or infinity: they are written as NULL (as the script dialect does).
127
+ * `LOAD DATA LOCAL INFILE` is deliberately not used: servers often disable it and enabling it on
128
+ the client allows server-driven file reads.
129
+
130
+ ## Snowflake
131
+
132
+ ```
133
+ shape generate retail --to 'snowflake://loader@myorg-myaccount/SHAPE_DB/PUBLIC?warehouse=WH&role=LOADER' \
134
+ --sink-config snowflake.private_key=file:///home/me/.snowflake/rsa_key.p8
135
+ ```
136
+
137
+ URI: `snowflake://<user>@<account>/<database>/<schema>?warehouse=WH&role=ROLE`. The account is
138
+ the account identifier (`org-account`, or `locator.region`); `schema` may be left out, `warehouse`
139
+ and `role` are optional. `schema_name` (an option) writes to another schema of the database.
140
+
141
+ **How rows go in.** Each table is cut into Parquet files of at most `chunk_rows` rows (default
142
+ 1,000,000) in a private temporary folder; every file is uploaded with `PUT` to the table's own
143
+ internal stage (`@%"TABLE"`), and then one statement loads them all:
144
+
145
+ ```
146
+ COPY INTO "TABLE" FROM @%"TABLE" FILE_FORMAT = (TYPE = PARQUET)
147
+ MATCH_BY_COLUMN_NAME = CASE_SENSITIVE PURGE = TRUE
148
+ ```
149
+
150
+ The number of rows `COPY INTO` reports as loaded must equal the number staged, or the write fails
151
+ (and a table this call created is dropped, a load into an existing table rolled back). The staged
152
+ files are removed with `REMOVE` after the load, also when a step fails (a `REMOVE` that fails is a
153
+ `RuntimeWarning`, never a second error), and the local files are removed in every case. The stage is
154
+ the table's: files left by another process in it would be loaded too, and the row count check
155
+ fails the write rather than let them in silently.
156
+
157
+ **Names.** Tables, schemas and columns are created exactly as named, quoted, so case is kept: a
158
+ table `customer` is `"customer"` (not `CUSTOMER`) and is queried quoted. A name longer than 255
159
+ characters, with a control character or a leading or trailing space, is refused with the name in the
160
+ message before any connection; so are two columns of one name.
161
+
162
+ **Type map from Arrow** (a type not listed, such as `time` or `duration`, is refused before any
163
+ connection, with the column's name):
164
+
165
+ | Arrow | Snowflake |
166
+ |---|---|
167
+ | any integer (including `uint64`) | `NUMBER(38,0)` |
168
+ | `float32`, `float64` | `FLOAT` |
169
+ | `decimal128(p,s)` (p up to 38) | `NUMBER(p,s)` |
170
+ | `string`, `large_string` (dictionaries decoded) | `VARCHAR`, or `VARCHAR(n)` from `columns={"c": {"max_length": n}}` |
171
+ | `bool` | `BOOLEAN` |
172
+ | `date32`, `date64` | `DATE` |
173
+ | `timestamp` without a zone | `TIMESTAMP_NTZ` (zone-less, kept as written) |
174
+ | `timestamp` with a zone | `TIMESTAMP_TZ`, stored as UTC |
175
+ | `binary`, `large_binary`, `fixed_size_binary` | `BINARY` |
176
+ | `list`, `struct`, `map` | `VARIANT` |
177
+
178
+ Timestamps are staged in microseconds (nanoseconds are rounded to them).
179
+
180
+ **Transactions and what a failure leaves behind.** Snowflake commits DDL at once. The connection
181
+ runs with `autocommit` off, so the `COPY INTO` is one transaction: a failure rolls the rows back, and
182
+ a table this call created is dropped again. `replace` has already dropped the old table and
183
+ `truncate` has already emptied it. With `commit_rows=N` the staged rows are loaded and committed
184
+ once at least N of them are waiting at the end of an input batch (N is rounded up to whole batches,
185
+ since a `COPY INTO` is a heavy statement); the committed rows and the table stay on a failure, and
186
+ `WriteError.rows_committed` says how many.
187
+
188
+ **Credentials.** A password is never accepted in the URI. Either a key pair or a password:
189
+
190
+ 1. `private_key`: a reference, `file://PATH` (readable only by its owner) or `env://NAME`, to an
191
+ unencrypted or encrypted PEM private key (PKCS#8), with an optional `private_key_passphrase`
192
+ (a reference or the value). On the command line `--sink-config snowflake.private_key=file://...`
193
+ resolves the reference first, so the sink then receives the PEM text itself, which it accepts too;
194
+ any other text is refused. Needs the `cryptography` package, which the connector installs.
195
+ 2. `password`: a reference or the value (in Python), or the environment variable
196
+ `SNOWFLAKE_PASSWORD`.
197
+
198
+ Giving both a key and a password is an error. Nothing of a key, passphrase or password appears in an
199
+ error message, a log record or a `repr`.
200
+
201
+ ## Databricks
202
+
203
+ ```
204
+ shape generate retail --to 'databricks://adb-123.4.azuredatabricks.net/sql/1.0/warehouses/abc123?catalog=main&schema=demo'
205
+ # DATABRICKS_TOKEN in the environment
206
+ ```
207
+
208
+ URI: `databricks://<host>/<http_path>?catalog=CAT&schema=SCH`, the workspace host and the SQL
209
+ warehouse's HTTP path (its connection details show both) with `catalog` and `schema` for where
210
+ tables go (`schema_name` overrides the schema). Only SQL warehouses are supported.
211
+
212
+ **How rows go in.** Delta tables in Unity Catalog are created with `CREATE TABLE ... USING DELTA`
213
+ and filled with multi-row `INSERT` statements of `batch_size` rows (default 1,000), every value a
214
+ bound parameter (`?` markers, the connector's native parameters). Dates, timestamps and binary
215
+ values are bound as text and converted in the statement (`CAST(? AS DATE)`,
216
+ `CAST(? AS TIMESTAMP_NTZ)`, `CAST(? AS TIMESTAMP)` from UTC, `UNHEX(?)`), so they reach the table
217
+ exactly whatever the session time zone. A warehouse limits how many parameters one statement can
218
+ carry: with very wide tables lower `batch_size`.
219
+
220
+ **Names.** Unity Catalog stores table and schema names in lower case, so a name with capitals, a
221
+ space, `.`, `/` or a backtick is refused with the name in the message (use the lower-case name);
222
+ a column name with a space or one of `,;{}()=`, a tab or a newline (which Delta cannot hold) is
223
+ refused; any name over 255 characters is refused; two columns that differ only in case are
224
+ refused. All before any connection.
225
+
226
+ **Type map from Arrow** (a type not listed, such as `time` or `duration`, is refused before any
227
+ connection, with the column's name):
228
+
229
+ | Arrow | Databricks |
230
+ |---|---|
231
+ | `int8`, `int16`, `int32`, `uint8`, `uint16` | `INT` |
232
+ | `int64`, `uint32` | `BIGINT` |
233
+ | `uint64` | `DECIMAL(20,0)` |
234
+ | `float32`, `float64` | `DOUBLE` |
235
+ | `decimal128(p,s)` (p up to 38) | `DECIMAL(p,s)` |
236
+ | `string`, `large_string` (dictionaries decoded) | `STRING` |
237
+ | `bool` | `BOOLEAN` |
238
+ | `date32`, `date64` | `DATE` |
239
+ | `timestamp` without a zone | `TIMESTAMP_NTZ` |
240
+ | `timestamp` with a zone | `TIMESTAMP`, stored as UTC |
241
+ | `binary`, `large_binary`, `fixed_size_binary` | `BINARY` |
242
+ | `list`, `struct`, `map` | `STRING`, as JSON text |
243
+
244
+ **Transactions and what a failure leaves behind.** A SQL warehouse commits every statement and has
245
+ no rollback, so there is no transaction around a write. `commit_rows` is accepted and is the batch
246
+ boundary: it does not shrink statements (`batch_size` sets how many rows each carries); it makes a
247
+ statement carry no rows of the next input batch, so rows become visible batch by batch while a
248
+ stream runs. A failure drops a table this call created, unless `commit_rows` was given; an `append`
249
+ into a table that already existed keeps the rows of the statements that had run (the error says how
250
+ many, `WriteError.rows_committed`). `replace` has already dropped the old table and `truncate` has
251
+ already emptied it.
252
+
253
+ **Credentials.** A token is never accepted in the URI, and the URI has no user part. Either:
254
+
255
+ 1. a personal access token: the `token` option (a reference `env://` / `file://`, or the value in
256
+ Python) or `DATABRICKS_TOKEN`;
257
+ 2. OAuth machine-to-machine for a service principal: `client_id` (an option, or in the URI query) and
258
+ `client_secret` (a reference or the value). The sink exchanges them at the workspace's
259
+ `/oidc/v1/token` endpoint for an access token that lasts about an hour.
260
+
261
+ On the command line, `--sink-config databricks.token=env://NAME` resolves the reference first. A
262
+ token and a client secret together, or one half of the OAuth pair, are errors.
263
+
264
+ ## DuckDB (`duckdb://`)
265
+
266
+ ```python
267
+ from shape_databases import DuckDbSink
268
+
269
+ DuckDbSink().write(
270
+ "duckdb:///out/retail.duckdb?schema=raw",
271
+ "customer",
272
+ batches,
273
+ write_mode="upsert",
274
+ primary_key=["customer_id"],
275
+ commit_rows=50_000,
276
+ )
277
+ ```
278
+
279
+ `duckdb:///PATH.duckdb` is relative to the working directory, `duckdb:////abs/path.duckdb`
280
+ absolute (Windows: `duckdb:///C:/data/x.duckdb`); a host, a password, no path and `:memory:` are
281
+ refused. `?schema=` (or `schema_name=`) is the DuckDB schema, created when missing in a step of its
282
+ own. Each Arrow batch is scanned by DuckDB as an Arrow table: no value is converted in Python.
283
+
284
+ | Arrow type | DuckDB column |
285
+ |---|---|
286
+ | bool | `BOOLEAN` |
287
+ | int8 / 16 / 32 / 64 | `TINYINT` / `SMALLINT` / `INTEGER` / `BIGINT` |
288
+ | uint8 / 16 / 32 / 64 | `UTINYINT` / `USMALLINT` / `UINTEGER` / `UBIGINT` |
289
+ | float32 / float64 (float16 as float32) | `FLOAT` / `DOUBLE` |
290
+ | decimal128(p, s), p at most 38 | `DECIMAL(p,s)` |
291
+ | string, large_string, dictionary | `VARCHAR`; `UUID` when the `columns` entry says `"type": "uuid"` |
292
+ | binary, large_binary, fixed binary | `BLOB` |
293
+ | date32 / date64 | `DATE` |
294
+ | time32 / time64 | `TIME` (nanoseconds cut to microseconds) |
295
+ | timestamp, no zone: s / ms / us / ns | `TIMESTAMP_S` / `TIMESTAMP_MS` / `TIMESTAMP` / `TIMESTAMP_NS` |
296
+ | timestamp with a zone | `TIMESTAMPTZ` |
297
+
298
+ Nested values and durations are refused with the column named. `primary_key` becomes a `PRIMARY KEY`;
299
+ a key column, or one whose `columns` entry says `"nullable": false`, is `NOT NULL`.
300
+
301
+ | option | meaning |
302
+ |---|---|
303
+ | `write_mode` (or `?write_mode=`; the option wins) | `create` (default: an existing table is an error), `append` (create if missing), `truncate` (`DELETE`, then add; create if missing), `replace` (drop and create), `upsert` (`INSERT OR REPLACE` on the primary key; none: `upsert needs a primary key on <table>`) |
304
+ | `commit_rows` | commit every N rows (rounded up to a batch) so another connection sees them |
305
+ | `schema_name`, `columns`, `primary_key`, `schema` | as above, as for the other sinks |
306
+
307
+ One table is one transaction: a failure rolls back the rows, the table this call created and a
308
+ `replace`'s drop; with `commit_rows` only the open chunk is lost (`WriteError.rows_committed` counts
309
+ what stays). Tables of a run are written at the same time, each on its own connection. A file that
310
+ another process holds locked is a `ShapeError` (exit 2) with DuckDB's message. Reading the tables
311
+ back gives the same `shape.repro.dataset_id` as the generated tables. DuckDB is imported when a write
312
+ starts, never at import time, and is never a core dependency.
313
+
314
+ ## Credentials
315
+
316
+ A password is never accepted in the URI (it would reach logs and shell history): a URI
317
+ with one is refused. Where it comes from, first match wins:
318
+
319
+ 1. the `password` option: the secret, or a reference `env://NAME` or `file://PATH`
320
+ (the file must be readable only by its owner, `chmod 600`);
321
+ 2. the `credential` option: an object with `get_token(scope)` returning something with `.token`
322
+ (every `azure-identity` credential, for Microsoft Entra database logins), a function
323
+ `scope -> token`, or an `env://` / `file://` reference; the token is the password
324
+ (`token_scope` overrides the default `https://ossrdbms-aad.database.windows.net/.default`, the
325
+ Azure Database for PostgreSQL and MySQL scope in the public cloud);
326
+ 3. the environment: `SHAPE_POSTGRES_PASSWORD`, then `PGPASSWORD`; `SHAPE_MYSQL_PASSWORD`, then
327
+ `MYSQL_PWD`;
328
+ 4. none: the driver's default (PostgreSQL reads `~/.pgpass`).
329
+
330
+ A password or token never appears in an exception message, a log record or a `repr`: errors from
331
+ the driver are scrubbed before they are reported, and are raised without the driver's own
332
+ exception attached.
333
+
334
+ ## Testing
335
+
336
+ Contract tests run on every pull request against an in-memory server
337
+ (`shape_databases.testing.FakeServer`) that records every statement, every `COPY` row and every
338
+ `INSERT` parameter list; `FakeSnowflake` and `FakeDatabricks` do the same for the cloud sinks
339
+ (staged Parquet files, `COPY INTO` results, a warehouse that refuses rollbacks). Round trips against
340
+ real accounts are marked `live` and skip, with the missing setting named, unless it is set:
341
+ `SHAPE_TEST_SNOWFLAKE_URI` with `SNOWFLAKE_PASSWORD` (or `SHAPE_TEST_SNOWFLAKE_PRIVATE_KEY`), and
342
+ `SHAPE_TEST_DATABRICKS_URI` with `DATABRICKS_TOKEN`
343
+ (`pytest -m live plugins/shape-databases/tests/test_live.py`). `pytest -m emulator plugins/shape-databases/tests` runs the end-to-end
344
+ tests against real PostgreSQL 16 and MySQL 8.4 (`docker compose -f ci/emulators/docker-compose.yml
345
+ up -d --wait postgres mysql`, with `SHAPE_POSTGRES_PASSWORD` / `SHAPE_MYSQL_PASSWORD` set to
346
+ `shape_emulator`), nightly in CI. The DuckDB sink needs no server: its tests write real DuckDB files.
347
+
348
+ Its version always equals core's (`sqllocks-shape`), and it is released together with core.
349
+ How plugins are written: `docs/plugins/authoring.md` in the repository.