Skip to content

Commit

Permalink
Merge branch 'release/1.6.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Oct 21, 2024
2 parents 05f7d0f + 8081367 commit aba3ea6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 8 deletions.
15 changes: 15 additions & 0 deletions cosmosdb-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# adaptTo() Live Server - Schema Creation for Cosmos DB (MS Azure)

As stated in the [CosmosDB documentation][cosmosdb-limitations], it's not possible to create a unique index after a collection was created:

> Azure Cosmos DB API for SQL or MongoDB accounts that create unique index after the container is created aren't supported for continuous backup. Only containers that create unique index as a part of the initial container creation are supported. For MongoDB accounts, you create unique index using [extension commands][cosmosdb-extension-commands].
The collection `qa-entries` requires a compound unique partial index to ensure the `entryIndex` numbers are numbered continuously for each talk, generating a number of QA entry numbers for each talk. This works via Mongoose schema definition of a native MongoDB instance, but not for CosmosDB with continuous backup.

The solution is to drop the collection `qa-entries` after creating the collections via Mongoose on server setup, and then recreate it via MongoDB shell using this script:

[qa-entries.txt](qa-entries.txt)


[cosmosdb-limitations]: https://learn.microsoft.com/en-us/azure/cosmos-db/continuous-backup-restore-introduction#current-limitations
[cosmosdb-extension-commands]: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/custom-commands
49 changes: 49 additions & 0 deletions cosmosdb-schema/qa-entries.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use adaptto-live

db["qa-entries"].drop()

db.runCommand({
customAction: "CreateCollection",
collection: "qa-entries",
indexes: [
{
name: "_id_",
key: { "_id": 1 },
unique: true
},
{
name: "talkId_1",
key: { "talkId": 1 }
},
{
name: "date_1",
key: { "date": 1 }
},
{
name: "userid_1",
key: { "userid": 1 }
},
{
name: "entryIndex_1",
key: { "entryIndex": 1 }
},
{
name: "replyTo_1",
key: { "replyTo": 1 }
},
{
name: "userid_1_username_1",
key: { "userid": 1, "username": 1 }
},
{
name: "qaEntryId_1_userid_1",
key: { "qaEntryId": 1, "userid": 1 }
},
{
name: "talkId_1_entryIndex_1",
key: { "talkId": 1, "entryIndex": -1 },
unique: true,
partialFilterExpression: { "entryIndex": { "$gt": 0 } }
}
]
})
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adaptto-live-server",
"version": "1.6.2",
"version": "1.6.3",
"private": true,
"scripts": {
"dev": "nodemon src/index.ts | pino-pretty",
Expand Down
4 changes: 2 additions & 2 deletions src/socket/admin/kpi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import log from '../../util/log'
import { MessageModel, QAEntryModel, TalkRatingModel, UserModel } from '../../repository/mongodb.schema'

export async function handleAdminKPI(socket : Socket<ClientToServerEvents,ServerToClientEvents,InterServerEvents,SocketData>) {
const { admin } = socket.data
const { admin, qaadmin } = socket.data
const minuteSlots = [0, 30]

// admin-only operations
if (!admin) {
if (!(admin || qaadmin)) {
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/socket/admin/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import log from '../../util/log'
import { LoginCodeModel, MessageModel, QAEntryModel, TalkRatingModel, UserModel } from '../../repository/mongodb.schema'

export async function handleAdminStatistics(socket : Socket<ClientToServerEvents,ServerToClientEvents,InterServerEvents,SocketData>) {
const { admin } = socket.data
const { admin, qaadmin } = socket.data

// admin-only operations
if (!admin) {
if (!(admin || qaadmin)) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion src/socket/socket.server.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface InterServerEvents {} // eslint-disable-line @typescript-eslint/no-empty-interface
export interface InterServerEvents {} // eslint-disable-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type

export interface SocketData {
userid: string
Expand Down

0 comments on commit aba3ea6

Please sign in to comment.