Skip to content

Commit

Permalink
build: 🔨 Add migration recover script
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 17, 2022
1 parent c9b3b04 commit d0119ee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"start:local": "ts-node index.ts",
"start:prod": "NODE_ENV=production ts-node index.ts",
"start:workspaces:migration": "ts-node workspaceMigration.ts"
"start:workspaces:migration": "ts-node workspaceMigration.ts",
"start:workspaces:migration:recover": "ts-node workspaceMigrationRecover.ts"
},
"devDependencies": {
"db": "*",
Expand Down
44 changes: 44 additions & 0 deletions packages/scripts/workspaceMigrationRecover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// See https://github.com/baptisteArno/typebot.io/issues/37

import { Plan, PrismaClient, WorkspaceRole } from 'db'
import path from 'path'

const prisma = new PrismaClient()

export const migrateWorkspace = async () => {
const user = await prisma.user.findFirst()
if (!user) return
console.log('Updating', user.email)
const newWorkspace = await prisma.workspace.create({
data: {
name: user.name ? `${user.name}'s workspace` : 'My workspace',
members: { create: { userId: user.id, role: WorkspaceRole.ADMIN } },
plan: Plan.TEAM,
},
})
await prisma.credentials.updateMany({
data: { workspaceId: newWorkspace.id },
})
await prisma.customDomain.updateMany({
data: { workspaceId: newWorkspace.id },
})
await prisma.dashboardFolder.updateMany({
data: { workspaceId: newWorkspace.id },
})
await prisma.typebot.updateMany({
data: { workspaceId: newWorkspace.id },
})
}

require('dotenv').config({
path: path.join(
__dirname,
process.env.NODE_ENV === 'production' ? '.env.production' : '.env.local'
),
})

const main = async () => {
await migrateWorkspace()
}

main().then()

4 comments on commit d0119ee

@vercel
Copy link

@vercel vercel bot commented on d0119ee May 17, 2022

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 d0119ee May 17, 2022

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 d0119ee May 17, 2022

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.