Skip to content

Latest commit

 

History

History
100 lines (69 loc) · 2.06 KB

File metadata and controls

100 lines (69 loc) · 2.06 KB

Quickstart: Constructive + PGPM

Constructive provides GraphQL server and code generation tools, while PGPM handles database migrations and packages. Install both for the complete workflow.

1. Install the CLIs

npm install -g @constructive-io/cli pgpm

2. Initialize a workspace

Generate a workspace along with its default services configuration:

pgpm init workspace # then enter workspace name
cd myworkspace

3. Run Postgres locally

The workspace includes a docker-compose.yml you can use to start Postgres and supporting services:

docker-compose up -d

If you already have Postgres installed locally, just ensure it is running and accessible.

4. Create a module & add changes

pgpm init
cd packages/mymodule

# Add schema
pgpm add --change schemas/myschema

# Add table (depends on schema)
pgpm add --change schemas/myschema/tables/mytable --requires schemas/myschema

5. Example generated SQL

deploy/schemas/myschema.sql

-- Deploy: schemas/myschema to pg
-- made with <3 @ constructive.io
CREATE SCHEMA myschema;

deploy/schemas/myschema/tables/mytable.sql

-- Deploy: schemas/myschema/tables/mytable to pg
-- made with <3 @ constructive.io
-- requires: schemas/myschema

CREATE TABLE myschema.mytable (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL
);

6. Deploy to Postgres

pgpm deploy --database testdb --createdb --yes

Sample output highlights:

  • Creates database testdb
  • Installs declared extensions (citext, pgcrypto)
  • Initializes migration schema
  • Deploys schema + table successfully
[deploy] SUCCESS: Starting deployment to database testdb...
[migrate] SUCCESS: Successfully deployed: schemas/myschema
[migrate] SUCCESS: Successfully deployed: schemas/myschema/tables/mytable
[deploy] SUCCESS: Deployment complete for mymodule.

7. Explore with GraphiQL

cnc explorer

http://localhost:5555/graphiql (default) http://myschema.testdb.localhost:5555/graphiql (specific to a schema)

8. Start GraphQL Server

cnc server