@pgpm/verify 0.4.0 → 0.6.0

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.
package/Makefile CHANGED
@@ -1,5 +1,5 @@
1
1
  EXTENSION = launchql-verify
2
- DATA = sql/launchql-verify--0.4.6.sql
2
+ DATA = sql/launchql-verify--0.5.0.sql
3
3
 
4
4
  PG_CONFIG = pg_config
5
5
  PGXS := $(shell $(PG_CONFIG) --pgxs)
package/README.md CHANGED
@@ -1,5 +1,509 @@
1
1
  # @pgpm/verify
2
2
 
3
- Verification utilities for LaunchQL deploy/verify/revert workflow.
3
+ Verification utilities for PostgreSQL extensions
4
4
 
5
- Provides essential verification functions used by other modules to validate database changes, including verify_table, verify_index, verify_function, and other assertion utilities.
5
+ ## Overview
6
+
7
+ `@pgpm/verify` is the foundational verification package used by all LaunchQL extensions. It provides SQL functions to verify the existence and correctness of database objects during deployment, testing, and migrations. This package is essential for the deploy/verify/revert pattern, ensuring that database changes are applied correctly and can be validated programmatically.
8
+
9
+ ## Features
10
+
11
+ - **Comprehensive Verification**: Verify tables, functions, schemas, indexes, triggers, views, domains, and roles
12
+ - **Universal Dependency**: Required by all 22 LaunchQL extension packages
13
+ - **Deploy/Verify/Revert Pattern**: Core component of safe database migrations
14
+ - **Testing Support**: Essential for integration and unit tests
15
+ - **Error Detection**: Catch deployment issues early with clear error messages
16
+ - **Pure plpgsql**: No external dependencies required
17
+
18
+ ## Installation
19
+
20
+ If you have `pgpm` installed:
21
+
22
+ ```bash
23
+ pgpm install @pgpm/verify
24
+ pgpm deploy
25
+ ```
26
+
27
+ This is a quick way to get started. The sections below provide more detailed installation options.
28
+
29
+ ### Prerequisites
30
+
31
+ ```bash
32
+ # Install pgpm globally
33
+ npm install -g pgpm
34
+
35
+ # Start PostgreSQL
36
+ pgpm docker start
37
+
38
+ # Set environment variables
39
+ eval "$(pgpm env)"
40
+ ```
41
+
42
+ ### Deploy
43
+
44
+ #### Option 1: Deploy by installing with pgpm
45
+
46
+ ```bash
47
+ pgpm install @pgpm/verify
48
+ pgpm deploy
49
+ ```
50
+
51
+ #### Option 2: Deploy from Package Directory
52
+
53
+ ```bash
54
+ cd packages/utils/verify
55
+ pgpm deploy --createdb
56
+ ```
57
+
58
+ #### Option 3: Deploy from Workspace Root
59
+
60
+ ```bash
61
+ # Install workspace dependencies
62
+ pnpm install
63
+
64
+ # Deploy with dependencies
65
+ pgpm deploy mydb1 --yes --createdb
66
+ ```
67
+
68
+ ## Core Functions
69
+
70
+ ### verify.verify_table(schema_name, table_name)
71
+
72
+ Verify that a table exists in the specified schema.
73
+
74
+ **Signature:**
75
+ ```sql
76
+ verify.verify_table(schema_name text, table_name text) RETURNS void
77
+ ```
78
+
79
+ **Usage:**
80
+ ```sql
81
+ -- Verify users table exists
82
+ SELECT verify.verify_table('public', 'users');
83
+
84
+ -- Verify in verify script
85
+ -- verify/schemas/public/tables/users/table.sql
86
+ SELECT verify.verify_table('public', 'users');
87
+ ```
88
+
89
+ ### verify.verify_function(function_name)
90
+
91
+ Verify that a function exists.
92
+
93
+ **Signature:**
94
+ ```sql
95
+ verify.verify_function(function_name text) RETURNS void
96
+ ```
97
+
98
+ **Usage:**
99
+ ```sql
100
+ -- Verify function exists
101
+ SELECT verify.verify_function('public.calculate_total');
102
+
103
+ -- Verify with schema prefix
104
+ SELECT verify.verify_function('utils.throw');
105
+ ```
106
+
107
+ ### verify.verify_schema(schema_name)
108
+
109
+ Verify that a schema exists.
110
+
111
+ **Signature:**
112
+ ```sql
113
+ verify.verify_schema(schema_name text) RETURNS void
114
+ ```
115
+
116
+ **Usage:**
117
+ ```sql
118
+ -- Verify schema exists
119
+ SELECT verify.verify_schema('public');
120
+ SELECT verify.verify_schema('app_jobs');
121
+ SELECT verify.verify_schema('status_public');
122
+ ```
123
+
124
+ ### verify.verify_index(schema_name, index_name)
125
+
126
+ Verify that an index exists in the specified schema.
127
+
128
+ **Signature:**
129
+ ```sql
130
+ verify.verify_index(schema_name text, index_name text) RETURNS void
131
+ ```
132
+
133
+ **Usage:**
134
+ ```sql
135
+ -- Verify index exists
136
+ SELECT verify.verify_index('public', 'users_email_idx');
137
+ SELECT verify.verify_index('app_jobs', 'jobs_priority_run_at_id_idx');
138
+ ```
139
+
140
+ ### verify.verify_trigger(trigger_name)
141
+
142
+ Verify that a trigger exists.
143
+
144
+ **Signature:**
145
+ ```sql
146
+ verify.verify_trigger(trigger_name text) RETURNS void
147
+ ```
148
+
149
+ **Usage:**
150
+ ```sql
151
+ -- Verify trigger exists
152
+ SELECT verify.verify_trigger('update_updated_at_trigger');
153
+ SELECT verify.verify_trigger('notify_worker');
154
+ ```
155
+
156
+ ### verify.verify_view(schema_name, view_name)
157
+
158
+ Verify that a view exists in the specified schema.
159
+
160
+ **Signature:**
161
+ ```sql
162
+ verify.verify_view(schema_name text, view_name text) RETURNS void
163
+ ```
164
+
165
+ **Usage:**
166
+ ```sql
167
+ -- Verify view exists
168
+ SELECT verify.verify_view('public', 'user_profiles_view');
169
+ SELECT verify.verify_view('status_public', 'achievements_summary');
170
+ ```
171
+
172
+ ### verify.verify_domain(schema_name, domain_name)
173
+
174
+ Verify that a domain type exists in the specified schema.
175
+
176
+ **Signature:**
177
+ ```sql
178
+ verify.verify_domain(schema_name text, domain_name text) RETURNS void
179
+ ```
180
+
181
+ **Usage:**
182
+ ```sql
183
+ -- Verify domain exists
184
+ SELECT verify.verify_domain('public', 'email');
185
+ SELECT verify.verify_domain('public', 'hostname');
186
+ SELECT verify.verify_domain('public', 'url');
187
+ ```
188
+
189
+ ### verify.verify_role(role_name)
190
+
191
+ Verify that a PostgreSQL role exists.
192
+
193
+ **Signature:**
194
+ ```sql
195
+ verify.verify_role(role_name text) RETURNS void
196
+ ```
197
+
198
+ **Usage:**
199
+ ```sql
200
+ -- Verify role exists
201
+ SELECT verify.verify_role('authenticated');
202
+ SELECT verify.verify_role('anonymous');
203
+ SELECT verify.verify_role('administrator');
204
+ ```
205
+
206
+ ## Usage in Deploy/Verify/Revert Pattern
207
+
208
+ ### Verify Scripts
209
+
210
+ Every deploy script should have a corresponding verify script:
211
+
212
+ ```
213
+ packages/example/
214
+ ├── deploy/
215
+ │ └── schemas/public/tables/users/table.sql
216
+ ├── verify/
217
+ │ └── schemas/public/tables/users/table.sql
218
+ └── revert/
219
+ └── schemas/public/tables/users/table.sql
220
+ ```
221
+
222
+ **deploy/schemas/public/tables/users/table.sql:**
223
+ ```sql
224
+ BEGIN;
225
+
226
+ CREATE TABLE public.users (
227
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
228
+ email text NOT NULL UNIQUE,
229
+ name text NOT NULL,
230
+ created_at timestamptz DEFAULT now()
231
+ );
232
+
233
+ COMMIT;
234
+ ```
235
+
236
+ **verify/schemas/public/tables/users/table.sql:**
237
+ ```sql
238
+ SELECT verify.verify_table('public', 'users');
239
+ ```
240
+
241
+ **revert/schemas/public/tables/users/table.sql:**
242
+ ```sql
243
+ BEGIN;
244
+ DROP TABLE IF EXISTS public.users;
245
+ COMMIT;
246
+ ```
247
+
248
+ ### Complex Verification
249
+
250
+ Verify multiple related objects:
251
+
252
+ **verify/schemas/app_jobs/tables/jobs/table.sql:**
253
+ ```sql
254
+ -- Verify table exists
255
+ SELECT verify.verify_table('app_jobs', 'jobs');
256
+
257
+ -- Verify indexes exist
258
+ SELECT verify.verify_index('app_jobs', 'jobs_priority_run_at_id_idx');
259
+ SELECT verify.verify_index('app_jobs', 'jobs_locked_by_idx');
260
+
261
+ -- Verify triggers exist
262
+ SELECT verify.verify_trigger('update_timestamps');
263
+ SELECT verify.verify_trigger('notify_worker');
264
+ ```
265
+
266
+ ## Usage in Testing
267
+
268
+ ### Integration Tests
269
+
270
+ Use verify functions in test setup and assertions:
271
+
272
+ ```javascript
273
+ describe('User Table', () => {
274
+ it('should create users table', async () => {
275
+ await pg.query(`
276
+ CREATE TABLE public.users (
277
+ id uuid PRIMARY KEY,
278
+ email text NOT NULL
279
+ )
280
+ `);
281
+
282
+ // Verify table was created
283
+ await pg.query(`SELECT verify.verify_table('public', 'users')`);
284
+ });
285
+
286
+ it('should create email index', async () => {
287
+ await pg.query(`
288
+ CREATE INDEX users_email_idx ON public.users(email)
289
+ `);
290
+
291
+ // Verify index was created
292
+ await pg.query(`SELECT verify.verify_index('public', 'users_email_idx')`);
293
+ });
294
+ });
295
+ ```
296
+
297
+ ### Verification in Migrations
298
+
299
+ Ensure migrations are applied correctly:
300
+
301
+ ```sql
302
+ -- Migration script
303
+ DO $$
304
+ BEGIN
305
+ -- Create schema
306
+ CREATE SCHEMA IF NOT EXISTS app_jobs;
307
+
308
+ -- Verify schema was created
309
+ PERFORM verify.verify_schema('app_jobs');
310
+
311
+ -- Create table
312
+ CREATE TABLE app_jobs.jobs (
313
+ id serial PRIMARY KEY,
314
+ task_identifier text NOT NULL
315
+ );
316
+
317
+ -- Verify table was created
318
+ PERFORM verify.verify_table('app_jobs', 'jobs');
319
+
320
+ RAISE NOTICE 'Migration completed successfully';
321
+ END $$;
322
+ ```
323
+
324
+ ## Integration Examples
325
+
326
+ ### With All LaunchQL Extensions
327
+
328
+ Every LaunchQL extension depends on `@pgpm/verify`:
329
+
330
+ **package.json:**
331
+ ```json
332
+ {
333
+ "dependencies": {
334
+ "@pgpm/verify": "workspace:*"
335
+ }
336
+ }
337
+ ```
338
+
339
+ **Verification in extensions:**
340
+ ```sql
341
+ -- @pgpm/types verifies domains
342
+ SELECT verify.verify_domain('public', 'email');
343
+ SELECT verify.verify_domain('public', 'hostname');
344
+
345
+ -- @pgpm/jobs verifies tables and functions
346
+ SELECT verify.verify_table('app_jobs', 'jobs');
347
+ SELECT verify.verify_function('app_jobs.add_job');
348
+
349
+ -- @pgpm/achievements verifies schemas and triggers
350
+ SELECT verify.verify_schema('status_public');
351
+ SELECT verify.verify_trigger('achievement_trigger');
352
+ ```
353
+
354
+ ### With CI/CD Pipeline
355
+
356
+ Verify deployments in CI:
357
+
358
+ ```bash
359
+ #!/bin/bash
360
+ # scripts/verify-deployment.sh
361
+
362
+ # Deploy changes
363
+ pgpm deploy test_db --yes --recursive --createdb
364
+
365
+ # Run verification
366
+ pgpm verify test_db --yes --recursive
367
+
368
+ # If verification fails, revert
369
+ if [ $? -ne 0 ]; then
370
+ echo "Verification failed, reverting..."
371
+ pgpm revert test_db --yes --recursive
372
+ exit 1
373
+ fi
374
+
375
+ echo "Deployment verified successfully"
376
+ ```
377
+
378
+ ## Error Handling
379
+
380
+ Verification functions throw clear errors when objects don't exist:
381
+
382
+ ```sql
383
+ -- Table doesn't exist
384
+ SELECT verify.verify_table('public', 'nonexistent_table');
385
+ -- ERROR: Table public.nonexistent_table does not exist
386
+
387
+ -- Function doesn't exist
388
+ SELECT verify.verify_function('public.nonexistent_function');
389
+ -- ERROR: Function public.nonexistent_function does not exist
390
+
391
+ -- Schema doesn't exist
392
+ SELECT verify.verify_schema('nonexistent_schema');
393
+ -- ERROR: Schema nonexistent_schema does not exist
394
+ ```
395
+
396
+ ## Best Practices
397
+
398
+ 1. **Always Create Verify Scripts**: Every deploy script should have a matching verify script
399
+ 2. **Verify Immediately**: Run verification right after deployment
400
+ 3. **Verify Dependencies**: Check that required objects exist before creating dependent objects
401
+ 4. **Use in Tests**: Incorporate verification in integration tests
402
+ 5. **CI Integration**: Make verification part of your CI/CD pipeline
403
+ 6. **Clear Naming**: Use descriptive names that match your deploy scripts
404
+
405
+ ## Use Cases
406
+
407
+ - **Safe Migrations**: Ensure database changes are applied correctly
408
+ - **Deployment Validation**: Verify production deployments
409
+ - **Testing**: Validate test database setup
410
+ - **CI/CD**: Automated verification in continuous integration
411
+ - **Rollback Safety**: Confirm revert scripts work correctly
412
+ - **Documentation**: Self-documenting database structure
413
+ - **Debugging**: Quickly identify missing database objects
414
+
415
+ ## Testing
416
+
417
+ ```bash
418
+ pnpm test
419
+ ```
420
+
421
+ ## Dependencies
422
+
423
+ None - this is the foundational package that all other packages depend on.
424
+
425
+ ## Development
426
+
427
+ See the [Development](#development-1) section below for information on working with this package.
428
+
429
+ ---
430
+
431
+ ## Development
432
+
433
+ ### **Before You Begin**
434
+
435
+ ```bash
436
+ # 1. Install pgpm
437
+ npm install -g pgpm
438
+
439
+ # 2. Start Postgres (Docker or local)
440
+ pgpm docker start
441
+
442
+ # 3. Load PG* environment variables (PGHOST, PGUSER, ...)
443
+ eval "$(pgpm env)"
444
+ ```
445
+
446
+ ---
447
+
448
+ ### **Starting a New Project**
449
+
450
+ ```bash
451
+ # 1. Create a workspace
452
+ pgpm init --workspace
453
+ cd my-app
454
+
455
+ # 2. Create your first module
456
+ pgpm init
457
+
458
+ # 3. Add a migration
459
+ pgpm add some_change
460
+
461
+ # 4. Deploy (auto-creates database)
462
+ pgpm deploy --createdb
463
+ ```
464
+
465
+ ---
466
+
467
+ ### **Working With an Existing Project**
468
+
469
+ ```bash
470
+ # 1. Clone and enter the project
471
+ git clone <repo> && cd <project>
472
+
473
+ # 2. Install dependencies
474
+ pnpm install
475
+
476
+ # 3. Deploy locally
477
+ pgpm deploy --createdb
478
+ ```
479
+
480
+ ---
481
+
482
+ ### **Testing a Module Inside a Workspace**
483
+
484
+ ```bash
485
+ # 1. Install workspace deps
486
+ pnpm install
487
+
488
+ # 2. Enter the module directory
489
+ cd packages/<some-module>
490
+
491
+ # 3. Run tests in watch mode
492
+ pnpm test:watch
493
+ ```
494
+
495
+ ## Related Tooling
496
+
497
+ * [pgpm](https://github.com/launchql/launchql/tree/main/packages/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
498
+ * [pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
499
+ * [supabase-test](https://github.com/launchql/launchql/tree/main/packages/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
500
+ * [graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
501
+ * [pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
502
+ * [libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
503
+ * [pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
504
+
505
+ ## Disclaimer
506
+
507
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
508
+
509
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
@@ -1,6 +1,6 @@
1
1
  # launchql-verify extension
2
2
  comment = 'launchql-verify extension'
3
- default_version = '0.4.6'
3
+ default_version = '0.5.0'
4
4
  module_pathname = '$libdir/launchql-verify'
5
5
  requires = 'plpgsql'
6
6
  relocatable = false
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@pgpm/verify",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Verification utilities for LaunchQL deploy/verify/revert workflow",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "scripts": {
9
- "bundle": "lql package",
9
+ "bundle": "pgpm package",
10
10
  "test": "jest",
11
11
  "test:watch": "jest --watch"
12
12
  },
13
13
  "devDependencies": {
14
- "@launchql/cli": "^4.9.0"
14
+ "pgpm": "^0.2.0"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/launchql/extensions"
18
+ "url": "https://github.com/launchql/pgpm-modules"
19
19
  },
20
- "homepage": "https://github.com/launchql/extensions",
20
+ "homepage": "https://github.com/launchql/pgpm-modules",
21
21
  "bugs": {
22
- "url": "https://github.com/launchql/extensions/issues"
22
+ "url": "https://github.com/launchql/pgpm-modules/issues"
23
23
  },
24
- "gitHead": "cc9f52a335caa6e21ee7751b04b77c84ce6cb809"
24
+ "gitHead": "c7d0eae588d7a764b382a330c8b853b341b13fb2"
25
25
  }
File without changes