-
Notifications
You must be signed in to change notification settings - Fork 2
Add schema support #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b4634be
add support to JSON-based schema seed
atilafassina 78f88e6
add support for `schemaPath` on vite-plugin
atilafassina 3381615
add changeset
atilafassina 17c69c2
update tanstack example
atilafassina 2455f50
improve error message for bad schema
atilafassina 0a7a873
add test for schema validation
atilafassina e7cbf22
move Zod to `package.dependencies` instead of `devDependencies`
atilafassina 6fd46fe
move Zod to `package.dependencies` instead of `devDependencies`
atilafassina ddb4541
improve queries logic
atilafassina c84d061
update `pnpm-lock.yaml`
atilafassina 24fa369
refactor: use SQL file instead of JSON
atilafassina f1ba604
adjust the configuration object on vite-plugin
atilafassina 0f14684
update changelogs
atilafassina 3beb140
update docs
atilafassina 0727611
cleanup code
atilafassina 7bd481d
rename `onCreate` to `seed`
atilafassina ee674f9
add referrer to examples
atilafassina 77fc18a
update release tag
atilafassina 4bd6fb0
set tanstack example to private
atilafassina 4a6ebae
update lockfile
atilafassina 06abf77
remove unused schema file
atilafassina 6768f0b
add tests, fix test run for CI
atilafassina 6aacd91
remove unused import
atilafassina 12b009c
adjust JSDoc and fix typos (`referer`/`referrer`)
atilafassina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@neondatabase/vite-plugin-postgres": minor | ||
| --- | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "neondb": minor | ||
| --- | ||
|
|
||
| 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. | ||
|
|
||
| | Option | Description | | ||
| | ------------ | --------------------------------------------------- | | ||
| | `-s, --seed` | Path to SQL file to execute after database creation | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id SERIAL PRIMARY KEY, | ||
| name text | ||
| ); | ||
|
|
||
| INSERT INTO users (name) VALUES | ||
| ('John Lennon'), | ||
| ('Paul McCartney'), | ||
| ('George Harrison'), | ||
| ('Ringo Starr'), | ||
| ('George Martin'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { neon } from "@neondatabase/serverless"; | ||
| import { getSqlCommands } from "./utils/fs.js"; | ||
|
|
||
| export async function seedDatabase( | ||
| schemaFilePath: string, | ||
| connectionString: string, | ||
| ) { | ||
| const client = neon(connectionString); | ||
| const commands = getSqlCommands(schemaFilePath); | ||
|
|
||
| for (const command of commands) { | ||
| await client.query(command); | ||
guillaumervls marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,25 @@ | ||
| import { neonColumnTypeOptions } from "./neon-schema.js"; | ||
| export type SqlScript = { | ||
| type: "sql-script"; | ||
| path: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Parameters for configuring Instagres database connection | ||
| * @param {string} dotEnvFile - Path to the .env file where the connection string will be saved | ||
| * @param {string} dotEnvKey - Environment variable name to store the connection string | ||
| * @param {boolean} withPooler - Whether to use connection pooling | ||
| * @param {string} referer - referrer name for tracking | ||
| * @param {string} seedPath - Path to the `.sql` file to be pushed to the database | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| export interface InstantNeonParams { | ||
| dotEnvFile?: string; | ||
| dotEnvKey?: string; | ||
| referrer?: string; | ||
| seed?: SqlScript; | ||
| } | ||
|
|
||
| export interface Defaults { | ||
| dotEnvPath: string; | ||
| dotEnvKey: string; | ||
| seed?: SqlScript; | ||
| } | ||
|
|
||
| export type NeonColumnTypes = (typeof neonColumnTypeOptions)[number]["value"]; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.