Skip to content

Commit a57d170

Browse files
committed
fix: rebuild with proper pgpm workspace scaffolding
Replaces manual file creation with proper pgpm workspace patterns: - .eslintrc.json (legacy format) instead of eslint.config.js (flat) - Makefile + bin/install.sh for Docker-based module installation - sql/ directories with bundled extension SQL per package - jest.config.js using testMatch (no explicit tsconfig reference) - Root tsconfig.json with proper exclude array - pgpm.json with InsForge role mappings - docker-compose.yml using ghcr.io/insforge/postgres:v15.13.2 - BEGIN/COMMIT transaction wrapping in deploy/revert SQL - BEGIN/ROLLBACK in verify SQL
1 parent e81bad5 commit a57d170

24 files changed

Lines changed: 459 additions & 432 deletions

.eslintrc.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:@typescript-eslint/recommended",
11+
"prettier"
12+
],
13+
"overrides": [],
14+
"parser": "@typescript-eslint/parser",
15+
"parserOptions": {
16+
"ecmaVersion": "latest",
17+
"sourceType": "module"
18+
},
19+
"plugins": [
20+
"@typescript-eslint",
21+
"simple-import-sort",
22+
"unused-imports"
23+
],
24+
"rules": {
25+
"indent": [
26+
"error",
27+
2
28+
],
29+
"quotes": [
30+
"error",
31+
"single",
32+
{
33+
"avoidEscape": true,
34+
"allowTemplateLiterals": true
35+
}
36+
],
37+
"quote-props": [
38+
"error",
39+
"as-needed"
40+
],
41+
"semi": [
42+
"error",
43+
"always"
44+
],
45+
"simple-import-sort/imports": 1,
46+
"simple-import-sort/exports": 1,
47+
"unused-imports/no-unused-imports": 1,
48+
"@typescript-eslint/no-unused-vars": [
49+
1,
50+
{
51+
"argsIgnorePattern": "React|res|next|^_"
52+
}
53+
],
54+
"@typescript-eslint/no-explicit-any": 0,
55+
"@typescript-eslint/no-var-requires": 0,
56+
"no-console": 0,
57+
"@typescript-eslint/ban-ts-comment": 0,
58+
"prefer-const": 0,
59+
"no-case-declarations": 0,
60+
"no-implicit-globals": 0,
61+
"@typescript-eslint/no-unsafe-declaration-merging": 0
62+
}
63+
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
**/node_modules/
22
**/.DS_Store
33
**/dist
4-
**/yarn-error.log
4+
**/pnpm-debug.log
55
lerna-debug.log
66
**/__tests__/**/*.js
77
**/__tests__/**/*.test.d.ts

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
up:
3+
docker-compose up -d
4+
5+
down:
6+
docker-compose down -v
7+
8+
ssh:
9+
docker exec -it postgres /bin/bash
10+
11+
roles:
12+
pgpm admin-users add --test --yes
13+
14+
install:
15+
docker exec postgres /sql-bin/install.sh

README.md

