Skip to content

Commit

Permalink
👷 Add daily database cleanup action
Browse files Browse the repository at this point in the history
Closes #201
  • Loading branch information
baptisteArno committed Jan 10, 2023
1 parent b142dc1 commit 4c2eaf9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 15 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/clean-database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Daily database cleanup

on:
schedule:
- cron: '0 6 * * *'

jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./packages/scripts
env:
DATABASE_URL: '${{ secrets.DATABASE_URL }}'
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2.2.2
- run: pnpm i --frozen-lockfile
- run: pnpm db:cleanDatabase
27 changes: 27 additions & 0 deletions packages/scripts/cleanDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PrismaClient } from 'db'
import { promptAndSetEnvironment } from './utils'

const prisma = new PrismaClient()

export const cleanDatabase = async () => {
await promptAndSetEnvironment('production')

console.log('Starting database cleanup...')
await deleteOldChatSessions()
console.log('Done!')
}

const deleteOldChatSessions = async () => {
const threeDaysAgo = new Date()
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3)
const { count } = await prisma.chatSession.deleteMany({
where: {
updatedAt: {
lte: threeDaysAgo,
},
},
})
console.log(`Deleted ${count} old chat sessions.`)
}

cleanDatabase().then()
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"private": true,
"scripts": {
"playground": "tsx playground.ts",
"db:cleanDatabase": "tsx cleanDatabase.ts",
"db:backup": "tsx backupDatabase.ts",
"db:restore": "tsx restoreDatabase.ts",
"db:setCustomPlan": "tsx setCustomPlan.ts",
Expand Down
34 changes: 19 additions & 15 deletions packages/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ import { join } from 'path'
import prompts from 'prompts'
import { isEmpty } from 'utils'

export const promptAndSetEnvironment = async () => {
const response = await prompts({
type: 'select',
name: 'env',
message: 'Pick an environment',
choices: [
{
title: 'Local',
value: 'local',
},
{ title: 'Staging', value: 'staging' },
{ title: 'Production', value: 'production' },
],
initial: 0,
})
export const promptAndSetEnvironment = async (
skipPrompt?: 'local' | 'staging' | 'production'
) => {
const response = skipPrompt
? { env: skipPrompt }
: await prompts({
type: 'select',
name: 'env',
message: 'Pick an environment',
choices: [
{
title: 'Local',
value: 'local',
},
{ title: 'Staging', value: 'staging' },
{ title: 'Production', value: 'production' },
],
initial: 0,
})

if (isEmpty(response.env)) process.exit()

Expand Down

5 comments on commit 4c2eaf9

@vercel
Copy link

@vercel vercel bot commented on 4c2eaf9 Jan 10, 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-alpha – ./apps/viewer

bot.artiweb.app
bot.devitus.com
bot.tc-mail.com
chat.sureb4.com
eventhub.com.au
games.klujo.com
sakuranembro.it
typebot.aloe.do
bot.piccinato.co
bot.sv-energy.it
botc.ceox.com.br
clo.closeer.work
cockroach.cr8.ai
faqs.nigerias.io
feedback.ofx.one
kw.wpwakanda.com
bot.truongnguyen.live
cdd.searchcube.com.sg
chat.missarkansas.org
chatbot.ownacademy.co
sbutton.wpwakanda.com
815639944.21000000.one
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bot.louismarcondes.com
bot.t20worldcup.com.au
c23111azqw.nigerias.io
felipewelington.com.br
form.searchcube.com.sg
gcase.barrettamario.it
help.giversforgood.com
info.clickasuransi.com
kodawariab736.skeep.it
my.swamprecordsgnv.com
premium.kandabrand.com
report.gratirabbit.com
resume.gratirabbit.com
83242573.actualizar.xyz
bot.blackboxtips.com.br
bot.upgradesolutions.eu
help.comebackreward.com
mainmenu.diddancing.com
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
link.cascadigital.com.br
onboarding.growthside.io
reward.onlinebotdemo.xyz
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
bot.fusionstarreviews.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thisiscrushhouse.com
sellmyharleylouisiana.com
verfica.botmachine.com.br
configurator.bouclidom.com
help.atlasoutfittersk9.com
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
piazzatorre.barrettamario.it
requests.swamprecordsgnv.com
type.cookieacademyonline.com
bot.brigadeirosemdrama.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
yourfeedback.comebackreward.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
viewer-v2-alpha-typebot-io.vercel.app
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-alpha-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 4c2eaf9 Jan 10, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 4c2eaf9 Jan 10, 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
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 4c2eaf9 Jan 10, 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
docs-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 4c2eaf9 Jan 10, 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

1stop.au
aginap.com
nepkit.com
bot.joof.it
bull.cr8.ai
cinecorn.com
kusamint.com
snake.cr8.ai
yoda.riku.ai
bergamo.store
bot.tvbeat.it
app.yvon.earth
bots.bridge.ai
chat.hayuri.id
gollum.riku.ai
gsbulletin.com
talk.gocare.io
bot.jesopizz.it
fitness.riku.ai
bot.contakit.com
zap.fundviser.in
bot.rihabilita.it
viewer.typebot.io
bot.danyservice.it
digitalhelp.com.au
bot.boston-voip.com
bot.dsignagency.com
chatbot.matthesv.de
demo.wemakebots.xyz
88584434.therpm.club
92109660.therpm.club
bot.barrettamario.it
hello.advergreen.com
bot.coachayongzul.com
bot.digitalpointer.id
bot.eikju.photography
bot.outstandbrand.com
bot.robertohairlab.it
criar.somaperuzzo.com
bot.ilmuseoaiborghi.it
bot.pratikmandalia.com
form.bridesquadapp.com
michaeljackson.riku.ai
87656003.actualizar.xyz
88152257.actualizar.xyz
91375310.actualizar.xyz
arrivalx2.wpwakanda.com
bot.hotelplayarimini.it
link.venturasuceder.com
manualhandlingcourse.ie
invite.bridesquadapp.com
bot.amicidisanfaustino.it
chat.thehomebuyersusa.com
forms.hiabhaykulkarni.com
healthandsafetycourses.uk
typebot-viewer.vercel.app
bot.adventureconsulting.hu
casestudyemb.wpwakanda.com
chat.atlasoutfittersk9.com
herbalife.barrettamario.it
homepageonly.wpwakanda.com
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
liveconvert2.kandalearn.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
forms.escoladeautomacao.com.br
viewer-v2-typebot-io.vercel.app
gerador.verificadordehospedes.com
bot.studiotecnicoimmobiliaremerelli.it
viewer-v2-git-main-typebot-io.vercel.app

Please sign in to comment.