Skip to content

Commit

Permalink
feat: consolidated migrations for 6.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Feb 7, 2020
1 parent e722cef commit 7788488
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 1,191 deletions.
32 changes: 21 additions & 11 deletions src/core/server/services/migrate/indexing.ts
@@ -1,10 +1,12 @@
import { merge } from "lodash";
import { Collection, IndexOptions } from "mongodb";
import { Collection, Db, IndexOptions } from "mongodb";
import now from "performance-now";

import { Writable } from "coral-common/types";
import logger from "coral-server/logger";

import collections from "../mongodb/collections";

type IndexType = 1 | -1 | "text";

export type IndexSpecification<T> = {
Expand Down Expand Up @@ -61,28 +63,36 @@ export function createIndexFactory<T>(

export function createConnectionOrderVariants<T>(
createIndexFn: IndexCreationFunction<T>,
variants: Array<IndexSpecification<T>>,
indexOptions: IndexOptions = { background: true }
variants: Array<IndexSpecification<T>>
) {
return async (
indexSpec: IndexSpecification<T>,
variantIndexOptions: IndexOptions = {}
) => {
return async (indexSpec: IndexSpecification<T>) => {
/**
* createIndexVariant will create a variant on the specified `indexSpec` that
* will include the new variation.
*
* @param variantSpec the spec that makes this variant different
*/
const createIndexVariant = (variantSpec: IndexSpecification<T>) =>
createIndexFn(
merge({}, indexSpec, variantSpec),
merge({}, indexOptions, variantIndexOptions)
);
createIndexFn(merge({}, indexSpec, variantSpec), { background: true });

// Create all the variants.
for (const variant of variants) {
await createIndexVariant(variant);
}
};
}

export const createIndexesFactory = (mongo: Db) => ({
users: createIndexFactory(collections.users(mongo)),
invites: createIndexFactory(collections.invites(mongo)),
tenants: createIndexFactory(collections.tenants(mongo)),
comments: createIndexFactory(collections.comments(mongo)),
stories: createIndexFactory(collections.stories(mongo)),
commentActions: createIndexFactory(collections.commentActions(mongo)),
commentModerationActions: createIndexFactory(
collections.commentModerationActions(mongo)
),
queries: createIndexFactory(collections.queries(mongo)),
migrations: createIndexFactory(collections.migrations(mongo)),
sites: createIndexFactory(collections.sites(mongo)),
});

This file was deleted.

0 comments on commit 7788488

Please sign in to comment.