From e6b97dc96cfaef0332cd8ce4162412e27bf2a80e Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 13 Sep 2017 07:40:11 +0200 Subject: [PATCH] Ensure things exist for new workspaces (Closes #482) --- app/models/workspace.js | 12 ++++++++++-- app/ui/index.js | 6 ------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/workspace.js b/app/models/workspace.js index a60aae15a..916a7280d 100644 --- a/app/models/workspace.js +++ b/app/models/workspace.js @@ -1,6 +1,7 @@ // @flow import type {BaseModel} from './index'; import * as db from '../common/database'; +import * as models from './index'; export const name = 'Workspace'; export const type = 'Workspace'; @@ -46,8 +47,15 @@ export function getById (id: string): Promise { return db.get(type, id); } -export function create (patch: Object = {}): Promise { - return db.docCreate(type, patch); +export async function create (patch: Object = {}): Promise { + const workspace = await db.docCreate(type, patch); + + // Make sure CookieJars and environments exist for all workspaces + // TODO: Find a better place to do this + await models.cookieJar.getOrCreateForParentId(workspace._id); + await models.environment.getOrCreateForWorkspace(workspace); + + return workspace; } export async function all (): Promise> { diff --git a/app/ui/index.js b/app/ui/index.js index 4c9c66d86..a9e8c480d 100644 --- a/app/ui/index.js +++ b/app/ui/index.js @@ -21,12 +21,6 @@ import {isDevelopment} from '../common/constants'; await initAnalytics(getAccountId()); await initPlugins(); - // Make sure CookieJars and environments exist for all workspaces - for (const workspace of await models.workspace.all()) { - await models.cookieJar.getOrCreateForParentId(workspace._id); - await models.environment.getOrCreateForWorkspace(workspace); - } - // Create Redux store const store = await initStore();