Skip to content

Commit 6610328

Browse files
committed
feat: naming-flat, emit-bundle (fast deploy), and import-granularity examples
1 parent 3cb539a commit 6610328

100 files changed

Lines changed: 1359 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ produced it.
4242
| [diff-migration](examples/diff-migration) | [the module (v1)](examples/import-dump/output/shop) vs [shop.v2.sql](examples/diff-migration/input/shop.v2.sql) | [migration module](examples/diff-migration/output/shop-v1-to-v2) + [delta as one SQL file](examples/diff-migration/output/shop.v1-to-v2.sql) |
4343
| [fold-atomic-statements](examples/fold-atomic-statements) | [atomic statement soup](examples/fold-atomic-statements/input/blog.atomic.sql) (empty `CREATE TABLE ()` + one `ADD COLUMN` per statement) | [grouped module](examples/fold-atomic-statements/output/blog) with fully folded CREATE TABLEs |
4444
| [flatten-history](examples/flatten-history) | [evolution log with churn](examples/flatten-history/input/inventory.churn.sql) (ADD then DROP column, late NOT NULL) | [flattened module](examples/flatten-history/output/inventory) |
45+
| [import-granularity](examples/import-granularity) | [raw pg_dump](examples/import-dump/input/shop.v1.sql) | [atomic module in one step](examples/import-granularity/output/shop-atomic-direct) (`import --granularity atomic`) |
46+
| [naming-flat](examples/naming-flat) | [the module](examples/import-dump/output/shop) | [flat change-path layout](examples/naming-flat/output/shop-object) (`--naming flat`) |
47+
| [emit-bundle](examples/emit-bundle) | [the module](examples/import-dump/output/shop) | [content-addressed bundle](examples/emit-bundle/output/shop.bundle.tar.gz) powering `pgpm deploy --fast` |
4548

46-
More examples are planned (`--naming flat`, bundles + `deploy --fast`,
47-
`--append-module`, live-db diff sides) — see the full combination matrix in
49+
More examples are planned (`--append-module`, live-db diff sides) — see the full combination matrix in
4850
[constructive-planning#1344](https://github.com/constructive-io/constructive-planning/issues/1344).
4951

5052
## Layout

examples/emit-bundle/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# emit-bundle — module → content-addressed bundle (+ fast deploy)
2+
3+
**Input:** [`../import-dump/output/shop/`](../import-dump/output/shop)
4+
5+
**Output:** [`output/shop.bundle.tar.gz`](output/shop.bundle.tar.gz) — the whole module projected into a single content-addressed archive (`pgpm-bundle.json`: manifest, deploy order, and every change's scripts).
6+
7+
```sh
8+
pgpm transform --granularity object --cwd examples/import-dump/output/shop \
9+
--out /tmp/roundtrip --emit-bundle "$PWD/examples/emit-bundle/output/shop.bundle.tar.gz"
10+
```
11+
12+
Bundles power `pgpm deploy --fast`: one-shot SQL plus a bulk migration ledger, reading a module's verified `sql/*.bundle.tar.gz` artifact when present and building it from `deploy/` when not. CI deploys the shop module with `--fast` and asserts the catalog is identical to the normal change-by-change deploy.
6.08 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# import-granularity — dial granularity at import time
2+
3+
**Input:** [`../import-dump/input/shop.v1.sql`](../import-dump/input/shop.v1.sql) — the same raw dump as [import-dump](../import-dump).
4+
5+
**Output:** [`output/shop-atomic-direct/`](output/shop-atomic-direct) — imported straight to **atomic** granularity in one step (no intermediate object-granularity module): each table change is an empty `CREATE TABLE` plus one `ALTER TABLE` per column/constraint.
6+
7+
```sh
8+
pgpm import examples/import-dump/input/shop.v1.sql --pkg shop-atomic-direct \
9+
--granularity atomic --out examples/import-granularity/output
10+
```
11+
12+
Demonstrates that the dials compose with any entry point: `import --granularity atomic``import` then `transform --granularity atomic`. CI proves the catalog is identical to every other variant.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Deploy: schemas/audit/procedures/log_order_change/procedure
2+
-- made with <3 @ constructive.io
3+
4+
-- requires: schemas/audit/schema
5+
6+
7+
CREATE FUNCTION audit.log_order_change() RETURNS trigger LANGUAGE plpgsql AS $$
8+
BEGIN
9+
INSERT INTO audit.change_log (table_name, row_id, operation)
10+
VALUES (TG_TABLE_NAME, NEW.id, TG_OP);
11+
RETURN NEW;
12+
END;
13+
$$;
14+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Deploy: schemas/audit/schema
2+
-- made with <3 @ constructive.io
3+
4+
5+
6+
7+
CREATE SCHEMA audit;
8+
9+
COMMENT ON SCHEMA audit IS 'Append-only change log for shop tables.';
10+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Deploy: schemas/audit/tables/change_log/table
2+
-- made with <3 @ constructive.io
3+
4+
-- requires: schemas/audit/schema
5+
6+
7+
CREATE TABLE audit.change_log (
8+
9+
);
10+
11+
ALTER TABLE audit.change_log
12+
ADD COLUMN id bigint
13+
GENERATED ALWAYS AS IDENTITY
14+
NOT NULL;
15+
16+
ALTER TABLE audit.change_log
17+
ADD COLUMN table_name text
18+
NOT NULL;
19+
20+
ALTER TABLE audit.change_log
21+
ADD COLUMN row_id uuid
22+
NOT NULL;
23+
24+
ALTER TABLE audit.change_log
25+
ADD COLUMN operation text
26+
NOT NULL;
27+
28+
ALTER TABLE audit.change_log
29+
ADD COLUMN changed_at timestamptz
30+
DEFAULT now()
31+
NOT NULL;
32+
33+
ALTER TABLE ONLY audit.change_log
34+
ADD CONSTRAINT change_log_pkey PRIMARY KEY (id);
35+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Deploy: schemas/shop/procedures/order_total/procedure
2+
-- made with <3 @ constructive.io
3+
4+
-- requires: schemas/shop/schema
5+
6+
7+
CREATE FUNCTION shop.order_total(
8+
p_order_id uuid
9+
) RETURNS int LANGUAGE sql STABLE AS $$
10+
SELECT COALESCE(SUM(quantity * unit_price_cents), 0)::integer
11+
FROM shop.order_items
12+
WHERE order_id = p_order_id;
13+
$$;
14+
15+
COMMENT ON FUNCTION shop.order_total(p_order_id uuid) IS 'Sum of line totals for an order, in cents.';
16+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Deploy: schemas/shop/schema
2+
-- made with <3 @ constructive.io
3+
4+
5+
6+
7+
CREATE SCHEMA shop;
8+
9+
COMMENT ON SCHEMA shop IS 'Storefront: customers, products, orders.';
10+
11+
GRANT USAGE ON SCHEMA shop TO app_user;
12+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Deploy: schemas/shop/sequences/order_number_seq
2+
-- made with <3 @ constructive.io
3+
4+
-- requires: schemas/shop/schema
5+
6+
7+
CREATE SEQUENCE shop.order_number_seq START 1000 INCREMENT 1 NO MINVALUE NO MAXVALUE CACHE 1;
8+

0 commit comments

Comments
 (0)