-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(users): Add public.users table and new users to it
Add public.users table because supabase auth.users is private. Add users to it after sign up. Handle database migrations and queries with prisma. Add prisma (CLI) and @prisma/client dependencies.
- Loading branch information
Showing
12 changed files
with
281 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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,22 @@ | ||
name: staging-deploy | ||
run-name: Deploy database changes to the Supabase Staging database. | ||
on: | ||
push: | ||
branches-ignore: | ||
- 'main' | ||
jobs: | ||
prisma-migrate-deploy: | ||
name: Run prisma migrations | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: staging | ||
env: | ||
DATABASE_URL: ${{ secrets.STAGING_DATABASE_URL }} | ||
DATABASE_DIRECT_URL: ${{ secrets.STAGING_DATABASE_DIRECT_URL }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
cache: 'npm' | ||
node-version-file: '.nvmrc' | ||
- run: npx prisma@5.0.0 migrate deploy |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,17 @@ | ||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" UUID NOT NULL, | ||
"email" VARCHAR(254) NOT NULL, | ||
"name" VARCHAR(500), | ||
"provider" VARCHAR(100) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_provider_key" ON "User"("provider"); |
This file contains 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,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
This file contains 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,21 @@ | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DATABASE_DIRECT_URL") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
// We use Supabase's authentication solution, which create users in a private "auth" schema. | ||
// So we create this User table in our "public" schema and add users to it after | ||
// they're created by Supabase's auth solution, using the same "id". | ||
model User { | ||
id String @id @db.Uuid | ||
email String @unique @db.VarChar(254) | ||
name String? @db.VarChar(500) | ||
provider String @unique @db.VarChar(100) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime? @updatedAt | ||
} |
This file contains 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,24 @@ | ||
import { PrismaClient, User } from '@prisma/client'; | ||
|
||
export interface CreateUserData { | ||
readonly email: string; | ||
readonly id: string; | ||
readonly name?: string; | ||
readonly provider: string; | ||
} | ||
|
||
export const createUser = async (data: CreateUserData) => { | ||
const prisma = new PrismaClient(); | ||
|
||
const user = await prisma.user.findUnique({ where: { id: data.id } }); | ||
|
||
if (user) return user; | ||
|
||
const newUser = await prisma.user.create({ data }); | ||
return newUser; | ||
}; | ||
|
||
export const findUserById = async (id: string) => { | ||
const prisma = new PrismaClient(); | ||
return await prisma.user.findUnique({ where: { id } }); | ||
}; |
This file contains 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 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 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 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 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,62 @@ | ||
/* | ||
* Flavio Silva on July 22, 2023: | ||
* Temporary fix. | ||
* Issue: | ||
* https://github.com/OMikkel/tailwind-datepicker-react/issues/19 | ||
* Solution provided here: | ||
* https://github.com/OMikkel/tailwind-datepicker-react/issues/19#issuecomment-1621474204 | ||
*/ | ||
declare module 'tailwind-datepicker-react' { | ||
import { ReactElement } from 'react'; | ||
|
||
interface ITheme { | ||
background?: string; | ||
todayBtn?: string; | ||
clearBtn?: string; | ||
icons?: string; | ||
text?: string; | ||
disabledText?: string; | ||
input?: string; | ||
inputIcon?: string; | ||
selected?: string; | ||
} | ||
|
||
interface IIcons { | ||
prev: () => ReactElement; | ||
next: () => ReactElement; | ||
} | ||
|
||
export interface IOptions { | ||
title?: string; | ||
autoHide?: boolean; | ||
todayBtn?: boolean; | ||
todayBtnText?: string; | ||
clearBtn?: boolean; | ||
clearBtnText?: string; | ||
maxDate?: Date; | ||
minDate?: Date; | ||
theme?: ITheme; | ||
icons?: IIcons; | ||
datepickerClassNames?: string; | ||
defaultDate?: Date | null; | ||
language?: string; | ||
weekDays?: string[]; | ||
disabledDates?: Date[]; | ||
inputNameProp?: string; | ||
inputIdProp?: string; | ||
inputPlaceholderProp?: string; | ||
inputDateFormatProp?: Intl.DateTimeFormatOptions; | ||
} | ||
|
||
type DatepickerProps = { | ||
children?: ReactElement | ReactNode; | ||
options?: IOptions; | ||
onChange?: (date: Date) => void; | ||
show: boolean; | ||
setShow: (show: boolean) => void; | ||
classNames?: string; | ||
selectedDateState?: [Date, (date: Date) => void]; | ||
}; | ||
|
||
export default function Datepicker(props: DatepickerProps): ReactElement; | ||
} |