Skip to content

Commit 8ae511e

Browse files
authored
Add schema support (#17)
1 parent c1bf20c commit 8ae511e

File tree

26 files changed

+311
-1810
lines changed

26 files changed

+311
-1810
lines changed

.changeset/quick-loops-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neondatabase/vite-plugin-postgres": minor
3+
---
4+
5+
Add `seed` option to seed database with SQL script on initialization. This option accepts a path to a SQL file that will be executed after the database is created.

.changeset/sweet-rabbits-shake.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"neondb": minor
3+
---
4+
5+
Add support for seeding a SQL script during database initialization. You can now provide a path to a SQL file that will be executed right after the database is created. Either via the prompt or with a command flag.
6+
7+
| Option | Description |
8+
| ------------ | --------------------------------------------------- |
9+
| `-s, --seed` | Path to SQL file to execute after database creation |

.github/workflows/release.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,10 @@ jobs:
7777
CHANGELOG_ENTRY=$(awk "/## $VERSION/,/## [0-9]/" "$CHANGELOG_PATH" | sed '1d;$d')
7878
git tag -a "$TAG" "$COMMIT" -m "Release $pkg@$VERSION"
7979
80-
# Add schema.json as asset for neondb package
81-
if [ "$pkg" = "neondb" ] && [ -f "$PKG_DIR/dist/schema.json" ]; then
82-
gh release create "$TAG" --notes "$CHANGELOG_ENTRY" --title "$pkg@$VERSION" "$PKG_DIR/dist/schema.json"
83-
else
84-
gh release create "$TAG" --notes "$CHANGELOG_ENTRY" --title "$pkg@$VERSION"
85-
fi
80+
gh release create "$TAG" --notes "$CHANGELOG_ENTRY" --title "$pkg@$VERSION"
8681
else
8782
git tag "$TAG" "$COMMIT"
88-
89-
# Add schema.json as asset for neondb package
90-
if [ "$pkg" = "neondb" ] && [ -f "$PKG_DIR/dist/schema.json" ]; then
91-
gh release create "$TAG" --notes "Release $pkg@$VERSION" --title "$pkg@$VERSION" "$PKG_DIR/dist/schema.json"
92-
else
93-
gh release create "$TAG" --notes "Release $pkg@$VERSION" --title "$pkg@$VERSION"
94-
fi
83+
gh release create "$TAG" --notes "Release $pkg@$VERSION" --title "$pkg@$VERSION"
9584
fi
9685
done
9786
env:

examples/react-spa/vite.config.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,19 @@ import react from "@vitejs/plugin-react";
33
import { defineConfig } from "vite";
44

55
export default defineConfig({
6-
plugins: [postgresPlugin(), react()],
6+
plugins: [
7+
postgresPlugin({
8+
/**
9+
* @todo
10+
* [IMPORTANT] This helps us understand where DB creations on Neon come from.
11+
* Please change this as soon as you can, to add your project name:
12+
*
13+
* @example
14+
* ""github:org/your-repo"
15+
* "npm:your-package"
16+
*/
17+
referrer: "github:neondatabase/neondb/react-spa",
18+
}),
19+
react(),
20+
],
721
});

examples/tanstack-start/app.config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ import tsConfigPaths from "vite-tsconfig-paths";
44
export default defineConfig({
55
vite: {
66
plugins: [
7-
postgresPlugin(),
7+
postgresPlugin({
8+
seed: {
9+
type: "sql-script",
10+
path: "./schema.sql",
11+
},
12+
/**
13+
* @todo
14+
* [IMPORTANT] This helps us understand where DB creations on Neon come from.
15+
* Please change this as soon as you can, to add your project name:
16+
*
17+
* @example
18+
* ""github:org/your-repo"
19+
* "npm:your-package"
20+
*/
21+
referrer: "github:neondatabase/neondb/tanstack-start",
22+
}),
823
tsConfigPaths({
924
projects: ["./tsconfig.json"],
1025
}),

examples/tanstack-start/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"type": "module",
7+
"private": true,
78
"scripts": {
89
"dev": "vinxi dev",
910
"build": "vinxi build",
@@ -25,6 +26,7 @@
2526
"@types/react": "^19.0.10",
2627
"@types/react-dom": "^19.0.4",
2728
"@vitejs/plugin-react": "^4.3.4",
29+
"neondb": "workspace:*",
2830
"typescript": "^5.8.2",
2931
"vite-tsconfig-paths": "^5.1.4"
3032
}

examples/tanstack-start/schema.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE IF NOT EXISTS users (
2+
id SERIAL PRIMARY KEY,
3+
name text
4+
);
5+
6+
INSERT INTO users (name) VALUES
7+
('John Lennon'),
8+
('Paul McCartney'),
9+
('George Harrison'),
10+
('Ringo Starr'),
11+
('George Martin');

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"build": "pnpm --filter neondb build && pnpm --filter vite-plugin-postgres build",
99
"format": "biome check --error-on-warnings --fix",
1010
"lint:ci": "biome ci --error-on-warnings",
11-
"test:ci": "pnpm --recursive vitest --passWithNoTests",
11+
"test:ci": "pnpm --recursive test:ci",
1212
"prepare": "husky"
1313
},
14-
"lint-staged": {
14+
"lint-staged": {
1515
"*": "biome check --write --no-errors-on-unmatched --files-ignore-unknown=true"
1616
},
1717
"devDependencies": {

packages/neondb/CHANGELOG.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,80 @@
44

55
### Patch Changes
66

7-
- ce1c182: Add better referer values for each package
7+
- ce1c182: Add better referrer values for each package
88

99
## 0.6.2
1010

1111
### Patch Changes
1212

13-
- 9e8a5a4: Fix Unclaimed project Time-to-Live (TTL)
13+
- 9e8a5a4: Fix Unclaimed project Time-to-Live (TTL)
1414

15-
The actual TTL of an unclaimed branch is 72 hours
15+
The actual TTL of an unclaimed branch is 72 hours
1616

1717
## 0.6.1
1818

1919
### Patch Changes
2020

21-
- 995ad06: Fix Neon domain and add keywords to `package.json`
21+
- 995ad06: Fix Neon domain and add keywords to `package.json`
2222

2323
## 0.6.0
2424

2525
### Minor Changes
2626

27-
- b807e80: Adds validation to user input on file name and environment variable key.
27+
- b807e80: Adds validation to user input on file name and environment variable key.
2828

29-
| Option | Default | Description | Validation |
30-
| ---------- | -------------- | ------------------------- | --------------------- |
31-
| dotEnvFile | ".env" | Path to env file | letters and `.` |
32-
| dotEnvKey | "DATABASE_URL" | Environment variable name | `SCREAMING_SNAKE_CASE |
29+
| Option | Default | Description | Validation |
30+
| ---------- | -------------- | ------------------------- | --------------------- |
31+
| dotEnvFile | ".env" | Path to env file | letters and `.` |
32+
| dotEnvKey | "DATABASE_URL" | Environment variable name | `SCREAMING_SNAKE_CASE |
3333

34-
- b807e80: Prevents creating a DB if flow is cancelled
34+
- b807e80: Prevents creating a DB if flow is cancelled
3535

36-
if the user aborts (CTRL+C), the CLI will not use the defaults and the process will be interrupted immediately.
36+
if the user aborts (CTRL+C), the CLI will not use the defaults and the process will be interrupted immediately.
3737

3838
### Patch Changes
3939

40-
- 31cb6f4: Remove `refferer`, `provider`, and `region` from possible CLI arguments
41-
- adbfcc9: Fix: prevent flags from being ignored
40+
- 31cb6f4: Remove `refferer`, `provider`, and `region` from possible CLI arguments
41+
- adbfcc9: Fix: prevent flags from being ignored
4242

43-
This release fixes a regression where `--env` and `--key` flags were being ignored and defaults would be used regardless.
43+
This release fixes a regression where `--env` and `--key` flags were being ignored and defaults would be used regardless.
4444

4545
## 0.5.0
4646

4747
### Minor Changes
4848

49-
- e3482a6: Fixed new lines being added in the .env file
49+
- e3482a6: Fixed new lines being added in the .env file
5050

5151
## 0.4.1
5252

5353
### Patch Changes
5454

55-
- 91c6b5f: Remove trailing whitespace from `.env`
55+
- 91c6b5f: Remove trailing whitespace from `.env`
5656

5757
## 0.4.0
5858

5959
### Minor Changes
6060

61-
- e09a8c8: Improve logs
61+
- e09a8c8: Improve logs
6262

63-
- Generate better logs for the CLI.
64-
- Add proper Claim URL to the `.env`.
65-
- Remove excess tabs from the `.env` output.
63+
- Generate better logs for the CLI.
64+
- Add proper Claim URL to the `.env`.
65+
- Remove excess tabs from the `.env` output.
6666

6767
## 0.3.1
6868

6969
### Patch Changes
7070

71-
- 11e28a5: Update endpoints
71+
- 11e28a5: Update endpoints
7272

7373
## 0.3.0
7474

7575
### Minor Changes
7676

77-
- 05de2a7: Add `/sdk` export for `instantNeon`
77+
- 05de2a7: Add `/sdk` export for `instantNeon`
7878

7979
## 0.2.1
8080

8181
### Patch Changes
8282

83-
- a0817d9: Append the defaults to the prompt messages.
83+
- a0817d9: Append the defaults to the prompt messages.

packages/neondb/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Options:
2121
- `-y, --yes` Use defaults, skip prompts
2222
- `-e, --env` Path to .env file (default: ./.env)
2323
- `-k, --key` Env key for connection string (default: DATABASE_URL)
24+
- `-s, --seed` Path to SQL file to execute after database creation
2425
- `-h, --help` Show help
2526

2627
---

0 commit comments

Comments
 (0)