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();