mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
[CORL-649] Migrations (#2597)
* feat: added migration framework * chore: added premod user status migration * feat: enhanced error handling of migrations * fix: added missing argument from abstract method * fix: another templating blunder * fix: removed debug code * feat: enhanced migration tracking * fix: remove skipping migrations * feat: moved indexing to migration system * fix: linting
This commit is contained in:
@@ -19,10 +19,7 @@ import {
|
||||
} from "coral-server/models/action/comment";
|
||||
import {
|
||||
Connection,
|
||||
createCollection,
|
||||
createConnection,
|
||||
createConnectionOrderVariants,
|
||||
createIndexFactory,
|
||||
doesNotContainNull,
|
||||
FilterQuery,
|
||||
nodesToEdges,
|
||||
@@ -32,6 +29,7 @@ import {
|
||||
resolveConnection,
|
||||
} from "coral-server/models/helpers";
|
||||
import { TenantResource } from "coral-server/models/tenant";
|
||||
import { comments as collection } from "coral-server/services/mongodb/collections";
|
||||
|
||||
import { PUBLISHED_STATUSES } from "./constants";
|
||||
import {
|
||||
@@ -42,8 +40,6 @@ import {
|
||||
import { Revision } from "./revision";
|
||||
import { CommentTag } from "./tag";
|
||||
|
||||
const collection = createCollection<Comment>("comments");
|
||||
|
||||
/**
|
||||
* Comment's are created by User's on Stories. Each Comment contains a body, and
|
||||
* can be moderated by another Moderator or Admin User.
|
||||
@@ -128,84 +124,6 @@ export interface Comment extends TenantResource {
|
||||
deletedAt?: Date;
|
||||
}
|
||||
|
||||
export async function createCommentIndexes(mongo: Db) {
|
||||
const createIndex = createIndexFactory(collection(mongo));
|
||||
|
||||
// UNIQUE { id }
|
||||
await createIndex({ tenantID: 1, id: 1 }, { unique: true });
|
||||
|
||||
// Facility for counting the tags against a story.
|
||||
await createIndex(
|
||||
{
|
||||
tenantID: 1,
|
||||
storyID: 1,
|
||||
"tags.type": 1,
|
||||
status: 1,
|
||||
},
|
||||
{
|
||||
background: true,
|
||||
partialFilterExpression: {
|
||||
"tags.type": { $exists: true },
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const variants = createConnectionOrderVariants<Readonly<Comment>>([
|
||||
{ createdAt: -1 },
|
||||
{ createdAt: 1 },
|
||||
{ childCount: -1, createdAt: -1 },
|
||||
{ "actionCounts.REACTION": -1, createdAt: -1 },
|
||||
]);
|
||||
|
||||
// Story based Comment Connection pagination.
|
||||
// { storyID, ...connectionParams }
|
||||
await variants(createIndex, {
|
||||
tenantID: 1,
|
||||
storyID: 1,
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// Moderation based Comment Connection pagination.
|
||||
// { storyID, ...connectionParams }
|
||||
await variants(createIndex, {
|
||||
tenantID: 1,
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// Story based Comment Connection pagination that are flagged.
|
||||
// { storyID, ...connectionParams }
|
||||
await variants(createIndex, {
|
||||
tenantID: 1,
|
||||
storyID: 1,
|
||||
status: 1,
|
||||
"actionCounts.FLAG": 1,
|
||||
});
|
||||
|
||||
// Story + Reply based Comment Connection pagination.
|
||||
// { storyID, ...connectionParams }
|
||||
await variants(createIndex, {
|
||||
tenantID: 1,
|
||||
storyID: 1,
|
||||
parentID: 1,
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// Author based Comment Connection pagination.
|
||||
// { authorID, ...connectionParams }
|
||||
await variants(createIndex, {
|
||||
tenantID: 1,
|
||||
authorID: 1,
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// Tag based Comment Connection pagination.
|
||||
// { tags.type, ...connectionParams }
|
||||
await variants(createIndex, {
|
||||
tenantID: 1,
|
||||
"tags.type": 1,
|
||||
});
|
||||
}
|
||||
|
||||
export type CreateCommentInput = Omit<
|
||||
Comment,
|
||||
| "id"
|
||||
|
||||
Reference in New Issue
Block a user