Skip to content

Commit

Permalink
🗃️ Remove list types from db schema
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 1, 2023
1 parent 1806840 commit 6e0f0e4
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ export const subscribeWebhookProcedure = authenticatedProcedure
await prisma.webhook.upsert({
where: { id: webhookBlock.webhookId },
update: { url, body: '{{state}}', method: 'POST' },
create: { url, body: '{{state}}', method: 'POST', typebotId },
create: {
url,
body: '{{state}}',
method: 'POST',
typebotId,
headers: [],
queryParams: [],
},
})

return {
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/pages/api/auth/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function CustomAdapter(p: PrismaClient): Adapter {
},
},
},
onboardingCategories: [],
},
})
if (process.env.USER_CREATED_WEBHOOK_URL)
Expand Down
10 changes: 8 additions & 2 deletions apps/builder/src/pages/api/users/[userId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import prisma from '@/lib/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from '@/features/auth/api'
import { methodNotAllowed, notAuthenticated } from 'utils/api'
import { User } from 'db'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
if (!user) return notAuthenticated(res)

const id = req.query.userId as string
if (req.method === 'PUT') {
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
const data = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as User
const typebots = await prisma.user.update({
where: { id },
data,
data: {
...data,
onboardingCategories: data.onboardingCategories ?? [],
},
})
return res.send({ typebots })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
await prisma.webhook.upsert({
where: { id: webhookId },
update: { url, body: '{{state}}', method: 'POST' },
create: { url, body: '{{state}}', method: 'POST', typebotId },
create: {
url,
body: '{{state}}',
method: 'POST',
typebotId,
headers: [],
queryParams: [],
},
})

return res.send({ message: 'success' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
await prisma.webhook.upsert({
where: { id: webhookId },
update: { url, body: '{{state}}', method: 'POST' },
create: { url, body: '{{state}}', method: 'POST', typebotId },
create: {
url,
body: '{{state}}',
method: 'POST',
typebotId,
headers: [],
queryParams: [],
},
})

return res.send({ message: 'success' })
Expand Down
1 change: 1 addition & 0 deletions apps/viewer/src/pages/api/typebots/[typebotId]/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
data: {
typebotId,
isCompleted: false,
variables: [],
},
})
res.send({ result })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ALTER TABLE
"PublicTypebot"
ALTER COLUMN
variables TYPE JSONB USING array_to_json(variables);

ALTER TABLE
"Result"
ALTER COLUMN
variables TYPE JSONB USING array_to_json(variables);

ALTER TABLE
"Typebot"
ALTER COLUMN
variables TYPE JSONB USING array_to_json(variables);

ALTER TABLE
"User"
ALTER COLUMN
"onboardingCategories" TYPE JSONB USING array_to_json("onboardingCategories");

ALTER TABLE
"Webhook"
ALTER COLUMN
"queryParams" TYPE JSONB USING array_to_json("queryParams"),
ALTER COLUMN
"headers" TYPE JSONB USING array_to_json("headers");
14 changes: 7 additions & 7 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ model User {
emailVerified DateTime?
image String?
company String?
onboardingCategories String[]
onboardingCategories Json
graphNavigation GraphNavigation?
preferredAppAppearance String?
preferredAppAppearance String?
accounts Account[]
apiTokens ApiToken[]
CollaboratorsOnTypebots CollaboratorsOnTypebots[]
Expand Down Expand Up @@ -157,7 +157,7 @@ model Typebot {
name String
folderId String?
groups Json
variables Json[]
variables Json
edges Json
theme Json
settings Json
Expand Down Expand Up @@ -204,7 +204,7 @@ model PublicTypebot {
updatedAt DateTime @default(now()) @updatedAt
typebotId String @unique
groups Json
variables Json[]
variables Json
edges Json
theme Json
settings Json
Expand All @@ -216,7 +216,7 @@ model Result {
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
typebotId String
variables Json[]
variables Json
isCompleted Boolean
hasStarted Boolean?
isArchived Boolean? @default(false)
Expand Down Expand Up @@ -266,8 +266,8 @@ model Webhook {
id String @id @default(cuid())
url String?
method String
queryParams Json[]
headers Json[]
queryParams Json
headers Json
body String?
typebotId String
typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
Expand Down
17 changes: 14 additions & 3 deletions packages/utils/playwright/databaseActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const injectFakeResults = async ({
: new Date(),
isCompleted: rand > 0.5,
hasStarted: true,
}
variables: [],
} satisfies Prisma.ResultCreateManyInput
}),
],
})
Expand Down Expand Up @@ -135,7 +136,10 @@ export const createWorkspaces = async (workspaces: Partial<Workspace>[]) => {

export const updateUser = (data: Partial<User>) =>
prisma.user.update({
data,
data: {
...data,
onboardingCategories: data.onboardingCategories ?? [],
},
where: {
id: userId,
},
Expand All @@ -149,7 +153,14 @@ export const createWebhook = async (
await prisma.webhook.delete({ where: { id: 'webhook1' } })
} catch {}
return prisma.webhook.create({
data: { method: 'GET', typebotId, id: 'webhook1', ...webhookProps },
data: {
method: 'GET',
typebotId,
id: 'webhook1',
...webhookProps,
queryParams: webhookProps?.queryParams ?? [],
headers: webhookProps?.headers ?? [],
},
})
}

Expand Down
8 changes: 7 additions & 1 deletion packages/utils/playwright/databaseSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const setupUsers = async () => {
email: 'user@email.com',
name: 'John Doe',
graphNavigation: GraphNavigation.TRACKPAD,
onboardingCategories: [],
apiTokens: {
createMany: {
data: [
Expand All @@ -82,7 +83,12 @@ export const setupUsers = async () => {
},
})
await prisma.user.create({
data: { id: otherUserId, email: 'other-user@email.com', name: 'James Doe' },
data: {
id: otherUserId,
email: 'other-user@email.com',
name: 'James Doe',
onboardingCategories: [],
},
})
return prisma.memberInWorkspace.createMany({
data: [
Expand Down

4 comments on commit 6e0f0e4

@vercel
Copy link

@vercel vercel bot commented on 6e0f0e4 Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

bot.eikju.photography
bot.incusservices.com
bot.meuesocial.com.br
bot.mycompany.reviews
bot.outstandbrand.com
bot.ramonmatos.com.br
bot.robertohairlab.it
bot.sharemyreview.net
bot.truongnguyen.live
botz.cloudsiteapp.com
cdd.searchcube.com.sg
chat.missarkansas.org
chatbot.ownacademy.co
criar.somaperuzzo.com
sbutton.wpwakanda.com
815639944.21000000.one
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bot.ilmuseoaiborghi.it
bot.louismarcondes.com
bot.pratikmandalia.com
bot.t20worldcup.com.au
c23111azqw.nigerias.io
dieta.barrettamario.it
felipewelington.com.br
form.bridesquadapp.com
form.searchcube.com.sg
gcase.barrettamario.it
help.giversforgood.com
info.clickasuransi.com
kodawariab736.skeep.it
michaeljackson.riku.ai
premium.kandabrand.com
report.gratirabbit.com
resume.gratirabbit.com
83242573.actualizar.xyz
87656003.actualizar.xyz
88152257.actualizar.xyz
91375310.actualizar.xyz
arrivalx2.wpwakanda.com
bot.blackboxtips.com.br
bot.hotelplayarimini.it
bot.upgradesolutions.eu
bots.baptiste-arnaud.fr
help.comebackreward.com
link.venturasuceder.com
mainmenu.diddancing.com
manualhandlingcourse.ie
register.kandabrand.com
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
91181264.your-access.one
ai.chromebookstoreph.com
form.sergiolimajr.com.br
hunterbot.saleshunter.ai
invite.bridesquadapp.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
piazzatorre.barrettamario.it
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6e0f0e4 Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 6e0f0e4 Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6e0f0e4 Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.