diff --git a/packages/prisma/migrations/20220502154345_adds_apps/migration.sql b/packages/prisma/migrations/20220502154345_adds_apps/migration.sql index ae44691d70..72a97bf191 100644 --- a/packages/prisma/migrations/20220502154345_adds_apps/migration.sql +++ b/packages/prisma/migrations/20220502154345_adds_apps/migration.sql @@ -24,20 +24,3 @@ CREATE UNIQUE INDEX "App_dirName_key" ON "App"("dirName"); -- AddForeignKey ALTER TABLE "Credential" ADD CONSTRAINT "Credential_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App"("slug") ON DELETE CASCADE ON UPDATE CASCADE; - --- Connects each saved Credential to their respective App -UPDATE "Credential" SET "appId" = 'apple-calendar' WHERE "type" = 'apple_calendar'; -UPDATE "Credential" SET "appId" = 'caldav-calendar' WHERE "type" = 'caldav_calendar'; -UPDATE "Credential" SET "appId" = 'google-calendar' WHERE "type" = 'google_calendar'; -UPDATE "Credential" SET "appId" = 'google-meet' WHERE "type" = 'google_video'; -UPDATE "Credential" SET "appId" = 'office365-calendar' WHERE "type" = 'office365_calendar'; -UPDATE "Credential" SET "appId" = 'msteams' WHERE "type" = 'office365_video'; -UPDATE "Credential" SET "appId" = 'dailyvideo' WHERE "type" = 'daily_video'; -UPDATE "Credential" SET "appId" = 'tandem' WHERE "type" = 'tandem_video'; -UPDATE "Credential" SET "appId" = 'zoom' WHERE "type" = 'zoom_video'; -UPDATE "Credential" SET "appId" = 'jitsi' WHERE "type" = 'jitsi_video'; -UPDATE "Credential" SET "appId" = 'hubspot' WHERE "type" = 'hubspot_other_calendar'; -UPDATE "Credential" SET "appId" = 'wipe-my-cal' WHERE "type" = 'wipemycal_other'; -UPDATE "Credential" SET "appId" = 'huddle01' WHERE "type" = 'huddle01_video'; -UPDATE "Credential" SET "appId" = 'slack' WHERE "type" = 'slack_messaging'; -UPDATE "Credential" SET "appId" = 'stripe' WHERE "type" = 'stripe_payment'; diff --git a/packages/prisma/migrations/20220502154345_adds_metamask_giphy/migration.sql b/packages/prisma/migrations/20220502154345_adds_metamask_giphy/migration.sql deleted file mode 100644 index 6de4fe4194..0000000000 --- a/packages/prisma/migrations/20220502154345_adds_metamask_giphy/migration.sql +++ /dev/null @@ -1,3 +0,0 @@ --- Connects each saved Credential to their respective App -UPDATE "Credential" SET "appId" = 'metamask' WHERE "type" = 'metamask_web3'; -UPDATE "Credential" SET "appId" = 'giphy' WHERE "type" = 'giphy_other'; diff --git a/packages/prisma/seed-app-store.ts b/packages/prisma/seed-app-store.ts index 85741e7a8f..c233366ccf 100644 --- a/packages/prisma/seed-app-store.ts +++ b/packages/prisma/seed-app-store.ts @@ -9,6 +9,7 @@ async function createApp( /** The directory name for `/packages/app-store/[dirName]` */ dirName: Prisma.AppCreateInput["dirName"], categories: Prisma.AppCreateInput["categories"], + type: Prisma.CredentialCreateInput["type"], keys?: Prisma.AppCreateInput["keys"] ) { await prisma.app.upsert({ @@ -16,71 +17,79 @@ async function createApp( create: { slug, dirName, categories, keys }, update: { dirName, categories, keys }, }); + await prisma.credential.updateMany({ + where: { type }, + data: { appId: slug }, + }); console.log(`📲 Upserted app: '${slug}'`); } async function main() { // Calendar apps - await createApp("apple-calendar", "applecalendar", ["calendar"]); - await createApp("caldav-calendar", "caldavcalendar", ["calendar"]); + await createApp("apple-calendar", "applecalendar", ["calendar"], "apple_calendar"); + await createApp("caldav-calendar", "caldavcalendar", ["calendar"], "caldav_calendar"); try { const { client_secret, client_id, redirect_uris } = JSON.parse(process.env.GOOGLE_API_CREDENTIALS).web; - await createApp("google-calendar", "googlecalendar", ["calendar"], { + await createApp("google-calendar", "googlecalendar", ["calendar"], "google_calendar", { + client_id, + client_secret, + redirect_uris, + }); + await createApp("google-meet", "googlevideo", ["video"], "google_video", { client_id, client_secret, redirect_uris, }); - await createApp("google-meet", "googlevideo", ["video"], { client_id, client_secret, redirect_uris }); } catch (e) { if (e instanceof Error) console.error("Error adding google credentials to DB:", e.message); } if (process.env.MS_GRAPH_CLIENT_ID && process.env.MS_GRAPH_CLIENT_SECRET) { - await createApp("office365-calendar", "office365calendar", ["calendar"], { + await createApp("office365-calendar", "office365calendar", ["calendar"], "office365_calendar", { client_id: process.env.MS_GRAPH_CLIENT_ID, client_secret: process.env.MS_GRAPH_CLIENT_SECRET, }); - await createApp("msteams", "office365video", ["video"]); + await createApp("msteams", "office365video", ["video"], "office365_video"); } // Video apps if (process.env.DAILY_API_KEY) { - await createApp("dailyvideo", "dailyvideo", ["video"], { + await createApp("dailyvideo", "dailyvideo", ["video"], "daily_video", { api_key: process.env.DAILY_API_KEY, scale_plan: process.env.DAILY_SCALE_PLAN, }); } if (process.env.TANDEM_CLIENT_ID && process.env.TANDEM_CLIENT_SECRET) { - await createApp("tandem", "tandemvideo", ["video"], { + await createApp("tandem", "tandemvideo", ["video"], "tandem_video", { client_id: process.env.TANDEM_CLIENT_ID as string, client_secret: process.env.TANDEM_CLIENT_SECRET as string, base_url: (process.env.TANDEM_BASE_URL as string) || "https://tandem.chat", }); } if (process.env.ZOOM_CLIENT_ID && process.env.ZOOM_CLIENT_SECRET) { - await createApp("zoom", "zoomvideo", ["video"], { + await createApp("zoom", "zoomvideo", ["video"], "zoom_video", { client_id: process.env.ZOOM_CLIENT_ID, client_secret: process.env.ZOOM_CLIENT_SECRET, }); } - await createApp("jitsi", "jitsivideo", ["video"]); + await createApp("jitsi", "jitsivideo", ["video"], "jitsi_video"); // Other apps if (process.env.HUBSPOT_CLIENT_ID && process.env.HUBSPOT_CLIENT_SECRET) { - await createApp("hubspot", "hubspotothercalendar", ["other"], { + await createApp("hubspot", "hubspotothercalendar", ["other"], "hubspot_other_calendar", { client_id: process.env.HUBSPOT_CLIENT_ID, client_secret: process.env.HUBSPOT_CLIENT_SECRET, }); } - await createApp("wipe-my-cal", "wipemycalother", ["other"]); + await createApp("wipe-my-cal", "wipemycalother", ["other"], "wipemycal_other"); if (process.env.GIPHY_API_KEY) { - await createApp("giphy", "giphy", ["other"], { + await createApp("giphy", "giphy", ["other"], "giphy_other", { api_key: process.env.GIPHY_API_KEY, }); } // Web3 apps - await createApp("huddle01", "huddle01video", ["web3", "video"]); - await createApp("metamask", "metamask", ["web3"]); + await createApp("huddle01", "huddle01video", ["web3", "video"], "huddle01_video"); + await createApp("metamask", "metamask", ["web3"], "metamask_web3"); // Messaging apps if (process.env.SLACK_CLIENT_ID && process.env.SLACK_CLIENT_SECRET && process.env.SLACK_SIGNING_SECRET) { - await createApp("slack", "slackmessaging", ["messaging"], { + await createApp("slack", "slackmessaging", ["messaging"], "slack_messaging", { client_id: process.env.SLACK_CLIENT_ID, client_secret: process.env.SLACK_CLIENT_SECRET, signing_secret: process.env.SLACK_SIGNING_SECRET, @@ -93,7 +102,7 @@ async function main() { process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY && process.env.STRIPE_WEBHOOK_SECRET ) { - await createApp("stripe", "stripepayment", ["payment"], { + await createApp("stripe", "stripepayment", ["payment"], "stripe_payment", { client_id: process.env.STRIPE_CLIENT_ID, client_secret: process.env.STRIPE_PRIVATE_KEY, payment_fee_fixed: 10,