Standard patterns for connecting applications to Neon Postgres and managing schema changes via migrations (Alembic / SQLModel / SQLAlchemy), with attention to serverless connection behaviour.
Use this Skill whenever you are:
This Skill must work for any backend that uses Neon Postgres, not just a specific framework or repository. [web:85][web:87][web:98]
Neon is a serverless Postgres:
Connection best practices:
DATABASE_URL connection string and do not
hard-code hostnames, ports, or credentials.Be prepared for occasional connection resets due to scaling-to-zero:
The Neon connection string must come from environment variables, for example:
DATABASE_URL – primary Neon Postgres connection string.DATABASE_URL_RW / DATABASE_URL_RO if using read/write
separation.Configuration rules:
DATABASE_URL values per environment (dev, staging,
prod) without changing code.For long-running app servers (e.g. FastAPI, Node API server):
For serverless/edge runtimes:
Treat the database schema as code with history:
Recommended pattern with Alembic:
alembic init alembic (or equivalent command).alembic.ini to load sqlalchemy.url from the same
env var used by the app (DATABASE_URL). [web:88][web:91]target_metadata in alembic/env.py to your ORM models’
metadata so migrations can be generated from model changes.Avoid calling metadata.create_all() in production startup paths for
non-trivial apps; prefer running migrations as part of deploy/CI/CD.
Typical workflow:
The application should assume the schema is already up to date; it should not modify the schema at runtime under normal conditions.
Implement simple health checks for the database:
/health endpoint or startup probe.Log connection errors with enough context to debug issues related to:
In serverless environments, pay attention to:
create_all() for schema
changes in production.When present, this Skill should align with:
A central database configuration module (e.g. db.py, database.py,
or db/__init__.py) that:
DATABASE_URL from the environment.A migrations directory (e.g. alembic/) that:
DATABASE_URL.target_metadata.If these are missing, propose creating them following Neon’s official guides and the patterns described above instead of inventing a new, ad-hoc connection/migration approach per project.