Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neon-explicit-database-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tanstack/create": patch
---

Replace the deprecated Neon Vite plugin with explicit database setup instructions, keeping app startup free of automatic database provisioning.
27 changes: 22 additions & 5 deletions examples/custom-cli/create-rwsdk/add-ons/neon/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
## Setting up Neon
## Neon setup

When running the `dev` command, `vite-plugin-neon-new` will identify there is not a database setup. It will then create and seed a claimable database.
Create a claimable database and write its connection string to `.env`:

It is the same process as [Neon Launchpad](https://neon.new).
```sh
npx neon@9.6.3 claim create --env-pull --file .env
```

> [!IMPORTANT]
> Claimable databases expire in 72 hours.
The CLI writes `DATABASE_URL`. Copy that value to `VITE_DATABASE_URL` in `.env` for this example.

Seed the claimable database from this project directory:

```sh
npx neon@9.6.3 psql --role-name neondb_owner -- -f db/init.sql
```

This creates the demo table and its three sample todos. Run it once, repeating the script inserts the sample todos again.

For an existing Neon database, skip creation, set `VITE_DATABASE_URL` in `.env` to its connection string, and run `db/init.sql` once in that project's SQL Editor. The SQL Editor requires an owned project, so use the CLI command above before claiming.

Start the app with your package manager's `dev` command.

To keep a claimable database, run `npx neon@9.6.3 claim accept` before it expires and complete the transfer in the browser. Claiming revokes the temporary database password. Get a fresh connection string from the destination project in the Neon Console, replace `VITE_DATABASE_URL` in `.env`, and restart the dev server. `claim accept` does not refresh `.env` for you.

See https://neon.com/docs/reference/claimable-neon for database setup and claiming.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# These will be automatically created by Neon Launchpad (https://neon.new).
# You will also need to
# Set this to your Neon database connection string.
VITE_DATABASE_URL=
VITE_DATABASE_URL_POOLER=

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,35 @@ function DBConnectionError() {
/>
</svg>
</div>
<h2 className="text-2xl font-bold mb-4">Database Connection Issue</h2>
<div className="text-lg mb-6">The Neon database is not connected.</div>
<h2 className="text-2xl font-bold mb-4">Neon database not connected</h2>
<div className="bg-black/30 p-6 rounded-lg max-w-xl mx-auto">
<h3 className="text-lg font-semibold mb-4">Required Steps to Fix:</h3>
<ul className="space-y-4 text-left list-none">
<li className="flex items-start">
<span className="inline-flex items-center justify-center w-8 h-8 rounded-full bg-amber-500 text-black font-bold mr-3 min-w-8 min-h-8">
1
</span>
<div>
Use the{' '}
<code className="bg-black/30 px-2 py-1 rounded">db/init.sql</code>{' '}
file to create the database
Create a database with{' '}
<code>npx neon@9.6.3 claim create --env-pull --file .env</code>,
then seed it once with{' '}
<code>
npx neon@9.6.3 psql --role-name neondb_owner -- -f db/init.sql
</code>
.
</div>
</li>
<li className="flex items-start">
<span className="inline-flex items-center justify-center w-8 h-8 rounded-full bg-amber-500 text-black font-bold mr-3 min-w-8 min-h-8">
2
</span>
<div>
Set the{' '}
Copy the CLI's <code>DATABASE_URL</code> value to{' '}
<code className="bg-black/30 px-2 py-1 rounded">
DATABASE_URL
VITE_DATABASE_URL
</code>{' '}
environment variable to the connection string of your Neon
database
in <code>.env</code>. After claiming, replace it with a fresh
connection string from the Neon Console. Restart the dev server
after changing <code>.env</code>.
</div>
</li>
</ul>
Expand Down
8 changes: 1 addition & 7 deletions examples/custom-cli/create-rwsdk/add-ons/neon/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
"jsName": "NeonDemo"
}
],
"integrations": [
{
"type": "vite-plugin",
"jsName": "neon",
"path": "neon-vite-plugin.ts"
}
],
"integrations": [],
"dependsOn": []
}
3 changes: 1 addition & 2 deletions examples/custom-cli/create-rwsdk/add-ons/neon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"@neondatabase/serverless": "^1.0.0",
"vite-plugin-neon-new": "^0.8.0"
"@neondatabase/serverless": "^1.0.0"
}
}
58 changes: 58 additions & 0 deletions packages/cli/tests-e2e/neon-smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import fs from 'node:fs'
import path from 'node:path'
import { expect, test } from '@playwright/test'
import { createReactAppFixture, optimizePageForFastE2E } from './helpers'

