Skip to content

Commit 2e67ef0

Browse files
committed
add schema and data export tool fsql-export
1 parent b4ba51c commit 2e67ef0

File tree

7 files changed

+540
-2
lines changed

7 files changed

+540
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.*.swp
33
dist/
44
node_modules/
5+
fsql-dumps/

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ Notes:
6666
fsql
6767
```
6868

69+
## Export
70+
71+
Export your Forge SQL database schema and data to a local SQL file.
72+
73+
```sh
74+
fsql-export
75+
```
76+
77+
Options:
78+
79+
- `--schema-only`: Export schema only (skip data)
80+
- `--output <file>`: Output file path (default: `./fsql-dumps/fsql-export-<timestamp>.sql`)
81+
- `--live-schema`: Fetch DDL from live database instead of `migration.ts`
82+
83+
Notes:
84+
85+
- uses `FORGE_SQL_WEBTRIGGER` from your `.env` file
86+
- exports schema and data to `./fsql-dumps/` by default
87+
- automatically looks for `migration.ts` to preserve your exact table definitions
88+
6989
## Upgrade
7090

7191
```sh

bin/fsql-export.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
import "../dist/export.js";

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"types": "dist/index.d.ts",
1313
"bin": {
1414
"fsql": "bin/fsql.js",
15-
"fsql-setup": "bin/setup.js"
15+
"fsql-setup": "bin/setup.js",
16+
"fsql-export": "bin/fsql-export.js"
1617
},
1718
"exports": {
1819
".": {

src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export class ForgeClient {
4747
clearTimeout(timeoutId);
4848

4949
if (!response.ok) {
50+
const contentType = response.headers.get("content-type");
51+
if (contentType && contentType.includes("text/html")) {
52+
return {
53+
error: `HTTP ${response.status} ${response.statusText}`,
54+
};
55+
}
56+
5057
const errorText = await response.text();
5158
return {
5259
error: `HTTP ${response.status}: ${errorText}`,

0 commit comments

Comments
 (0)