@tejasanik/postgres-mcp-server 2.1.1 → 2.2.1
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 +163 -95
- package/dist/db-manager/index.js +7 -0
- package/dist/db-manager/validation.js +54 -0
- package/dist/db-manager.js +589 -26
- package/dist/index.js +141 -11
- package/dist/tools/analysis-tools.js +53 -49
- package/dist/tools/schema-tools.js +174 -92
- package/dist/tools/server-tools.js +5 -2
- package/dist/tools/sql/utils/connection-utils.js +129 -0
- package/dist/tools/sql/utils/constants.js +55 -0
- package/dist/tools/sql/utils/dry-run-utils.js +173 -0
- package/dist/tools/sql/utils/file-handler.js +150 -0
- package/dist/tools/sql/utils/index.js +12 -0
- package/dist/tools/sql/utils/result-formatter.js +154 -0
- package/dist/tools/sql/utils/sql-parser.js +468 -0
- package/dist/tools/sql-tools.js +383 -532
- package/dist/utils/validation.js +335 -72
- package/package.json +10 -4
- package/dist/__tests__/analysis-tools.test.d.ts +0 -2
- package/dist/__tests__/analysis-tools.test.d.ts.map +0 -1
- package/dist/__tests__/analysis-tools.test.js +0 -294
- package/dist/__tests__/analysis-tools.test.js.map +0 -1
- package/dist/__tests__/db-manager.test.d.ts +0 -2
- package/dist/__tests__/db-manager.test.d.ts.map +0 -1
- package/dist/__tests__/db-manager.test.js +0 -410
- package/dist/__tests__/db-manager.test.js.map +0 -1
- package/dist/__tests__/mcp-server.test.d.ts +0 -13
- package/dist/__tests__/mcp-server.test.d.ts.map +0 -1
- package/dist/__tests__/mcp-server.test.js +0 -146
- package/dist/__tests__/mcp-server.test.js.map +0 -1
- package/dist/__tests__/schema-tools.test.d.ts +0 -2
- package/dist/__tests__/schema-tools.test.d.ts.map +0 -1
- package/dist/__tests__/schema-tools.test.js +0 -171
- package/dist/__tests__/schema-tools.test.js.map +0 -1
- package/dist/__tests__/server-tools.test.d.ts +0 -2
- package/dist/__tests__/server-tools.test.d.ts.map +0 -1
- package/dist/__tests__/server-tools.test.js +0 -137
- package/dist/__tests__/server-tools.test.js.map +0 -1
- package/dist/__tests__/sql-tools.test.d.ts +0 -2
- package/dist/__tests__/sql-tools.test.d.ts.map +0 -1
- package/dist/__tests__/sql-tools.test.js +0 -1912
- package/dist/__tests__/sql-tools.test.js.map +0 -1
- package/dist/__tests__/validation.test.d.ts +0 -2
- package/dist/__tests__/validation.test.d.ts.map +0 -1
- package/dist/__tests__/validation.test.js +0 -203
- package/dist/__tests__/validation.test.js.map +0 -1
- package/dist/db-manager.d.ts +0 -83
- package/dist/db-manager.d.ts.map +0 -1
- package/dist/db-manager.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/tools/analysis-tools.d.ts +0 -25
- package/dist/tools/analysis-tools.d.ts.map +0 -1
- package/dist/tools/analysis-tools.js.map +0 -1
- package/dist/tools/index.d.ts +0 -5
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/schema-tools.d.ts +0 -22
- package/dist/tools/schema-tools.d.ts.map +0 -1
- package/dist/tools/schema-tools.js.map +0 -1
- package/dist/tools/server-tools.d.ts +0 -61
- package/dist/tools/server-tools.d.ts.map +0 -1
- package/dist/tools/server-tools.js.map +0 -1
- package/dist/tools/sql-tools.d.ts +0 -194
- package/dist/tools/sql-tools.d.ts.map +0 -1
- package/dist/tools/sql-tools.js.map +0 -1
- package/dist/types.d.ts +0 -394
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/retry.d.ts +0 -21
- package/dist/utils/retry.d.ts.map +0 -1
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -27
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,101 +4,6 @@ A Model Context Protocol (MCP) server for PostgreSQL database management and ana
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
## 🤖 Agent Experience (AX) - Claude Code Review
|
|
8
|
-
|
|
9
|
-
**Tested by:** Claude Code (Sonnet 4.5)
|
|
10
|
-
**Use Case:** Database deployment, schema exploration, and SQL migration
|
|
11
|
-
**Rating:** ⭐⭐⭐⭐⭐ (9.5/10)
|
|
12
|
-
|
|
13
|
-
### What I Loved
|
|
14
|
-
|
|
15
|
-
**1. Clear, Structured Responses**
|
|
16
|
-
Every response includes connection context (`server`, `database`, `schema`), making it crystal clear which environment I'm working in. This is essential when managing multiple databases - I never have to guess where a query ran.
|
|
17
|
-
|
|
18
|
-
**2. Excellent Error Handling**
|
|
19
|
-
When I encountered a syntax error with Liquibase's `/` delimiter, the error message showed:
|
|
20
|
-
|
|
21
|
-
- Exact line number (151)
|
|
22
|
-
- The failing statement
|
|
23
|
-
- Transaction rollback confirmation
|
|
24
|
-
|
|
25
|
-
This made troubleshooting instant. No digging through logs or guessing what failed.
|
|
26
|
-
|
|
27
|
-
**3. Server Management is Intuitive**
|
|
28
|
-
|
|
29
|
-
- `list_servers` → Shows all available servers with connection status
|
|
30
|
-
- `list_databases` → Filters databases by server name
|
|
31
|
-
- `switch_server_db` → Seamless switching with immediate confirmation
|
|
32
|
-
|
|
33
|
-
The flow is natural: discover → select → connect → execute.
|
|
34
|
-
|
|
35
|
-
**4. SQL File Deployment Made Easy**
|
|
36
|
-
The `stripPatterns` feature solved my exact problem:
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
execute_sql_file({
|
|
40
|
-
filePath: "/path/to/liquibase.sql",
|
|
41
|
-
stripPatterns: ["/"], // Removes Liquibase delimiters
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Before this feature, I had to manually remove delimiters or use raw `execute_sql`. Now it's one clean call.
|
|
46
|
-
|
|
47
|
-
**5. Dry-Run Capabilities are Outstanding**
|
|
48
|
-
`dry_run_sql_file` is a game-changer:
|
|
49
|
-
|
|
50
|
-
- Executes ALL statements in a transaction
|
|
51
|
-
- Shows REAL errors with PostgreSQL error codes and constraint names
|
|
52
|
-
- Automatically skips non-rollbackable operations (VACUUM, NEXTVAL)
|
|
53
|
-
- Provides EXPLAIN plans for skipped statements
|
|
54
|
-
- Then rolls back everything
|
|
55
|
-
|
|
56
|
-
This is _way_ better than just parsing - I can catch constraint violations, trigger issues, and get exact row counts before deployment.
|
|
57
|
-
|
|
58
|
-
**6. Security by Default**
|
|
59
|
-
|
|
60
|
-
- Credentials never appear in responses
|
|
61
|
-
- Host/port intentionally hidden (only server names visible)
|
|
62
|
-
- Readonly mode available for production safety
|
|
63
|
-
- Connection context always visible
|
|
64
|
-
|
|
65
|
-
### Improvements Based on My Feedback
|
|
66
|
-
|
|
67
|
-
The developer implemented several features after I tested the MCP:
|
|
68
|
-
|
|
69
|
-
✅ **SQL File Delimiter Support** - Added `stripPatterns` for Liquibase `/`, SQL Server `GO`, etc.
|
|
70
|
-
✅ **Validate-Only Mode** - `execute_sql_file({ validateOnly: true })` previews without execution
|
|
71
|
-
✅ **Enhanced Connection Info** - `get_current_connection` now returns `user` and AI `context`
|
|
72
|
-
✅ **Comprehensive Dry-Run** - `dry_run_sql_file` provides real execution + rollback
|
|
73
|
-
✅ **Better Error Details** - PostgreSQL error codes, constraint names, hints included
|
|
74
|
-
|
|
75
|
-
### Real-World Experience
|
|
76
|
-
|
|
77
|
-
**Task:** Deploy a PostgreSQL function to two databases (dev + GraphQL-Intro-DB)
|
|
78
|
-
|
|
79
|
-
1. **Discovery**: `list_servers` showed all configured servers
|
|
80
|
-
2. **Preview**: Used `preview_sql_file` to check the file structure
|
|
81
|
-
3. **Issue**: Got syntax error from Liquibase's `/` delimiter
|
|
82
|
-
4. **Solution**: Switched to direct `execute_sql` to bypass the delimiter
|
|
83
|
-
5. **Deployment**: Successfully deployed to both databases
|
|
84
|
-
6. **Verification**: Used `get_current_connection` to confirm each deployment
|
|
85
|
-
|
|
86
|
-
Total time: ~3 minutes. The structured responses and clear errors made it feel effortless.
|
|
87
|
-
|
|
88
|
-
### Minor Suggestions for Future
|
|
89
|
-
|
|
90
|
-
1. **Batch Cross Servers Deployment** - Deploy same script to multiple servers at once
|
|
91
|
-
2. **Recent Connections** - Quick-switch to recently used databases
|
|
92
|
-
3. **Statement Progress** - Show progress for large SQL files (e.g., "Executing statement 15/100...")
|
|
93
|
-
|
|
94
|
-
### Bottom Line
|
|
95
|
-
|
|
96
|
-
This MCP is production-ready and developer-friendly. The combination of clear responses, robust error handling, and powerful features like dry-run make it an essential tool for database work. The developer clearly understands the needs of both AI agents and human operators.
|
|
97
|
-
|
|
98
|
-
**Recommended for:** Database migrations, schema exploration, multi-environment management, and production deployments.
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
7
|
## Installation
|
|
103
8
|
|
|
104
9
|
```bash
|
|
@@ -395,6 +300,7 @@ Lists all database schemas in the current PostgreSQL database.
|
|
|
395
300
|
**Parameters:**
|
|
396
301
|
|
|
397
302
|
- `includeSystemSchemas` (optional): Include system schemas
|
|
303
|
+
- `server`, `database`, `schema` (optional): One-time connection override
|
|
398
304
|
|
|
399
305
|
#### `list_objects`
|
|
400
306
|
|
|
@@ -405,6 +311,7 @@ Lists database objects within a specified schema.
|
|
|
405
311
|
- `schema` (required): Schema name to list objects from
|
|
406
312
|
- `objectType` (optional): Type of objects to list (table, view, sequence, extension, all)
|
|
407
313
|
- `filter` (optional): Filter objects by name
|
|
314
|
+
- `server`, `database`, `targetSchema` (optional): One-time connection override
|
|
408
315
|
|
|
409
316
|
#### `get_object_details`
|
|
410
317
|
|
|
@@ -415,6 +322,7 @@ Provides detailed information about a database object including columns, constra
|
|
|
415
322
|
- `schema` (required): Schema name containing the object
|
|
416
323
|
- `objectName` (required): Name of the object
|
|
417
324
|
- `objectType` (optional): Type of the object
|
|
325
|
+
- `server`, `database`, `targetSchema` (optional): One-time connection override
|
|
418
326
|
|
|
419
327
|
### Query Execution
|
|
420
328
|
|
|
@@ -432,6 +340,7 @@ Executes SQL statements on the database. Supports pagination and parameterized q
|
|
|
432
340
|
- `includeSchemaHint` (optional): Include schema information (columns, primary keys, foreign keys) for tables referenced in the query.
|
|
433
341
|
- `allowMultipleStatements` (optional): Allow multiple SQL statements separated by semicolons. Returns results for each statement with line numbers.
|
|
434
342
|
- `transactionId` (optional): Execute within an active transaction. Get this from `begin_transaction`.
|
|
343
|
+
- `server`, `database`, `schema` (optional): One-time connection override. Execute on a different server/database/schema without changing the main connection. Cannot be used with `transactionId`.
|
|
435
344
|
|
|
436
345
|
**Returns:**
|
|
437
346
|
|
|
@@ -811,6 +720,70 @@ Gets the execution plan for a SQL query.
|
|
|
811
720
|
- `buffers` (optional): Include buffer usage statistics
|
|
812
721
|
- `format` (optional): Output format (text, json, yaml, xml)
|
|
813
722
|
- `hypotheticalIndexes` (optional): Simulate indexes (requires hypopg extension)
|
|
723
|
+
- `server`, `database`, `schema` (optional): One-time connection override (see below)
|
|
724
|
+
|
|
725
|
+
### Connection Override (One-Time Execution)
|
|
726
|
+
|
|
727
|
+
Most query execution tools support **one-time connection override** parameters that allow executing a query on a different server/database/schema without changing the main connection. This is useful for:
|
|
728
|
+
|
|
729
|
+
- Querying multiple databases in a single workflow
|
|
730
|
+
- Running read queries against a replica while keeping the main connection to primary
|
|
731
|
+
- Comparing schemas across different servers
|
|
732
|
+
|
|
733
|
+
**Supported tools:** `execute_sql`, `explain_query`, `list_schemas`, `list_objects`, `get_object_details`, `execute_sql_file`, `mutation_preview`, `mutation_dry_run`, `dry_run_sql_file`, `batch_execute`
|
|
734
|
+
|
|
735
|
+
**Override Parameters:**
|
|
736
|
+
|
|
737
|
+
- `server` (optional): Execute on this server instead of the current one
|
|
738
|
+
- `database` (optional): Execute on this database instead of the current one
|
|
739
|
+
- `schema` (optional): Set search_path to this schema for this execution only
|
|
740
|
+
|
|
741
|
+
**Important Notes:**
|
|
742
|
+
|
|
743
|
+
1. The main connection remains unchanged after the query completes
|
|
744
|
+
2. Connection override cannot be used with transactions (`transactionId`)
|
|
745
|
+
3. Override connections use a separate connection pool with LRU eviction
|
|
746
|
+
4. Maximum 10 cached override pools, each limited to 2 connections
|
|
747
|
+
5. Total connections across all pools limited to 50
|
|
748
|
+
|
|
749
|
+
**Examples:**
|
|
750
|
+
|
|
751
|
+
```
|
|
752
|
+
# Query another database without switching
|
|
753
|
+
execute_sql({
|
|
754
|
+
sql: "SELECT * FROM users LIMIT 10",
|
|
755
|
+
database: "analytics_db"
|
|
756
|
+
})
|
|
757
|
+
|
|
758
|
+
# Query a different server entirely
|
|
759
|
+
execute_sql({
|
|
760
|
+
sql: "SELECT COUNT(*) FROM orders",
|
|
761
|
+
server: "reporting",
|
|
762
|
+
database: "warehouse"
|
|
763
|
+
})
|
|
764
|
+
|
|
765
|
+
# List schemas on a different server
|
|
766
|
+
list_schemas({
|
|
767
|
+
server: "production",
|
|
768
|
+
database: "myapp"
|
|
769
|
+
})
|
|
770
|
+
|
|
771
|
+
# Compare table structure across environments
|
|
772
|
+
get_object_details({
|
|
773
|
+
schema: "public",
|
|
774
|
+
objectName: "users",
|
|
775
|
+
server: "staging"
|
|
776
|
+
})
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
**Connection Pool Management:**
|
|
780
|
+
|
|
781
|
+
Override connections are managed efficiently:
|
|
782
|
+
|
|
783
|
+
- Pools are cached and reused for repeated queries to the same server/database
|
|
784
|
+
- LRU eviction removes oldest pools when limit (10) is reached
|
|
785
|
+
- Connections are properly released after each query
|
|
786
|
+
- Global connection limit prevents resource exhaustion
|
|
814
787
|
|
|
815
788
|
### Performance Analysis
|
|
816
789
|
|
|
@@ -996,6 +969,101 @@ When `execute_sql_file` or multi-statement execution encounters errors, line num
|
|
|
996
969
|
- Optional: `pg_stat_statements` extension for query performance analysis
|
|
997
970
|
- Optional: `hypopg` extension for hypothetical index simulation
|
|
998
971
|
|
|
972
|
+
## 🤖 Agent Experience (AX) - Claude Code Review
|
|
973
|
+
|
|
974
|
+
**Tested by:** Claude Code (Sonnet 4.5)
|
|
975
|
+
**Use Case:** Database deployment, schema exploration, and SQL migration
|
|
976
|
+
**Rating:** ⭐⭐⭐⭐⭐ (9.5/10)
|
|
977
|
+
|
|
978
|
+
### What I Loved
|
|
979
|
+
|
|
980
|
+
**1. Clear, Structured Responses**
|
|
981
|
+
Every response includes connection context (`server`, `database`, `schema`), making it crystal clear which environment I'm working in. This is essential when managing multiple databases - I never have to guess where a query ran.
|
|
982
|
+
|
|
983
|
+
**2. Excellent Error Handling**
|
|
984
|
+
When I encountered a syntax error with Liquibase's `/` delimiter, the error message showed:
|
|
985
|
+
|
|
986
|
+
- Exact line number (151)
|
|
987
|
+
- The failing statement
|
|
988
|
+
- Transaction rollback confirmation
|
|
989
|
+
|
|
990
|
+
This made troubleshooting instant. No digging through logs or guessing what failed.
|
|
991
|
+
|
|
992
|
+
**3. Server Management is Intuitive**
|
|
993
|
+
|
|
994
|
+
- `list_servers` → Shows all available servers with connection status
|
|
995
|
+
- `list_databases` → Filters databases by server name
|
|
996
|
+
- `switch_server_db` → Seamless switching with immediate confirmation
|
|
997
|
+
|
|
998
|
+
The flow is natural: discover → select → connect → execute.
|
|
999
|
+
|
|
1000
|
+
**4. SQL File Deployment Made Easy**
|
|
1001
|
+
The `stripPatterns` feature solved my exact problem:
|
|
1002
|
+
|
|
1003
|
+
```javascript
|
|
1004
|
+
execute_sql_file({
|
|
1005
|
+
filePath: "/path/to/liquibase.sql",
|
|
1006
|
+
stripPatterns: ["/"], // Removes Liquibase delimiters
|
|
1007
|
+
});
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
Before this feature, I had to manually remove delimiters or use raw `execute_sql`. Now it's one clean call.
|
|
1011
|
+
|
|
1012
|
+
**5. Dry-Run Capabilities are Outstanding**
|
|
1013
|
+
`dry_run_sql_file` is a game-changer:
|
|
1014
|
+
|
|
1015
|
+
- Executes ALL statements in a transaction
|
|
1016
|
+
- Shows REAL errors with PostgreSQL error codes and constraint names
|
|
1017
|
+
- Automatically skips non-rollbackable operations (VACUUM, NEXTVAL)
|
|
1018
|
+
- Provides EXPLAIN plans for skipped statements
|
|
1019
|
+
- Then rolls back everything
|
|
1020
|
+
|
|
1021
|
+
This is _way_ better than just parsing - I can catch constraint violations, trigger issues, and get exact row counts before deployment.
|
|
1022
|
+
|
|
1023
|
+
**6. Security by Default**
|
|
1024
|
+
|
|
1025
|
+
- Credentials never appear in responses
|
|
1026
|
+
- Host/port intentionally hidden (only server names visible)
|
|
1027
|
+
- Readonly mode available for production safety
|
|
1028
|
+
- Connection context always visible
|
|
1029
|
+
|
|
1030
|
+
### Improvements Based on My Feedback
|
|
1031
|
+
|
|
1032
|
+
The developer implemented several features after I tested the MCP:
|
|
1033
|
+
|
|
1034
|
+
✅ **SQL File Delimiter Support** - Added `stripPatterns` for Liquibase `/`, SQL Server `GO`, etc.
|
|
1035
|
+
✅ **Validate-Only Mode** - `execute_sql_file({ validateOnly: true })` previews without execution
|
|
1036
|
+
✅ **Enhanced Connection Info** - `get_current_connection` now returns `user` and AI `context`
|
|
1037
|
+
✅ **Comprehensive Dry-Run** - `dry_run_sql_file` provides real execution + rollback
|
|
1038
|
+
✅ **Better Error Details** - PostgreSQL error codes, constraint names, hints included
|
|
1039
|
+
|
|
1040
|
+
### Real-World Experience
|
|
1041
|
+
|
|
1042
|
+
**Task:** Deploy a PostgreSQL function to two databases (dev + GraphQL-Intro-DB)
|
|
1043
|
+
|
|
1044
|
+
1. **Discovery**: `list_servers` showed all configured servers
|
|
1045
|
+
2. **Preview**: Used `preview_sql_file` to check the file structure
|
|
1046
|
+
3. **Issue**: Got syntax error from Liquibase's `/` delimiter
|
|
1047
|
+
4. **Solution**: Switched to direct `execute_sql` to bypass the delimiter
|
|
1048
|
+
5. **Deployment**: Successfully deployed to both databases
|
|
1049
|
+
6. **Verification**: Used `get_current_connection` to confirm each deployment
|
|
1050
|
+
|
|
1051
|
+
Total time: ~3 minutes. The structured responses and clear errors made it feel effortless.
|
|
1052
|
+
|
|
1053
|
+
### Minor Suggestions for Future
|
|
1054
|
+
|
|
1055
|
+
1. **Batch Cross Servers Deployment** - Deploy same script to multiple servers at once
|
|
1056
|
+
2. **Recent Connections** - Quick-switch to recently used databases
|
|
1057
|
+
3. **Statement Progress** - Show progress for large SQL files (e.g., "Executing statement 15/100...")
|
|
1058
|
+
|
|
1059
|
+
### Bottom Line
|
|
1060
|
+
|
|
1061
|
+
This MCP is production-ready and developer-friendly. The combination of clear responses, robust error handling, and powerful features like dry-run make it an essential tool for database work. The developer clearly understands the needs of both AI agents and human operators.
|
|
1062
|
+
|
|
1063
|
+
**Recommended for:** Database migrations, schema exploration, multi-environment management, and production deployments.
|
|
1064
|
+
|
|
1065
|
+
---
|
|
1066
|
+
|
|
999
1067
|
## License
|
|
1000
1068
|
|
|
1001
1069
|
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Manager Validation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Centralized validation functions for database and schema names.
|
|
5
|
+
* Prevents SQL injection and ensures PostgreSQL-compatible identifiers.
|
|
6
|
+
*/
|
|
7
|
+
/** Pattern for valid database names: start with letter/underscore, alphanumeric/underscore/hyphen */
|
|
8
|
+
const DATABASE_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
|
|
9
|
+
/** Pattern for SQL injection characters that must not appear in database names */
|
|
10
|
+
const SQL_INJECTION_PATTERN = /--|;|'|"|`/;
|
|
11
|
+
/** Pattern for valid schema names: start with letter/underscore, alphanumeric/underscore only */
|
|
12
|
+
const SCHEMA_NAME_PATTERN = /^[a-zA-Z_]\w*$/;
|
|
13
|
+
/**
|
|
14
|
+
* Validates a database name for PostgreSQL compatibility and SQL injection prevention.
|
|
15
|
+
*
|
|
16
|
+
* @param name - The database name to validate
|
|
17
|
+
* @throws Error if the database name is invalid
|
|
18
|
+
*/
|
|
19
|
+
export function validateDatabaseName(name) {
|
|
20
|
+
if (!DATABASE_NAME_PATTERN.test(name) || SQL_INJECTION_PATTERN.test(name)) {
|
|
21
|
+
throw new Error('Invalid database name. Allowed: letters, digits, underscores, hyphens. ' +
|
|
22
|
+
'Cannot contain SQL characters (;, --, quotes).');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Validates a schema name for PostgreSQL compatibility.
|
|
27
|
+
*
|
|
28
|
+
* @param name - The schema name to validate
|
|
29
|
+
* @throws Error if the schema name is invalid
|
|
30
|
+
*/
|
|
31
|
+
export function validateSchemaName(name) {
|
|
32
|
+
if (!SCHEMA_NAME_PATTERN.test(name)) {
|
|
33
|
+
throw new Error('Invalid schema name. Only alphanumeric characters and underscores are allowed.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a database name is valid without throwing.
|
|
38
|
+
*
|
|
39
|
+
* @param name - The database name to check
|
|
40
|
+
* @returns true if valid, false otherwise
|
|
41
|
+
*/
|
|
42
|
+
export function isValidDatabaseName(name) {
|
|
43
|
+
return DATABASE_NAME_PATTERN.test(name) && !SQL_INJECTION_PATTERN.test(name);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a schema name is valid without throwing.
|
|
47
|
+
*
|
|
48
|
+
* @param name - The schema name to check
|
|
49
|
+
* @returns true if valid, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
export function isValidSchemaName(name) {
|
|
52
|
+
return SCHEMA_NAME_PATTERN.test(name);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=validation.js.map
|