for (const rejects of [true, false]) {
test(`@matrix Neon ${rejects ? 'shows recovery after a rejected query' : 'renders successful query results'}`, async ({
page,
}) => {
const app = await createReactAppFixture({
appName: `neon-query-${rejects ? 'failure' : 'success'}`,
addOns: ['neon'],
runQualityGatesChecks: true,
afterCreate: async (dir) => {
fs.writeFileSync(
path.join(dir, 'src/db.ts'),
`
export async function getClient() {
return { query: async (..._args: unknown[]) => {
${rejects ? "throw new Error('Local test: password authentication failed')" : "return [{ id: 1, title: 'Local query success' }]"}
} }
}
`,
)
},
})
try {
await optimizePageForFastE2E(page)
await page.goto(app.url + '/demo/neon')
if (rejects) {
await expect(
page.getByRole('heading', {
name: 'Neon database not connected',
exact: true,
}),
).toBeVisible()
await expect(
page.getByText('a fresh connection string from the Neon Console', {
exact: false,
}),
).toBeVisible()
} else {
await expect(
page.getByText('Local query success', { exact: true }),
).toBeVisible()
await expect(
page.getByRole('heading', {
name: 'Neon database not connected',
exact: true,
}),
).toHaveCount(0)
}
} finally {
await app.stop()
await app.cleanup()
}
})
}
25 changes: 20 additions & 5 deletions packages/create/src/frameworks/react/add-ons/neon/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
## Setting up Neon
## Neon setup

When running the `dev` command, `vite-plugin-neon-new` will identify there is not a database setup. It will then create and seed a claimable database.
Create a claimable database and write its connection string to `.env`:

It is the same process as [Neon Launchpad](https://neon.new).
```sh
npx neon@9.6.3 claim create --env-pull --file .env
```

> [!IMPORTANT]
> Claimable databases expire in 72 hours.
Seed the claimable database from this project directory:

```sh
npx neon@9.6.3 psql --role-name neondb_owner -- -f db/init.sql
```

This creates the demo table and its three sample todos. Run it once, repeating the script inserts the sample todos again.

For an existing Neon database, skip creation, set `DATABASE_URL` in `.env` to its connection string, and run `db/init.sql` once in that project's SQL Editor. The SQL Editor requires an owned project, so use the CLI command above before claiming.

Start the app with your package manager's `dev` command.

To keep a claimable database, run `npx neon@9.6.3 claim accept` before it expires and complete the transfer in the browser. Claiming revokes the temporary database password. Get a fresh connection string from the destination project in the Neon Console, replace `DATABASE_URL` in `.env`, and restart the dev server. `claim accept` does not refresh `.env` for you.

See https://neon.com/docs/reference/claimable-neon for database setup and claiming.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# These will be automatically created by Neon Launchpad (https://neon.new).
# You will also need to
# Set this to your Neon database connection string.
DATABASE_URL=
DATABASE_URL_POOLER=

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import { getClient } from '#/db'
const getTodos = createServerFn({
method: 'GET',
}).handler(async () => {
const client = await getClient()
if (!client) {
try {
const client = await getClient()
if (!client) {
return undefined
}
return (await client.query(`SELECT * FROM todos`)) as Array<{
id: number
title: string
}>
} catch {
return undefined
}
return (await client.query(`SELECT * FROM todos`)) as Array<{
id: number
title: string
}>
})

const insertTodo = createServerFn({
Expand Down Expand Up @@ -122,24 +126,28 @@ function DBConnectionError() {
/>
</svg>
</div>
<h2 className="text-2xl font-bold mb-4">Database Connection Issue</h2>
<div className="demo-muted text-lg mb-6">
The Neon database is not connected.
</div>
<h2 className="text-2xl font-bold mb-4">Neon database not connected</h2>
<div className="demo-card max-w-xl mx-auto text-left">
<h3 className="text-lg font-semibold mb-4">Required Steps to Fix:</h3>
<ul className="space-y-4 text-left list-none">
<li className="flex items-start">
<span className="demo-pill mr-3 min-w-8 justify-center">1</span>
<div>
Use the <code>db/init.sql</code> file to create the database
Create a database with{' '}
<code>npx neon@9.6.3 claim create --env-pull --file .env</code>,
then seed it once with{' '}
<code>
npx neon@9.6.3 psql --role-name neondb_owner -- -f db/init.sql
</code>
.
</div>
</li>
<li className="flex items-start">
<span className="demo-pill mr-3 min-w-8 justify-center">2</span>
<div>
Set the <code>DATABASE_URL</code> environment variable to the
connection string of your Neon database
Use <code>DATABASE_URL</code> in <code>.env</code> for the
connection string. After claiming the database, replace it with a
fresh connection string from the Neon Console. Restart the dev
server after changing <code>.env</code>.
</div>
</li>
</ul>
Expand Down
8 changes: 1 addition & 7 deletions packages/create/src/frameworks/react/add-ons/neon/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,5 @@
"jsName": "NeonDemo"
}
],
"integrations": [
{
"type": "vite-plugin",
"jsName": "neon",
"path": "neon-vite-plugin.ts"
}
]
"integrations": []
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"@neondatabase/serverless": "^1.0.2",
"vite-plugin-neon-new": "^0.8.0"
"@neondatabase/serverless": "^1.0.2"
}
}
52 changes: 52 additions & 0 deletions packages/create/tests/neon-scaffold.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, expect, it } from 'vitest'

import { finalizeAddOns } from '../src/add-ons.js'
import { createApp } from '../src/create-app.js'
import { createMemoryEnvironment } from '../src/environment.js'
import { createFrameworkDefinition } from '../src/frameworks/react/index.js'
import type { Framework } from '../src/types.js'

describe('Neon scaffold', () => {
it('requires explicit database setup instead of provisioning through Vite', async () => {
const { base, addOns, ...definition } = createFrameworkDefinition()
const framework: Framework = {
...definition,
getFiles: () => Promise.resolve(Object.keys(base)),
getFileContents: (path) => Promise.resolve(base[path]),
getDeletedFiles: () => Promise.resolve([]),
getAddOns: () => addOns,
}
const { environment, output } = createMemoryEnvironment()
await createApp(environment, {
projectName: 'neon-app',
targetDir: '/neon-app',
framework,
mode: 'file-router',
typescript: true,
tailwind: true,
packageManager: 'npm',
git: false,
install: false,
intent: false,
chosenAddOns: await finalizeAddOns(framework, 'file-router', ['neon']),
addOnOptions: {},
})

const manifest = JSON.parse(output.files['/neon-app/package.json'])
expect(manifest.dependencies['@neondatabase/serverless']).toBeDefined()
expect(manifest.dependencies['vite-plugin-neon-new']).toBeUndefined()
expect(output.files['/neon-app/neon-vite-plugin.ts']).toBeUndefined()
expect(output.files['/neon-app/vite.config.ts']).not.toContain('neon')
expect(output.files['/neon-app/db/init.sql']).toContain('CREATE TABLE')
expect(output.files['/neon-app/README.md']).toContain(
'claim create --env-pull --file .env',
)
expect(output.files['/neon-app/README.md']).toContain(
'psql --role-name neondb_owner -- -f db/init.sql',
)
expect(output.files['/neon-app/README.md']).toContain(
'replace `DATABASE_URL` in `.env`, and restart the dev server',
)
expect(output.commands).toEqual([])
})
})
Loading