Lines changed: 4 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,15 @@ A friendly playground for building and validating InsForge Row-Level Security (R
1111

1212
Built with [`insforge-test`](https://www.npmjs.com/package/insforge-test) — an InsForge-optimized version of [`pgsql-test`](https://www.npmjs.com/package/pgsql-test) for instant, isolated Postgres test databases with automatic rollbacks and InsForge defaults.
1313

14-
## Features
14+
## Developing
1515

16-
- 🔐 **RLS Policy Testing** - Real-world examples with pets table and user-scoped access
17-
- 🧪 **Comprehensive Test Suite** - End-to-end tests against InsForge auth schema
18-
- 🐘 **InsForge Docker Stack** - Uses `ghcr.io/insforge/postgres` for native InsForge environment
19-
-**Jest Integration** - Fast, isolated tests with automatic rollbacks
20-
- 🚀 **CI/CD Ready** - GitHub Actions workflows with InsForge Docker services
21-
- 🧩 **Modular Architecture** - Reusable pgpm schema packages you can extend
22-
23-
## Quick Start
24-
25-
```bash
26-
# Start InsForge Postgres via Docker
27-
docker compose up -d
28-
29-
# Install dependencies
16+
```sh
17+
docker-compose up -d
3018
pnpm install
31-
32-
# Run tests in watch mode
3319
cd packages/hello-world
3420
pnpm test:watch
3521
```
3622

37-
## Repository Structure
38-
39-
This is a pgpm workspace combining `pnpm` and `pgpm` for modular Postgres packages:
40-
41-
- **`packages/insforge`** - InsForge base schema: auth functions, users table, auto-RLS event triggers
42-
- **`packages/hello-world`** - Demo extension showcasing RLS with pets table
43-
4423
## InsForge Roles
4524

4625
InsForge uses three built-in PostgreSQL roles:
@@ -53,80 +32,9 @@ InsForge uses three built-in PostgreSQL roles:
5332

5433
These roles are mapped in `pgpm.json` and used by `insforge-test` for RLS testing.
5534

56-
## Testing
57-
58-
Run tests in different modes:
59-
60-
```bash
61-
# Run all tests from root
62-
pnpm test
63-
64-
# Watch mode for specific package
65-
cd packages/hello-world
66-
pnpm test:watch
67-
```
68-
69-
## Docker Setup
70-
71-
### Using Docker Compose (recommended)
72-
73-
```bash
74-
docker compose up -d
75-
```
76-
77-
This starts the InsForge Postgres image (`ghcr.io/insforge/postgres:v15.13.2`) on port 5432.
78-
79-
### Using Docker directly
80-
81-
```bash
82-
docker run -d \
83-
--name insforge-postgres \
84-
-e POSTGRES_USER=postgres \
85-
-e POSTGRES_PASSWORD=postgres \
86-
-e POSTGRES_DB=insforge \
87-
-p 5432:5432 \
88-
ghcr.io/insforge/postgres:v15.13.2
89-
```
90-
91-
## Requirements
92-
93-
- Node.js 20+
94-
- pnpm 10+
95-
- Docker (for running InsForge Postgres)
96-
97-
## Troubleshooting
98-
99-
If you encounter connection issues, set your environment variables:
100-
101-
```bash
102-
export PGPORT=5432
103-
export PGHOST=localhost
104-
export PGUSER=postgres
105-
export PGPASSWORD=postgres
106-
```
107-
108-
Common issues:
109-
- Ensure InsForge Postgres container is running (`docker compose ps`)
110-
- Check that port 5432 is available and not used by another Postgres instance
111-
- Use Node.js 20+ to avoid compatibility issues
112-
113-
## Education and Tutorials
114-
115-
1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
116-
Get started with modular databases in minutes. Install prerequisites and deploy your first module.
117-
118-
2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
119-
Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
120-
121-
3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
122-
Master the workflow for adding, organizing, and managing database changes with pgpm.
123-
124-
4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
125-
Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
126-
12735
## Credits
12836

129-
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
37+
**Built by [Constructive](https://constructive.io) — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
13038

13139
## Disclaimer
13240

bin/install.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Define colors and styles
5+
GREEN="\033[0;32m"
6+
BOLD="\033[1m"
7+
RESET="\033[0m"
8+
CYAN="\033[0;36m"
9+
YELLOW="\033[1;33m"
10+
11+
install_sql_modules() {
12+
local base_dir="$1"
13+
local label
14+
label=$(basename "$base_dir")
15+
16+
if [[ ! -d "$base_dir" ]]; then
17+
echo -e "${YELLOW}Warning:${RESET} SQL module directory '${CYAN}${base_dir}${RESET}' does not exist. Skipping..."
18+
return
19+
fi
20+
21+
echo -e "${GREEN}Installing SQL modules from:${RESET} ${CYAN}${base_dir}${RESET}"
22+
find "$base_dir" -type f -name "sqitch.plan" | while read -r plan_file; do
23+
local dir rel_path pkg_name
24+
dir=$(dirname "$plan_file")
25+
rel_path="${dir#"$base_dir"/}" # strip base_dir prefix
26+
pkg_name="${BOLD}${GREEN}${rel_path}${RESET}" # colorize and bold package name
27+
echo -e "${CYAN}→ Installing in:${RESET} ${pkg_name}"
28+
(cd "$dir" && make install)
29+
done
30+
}
31+
32+
install_sql_modules "/sql-packages"

docker-compose.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
services:
22
postgres:
3+
container_name: postgres
34
image: ghcr.io/insforge/postgres:v15.13.2
45
command: postgres -c config_file=/etc/postgresql/postgresql.conf
56
environment:
6-
- POSTGRES_USER=${POSTGRES_USER:-postgres}
7-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
8-
- POSTGRES_DB=${POSTGRES_DB:-insforge}
9-
volumes:
10-
- postgres-data:/var/lib/postgresql/data
7+
- POSTGRES_USER=postgres
8+
- POSTGRES_PASSWORD=postgres
9+
- POSTGRES_DB=insforge
1110
ports:
12-
- "${POSTGRES_PORT:-5432}:5432"
13-
healthcheck:
14-
test: ["CMD-SHELL", "pg_isready -U postgres"]
15-
interval: 5s
16-
timeout: 5s
17-
retries: 5
18-
19-
volumes:
20-
postgres-data:
11+
- "5432:5432"
12+
expose:
13+
- "5432"
14+
volumes:
15+
- ./bin:/sql-bin
16+
- ./packages:/sql-packages

eslint.config.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

lerna.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3-
"version": "0.1.0",
4-
"npmClient": "pnpm"
3+
"version": "independent",
4+
"npmClient": "pnpm",
5+
"npmClientArgs": [
6+
"--frozen-lockfile"
7+
],
8+
"packages": [
9+
"packages/*"
10+
],
11+
"registry": "https://registry.npmjs.org",
12+
"command": {
13+
"create": {
14+
"homepage": "https://github.com/constructive-io/insforge-test-suite",
15+
"license": "SEE LICENSE IN LICENSE",
16+
"access": "restricted"
17+
},
18+
"publish": {
19+
"allowBranch": "main",
20+
"message": "chore(release): publish",
21+
"conventionalCommits": true
22+
}
23+
}
524
}

0 commit comments

Comments
 (0)