Skip to content
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

docs(pg-adapter): add unique and foreign key constraints to the PG adapter schema #12381

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
30 changes: 15 additions & 15 deletions docs/pages/getting-started/adapters/pg.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,21 @@ The SQL schema for the tables used by this adapter is as follows. Learn more abo
doc page on [Database Models](/guides/creating-a-database-adapter).

```sql
CREATE TABLE verification_token
CREATE TABLE users
(
identifier TEXT NOT NULL,
expires TIMESTAMPTZ NOT NULL,
token TEXT NOT NULL,
id SERIAL,
name VARCHAR(255),
email VARCHAR(255) UNIQUE,
"emailVerified" TIMESTAMPTZ,
image TEXT,

PRIMARY KEY (identifier, token)
PRIMARY KEY (id)
);

CREATE TABLE accounts
(
id SERIAL,
"userId" INTEGER NOT NULL,
"userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
type VARCHAR(255) NOT NULL,
provider VARCHAR(255) NOT NULL,
"providerAccountId" VARCHAR(255) NOT NULL,
Expand All @@ -232,22 +234,20 @@ CREATE TABLE accounts
CREATE TABLE sessions
(
id SERIAL,
"userId" INTEGER NOT NULL,
"userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
expires TIMESTAMPTZ NOT NULL,
"sessionToken" VARCHAR(255) NOT NULL,
"sessionToken" VARCHAR(255) UNIQUE NOT NULL,

PRIMARY KEY (id)
);

CREATE TABLE users
CREATE TABLE verification_token
(
id SERIAL,
name VARCHAR(255),
email VARCHAR(255),
"emailVerified" TIMESTAMPTZ,
image TEXT,
identifier TEXT NOT NULL,
expires TIMESTAMPTZ NOT NULL,
token TEXT NOT NULL,

PRIMARY KEY (id)
PRIMARY KEY (identifier, token)
);

```
2 changes: 1 addition & 1 deletion docs/pages/getting-started/providers/apple.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Code } from "@/components/Code"
- Sign in with Apple [REST API](https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api)
- [How to retrieve](https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple#3383773) the user's information from Apple ID servers

> **_NOTE:_** Apple currently does not support [RedirectProxyUrl](https://github.com/nextauthjs/next-auth/blob/3ec06842682a31e53fceabca701a362abda1e7dd/packages/core/src/lib/utils/providers.ts#L48) usage.
> **_NOTE:_** Apple currently does not support [RedirectProxyUrl](https://github.com/nextauthjs/next-auth/blob/3ec06842682a31e53fceabca701a362abda1e7dd/packages/core/src/lib/utils/providers.ts#L48) usage.
## Setup

Expand Down
40 changes: 20 additions & 20 deletions packages/adapter-pg/schema.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
\set ON_ERROR_STOP true

CREATE TABLE verification_token
CREATE TABLE users
(
identifier TEXT NOT NULL,
expires TIMESTAMPTZ NOT NULL,
token TEXT NOT NULL,

PRIMARY KEY (identifier, token)
id SERIAL,
name VARCHAR(255),
email VARCHAR(255) UNIQUE,
"emailVerified" TIMESTAMPTZ,
image TEXT,

PRIMARY KEY (id)
);

CREATE TABLE accounts
(
id SERIAL,
"userId" INTEGER NOT NULL,
"userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
type VARCHAR(255) NOT NULL,
provider VARCHAR(255) NOT NULL,
"providerAccountId" VARCHAR(255) NOT NULL,
Expand All @@ -23,27 +25,25 @@ CREATE TABLE accounts
scope TEXT,
session_state TEXT,
token_type TEXT,

PRIMARY KEY (id)
);

CREATE TABLE sessions
(
id SERIAL,
"userId" INTEGER NOT NULL,
"userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
expires TIMESTAMPTZ NOT NULL,
"sessionToken" VARCHAR(255) NOT NULL,

"sessionToken" VARCHAR(255) UNIQUE NOT NULL,
PRIMARY KEY (id)
);

CREATE TABLE users
CREATE TABLE verification_token
(
id SERIAL,
name VARCHAR(255),
email VARCHAR(255),
"emailVerified" TIMESTAMPTZ,
image TEXT,

PRIMARY KEY (id)
identifier TEXT NOT NULL,
expires TIMESTAMPTZ NOT NULL,
token TEXT NOT NULL,

PRIMARY KEY (identifier, token)
);
Loading