Skip to content

Latest commit

 

History

History
81 lines (60 loc) · 1.14 KB

example.md

File metadata and controls

81 lines (60 loc) · 1.14 KB

Example

Requires Docker and PostgreSQL client binaries.

Run PostgreSQL

docker run \
  -e POSTGRES_HOST_AUTH_METHOD=trust \
  -e POSTGRES_USER="$USER" \
  -p 5432:5432 \
  --rm \
  postgres

For the remaining steps, open a new terminal session and run

export PGHOST=localhost

Create source database

createdb source

PGDATABASE=source psql -c '
CREATE TABLE parent (
    id int PRIMARY KEY
);

CREATE TABLE child (
    id int PRIMARY KEY,
    parent_id int REFERENCES parent (id)
);

INSERT INTO parent (id)
VALUES (1), (2);

INSERT INTO child (id, parent_id)
VALUES (1, 1), (2, 1), (3, 2);
'

Dump a slice

PGDATABASE=source slicedb schema > schema.json
PGDATABASE=source slicedb dump --include-schema --root public.parent 'id = 1' --schema schema.json > slice.zip

Create target database

createdb target

Restore a slice

PGDATABASE=target slicedb restore --include-schema < slice.zip

Inspect the result

PGDATABASE=target psql -c 'TABLE parent' -c 'TABLE child'
 id
----
  1
(1 row)

 id | parent_id
----+-----------
  1 |         1
  2 |         1
(2 rows)