@xubylele/schema-forge 1.12.2 → 1.13.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/README.md CHANGED
@@ -15,6 +15,8 @@ A modern CLI tool for database schema management with a clean DSL and automatic
15
15
  - **Constraint Diffing** - Detects UNIQUE and PRIMARY KEY changes with deterministic constraint names
16
16
  - **Live PostgreSQL Introspection** - Extract normalized schema directly from `information_schema`
17
17
  - **Policy (RLS) support** - Define Row Level Security policies in the DSL: `for select|insert|update|delete|all`, optional `to role1 role2` (e.g. `anon`, `authenticated`). Invalid policies produce clear CLI errors during validation. See [RLS policy patterns](https://github.com/xubylele/schema-forge-core/blob/main/docs/rls-policy-patterns.md) for user-owned rows, public read/authenticated write, and multi-tenant examples.
18
+ - **Index support** - Define regular, unique, expression, and partial indexes directly in DSL and generate deterministic create/drop operations.
19
+ - **View support** - Define SQL views in DSL and generate create/replace/drop view operations.
18
20
 
19
21
  ## Installation
20
22
 
@@ -41,7 +43,7 @@ const result = await generate({ name: 'MyMigration' });
41
43
  if (result.exitCode !== EXIT_CODES.SUCCESS) process.exit(result.exitCode);
42
44
  ```
43
45
 
44
- **Exports:** `init`, `generate`, `diff`, `doctor`, `validate`, `introspect`, `importSchema` (each returns `Promise<RunResult>`), `RunResult` (`{ exitCode: number }`), `EXIT_CODES`, and option types (`InitOptions`, `GenerateOptions`, `DiffOptions`, etc.). Entrypoint: `@xubylele/schema-forge/api`. Exit code semantics: [docs/exit-codes.json](docs/exit-codes.json).
46
+ **Exports:** `init`, `generate`, `diff`, `plan`, `preview`, `doctor`, `validate`, `introspect`, `importSchema` (each returns `Promise<RunResult>`), `RunResult` (`{ exitCode: number }`), `EXIT_CODES`, and option types (`InitOptions`, `GenerateOptions`, `DiffOptions`, etc.). Entrypoint: `@xubylele/schema-forge/api`. Exit code semantics: [docs/exit-codes.json](docs/exit-codes.json).
45
47
 
46
48
  ## Development
47
49
 
@@ -253,6 +255,37 @@ Shows what SQL would be generated if you ran `generate`. Useful for previewing c
253
255
 
254
256
  When `--url` (or `DATABASE_URL`) is provided, `diff` compares your target DSL schema against the live PostgreSQL schema introspected from `information_schema`.
255
257
 
258
+ ### `schema-forge plan`
259
+
260
+ Preview migration operations as human-readable plan lines.
261
+
262
+ ```bash
263
+ schema-forge plan [--safe] [--force]
264
+ ```
265
+
266
+ **Options:**
267
+
268
+ - `--safe` - Block execution if destructive operations are detected (exits with error)
269
+ - `--force` - Bypass safety checks and proceed with destructive operations (shows warning)
270
+ - `--url` - PostgreSQL connection URL for live database plan (fallback: `DATABASE_URL`)
271
+ - `--schema` - Comma-separated schema names to introspect (default: `public`)
272
+
273
+ Example output:
274
+
275
+ ```text
276
+ + create table users
277
+ + create index idx_users_email on users
278
+ ~ replace view active_users
279
+ ```
280
+
281
+ ### `schema-forge preview`
282
+
283
+ Alias for `schema-forge plan`.
284
+
285
+ ```bash
286
+ schema-forge preview [--safe] [--force]
287
+ ```
288
+
256
289
  ### `schema-forge import`
257
290
 
258
291
  Reconstruct `schemaforge/schema.sf` from existing PostgreSQL/Supabase SQL migrations.
@@ -601,6 +634,25 @@ using true
601
634
 
602
635
  Invalid policies (missing table, invalid command, or no expressions) fail `schema-forge validate` with a clear error message. For common patterns (user-owned rows, public read / authenticated write, multi-tenant), see [RLS policy patterns](https://github.com/xubylele/schema-forge-core/blob/main/docs/rls-policy-patterns.md) in the core package.
603
636
 
637
+ ### Indexes
638
+
639
+ Indexes are declared at the top level and target an existing table.
640
+
641
+ ```sql
642
+ index idx_users_email on users(email)
643
+ index idx_users_lower_email on users((lower(email)))
644
+ index idx_active_users on users(id) where is_active = true
645
+ index unique idx_users_handle on users(handle)
646
+ ```
647
+
648
+ ### Views
649
+
650
+ Views are declared at the top level with a SQL query body.
651
+
652
+ ```sql
653
+ view active_users as select id, email from users where is_active = true
654
+ ```
655
+
604
656
  ### Examples
605
657
 
606
658
  #### Simple table
@@ -692,10 +744,11 @@ A typical development workflow looks like this:
692
744
 
693
745
  1. **Initialize** - `schema-forge init` or `schema-forge init supabase` (one time)
694
746
  2. **Edit schema** - Modify `schemaforge/schema.sf`
695
- 3. **Preview changes** - `schema-forge diff` (optional)
696
- 4. **Generate migration** - `schema-forge generate --name "description"`
697
- 5. **Apply migration** - Run the generated SQL against your database
698
- 6. **Repeat** - Continue editing and generating migrations as needed
747
+ 3. **Preview operations** - `schema-forge plan` (optional)
748
+ 4. **Preview SQL** - `schema-forge diff` (optional)
749
+ 5. **Generate migration** - `schema-forge generate --name "description"`
750
+ 6. **Apply migration** - Run the generated SQL against your database
751
+ 7. **Repeat** - Continue editing and generating migrations as needed
699
752
 
700
753
  ## Tips
701
754
 
package/dist/api.d.ts CHANGED
@@ -35,6 +35,16 @@ interface IntrospectOptions {
35
35
  out?: string;
36
36
  }
37
37
 
38
+ interface PlanOptions {
39
+ safe?: boolean;
40
+ force?: boolean;
41
+ url?: string;
42
+ schema?: string;
43
+ }
44
+
45
+ interface PreviewOptions extends PlanOptions {
46
+ }
47
+
38
48
  interface ValidateOptions {
39
49
  json?: boolean;
40
50
  url?: string;
@@ -57,7 +67,9 @@ declare function generate(options?: GenerateOptions): Promise<RunResult>;
57
67
  declare function diff(options?: DiffOptions): Promise<RunResult>;
58
68
  declare function doctor(options?: DoctorOptions): Promise<RunResult>;
59
69
  declare function validate(options?: ValidateOptions): Promise<RunResult>;
70
+ declare function plan(options?: PlanOptions): Promise<RunResult>;
71
+ declare function preview(options?: PreviewOptions): Promise<RunResult>;
60
72
  declare function introspect(options?: IntrospectOptions): Promise<RunResult>;
61
73
  declare function importSchema(inputPath: string, options?: ImportOptions): Promise<RunResult>;
62
74
 
63
- export { type DiffOptions, type DoctorOptions, EXIT_CODES, type GenerateOptions, type ImportOptions, type InitOptions, type IntrospectOptions, type RunResult, type ValidateOptions, diff, doctor, generate, importSchema, init, introspect, validate };
75
+ export { type DiffOptions, type DoctorOptions, EXIT_CODES, type GenerateOptions, type ImportOptions, type InitOptions, type IntrospectOptions, type PlanOptions, type PreviewOptions, type RunResult, type ValidateOptions, diff, doctor, generate, importSchema, init, introspect, plan, preview, validate };