-
-
Notifications
You must be signed in to change notification settings - Fork 50
[Fix] Recover conversation migration state safely #817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { existsSync } from 'fs' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { createHash, randomUUID } from 'crypto' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Context } from 'koishi' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Config } from '../config' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -15,13 +16,19 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LegacyRoomRecord, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LegacyUserRecord | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '../services/types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { defineLegacyMigrationTables } from './legacy_tables' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defineLegacyMigrationTables, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isMissingTableError, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LEGACY_MIGRATION_TABLES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from './legacy_tables' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { BindingProgress, MessageProgress, RoomProgress } from './types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aclKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createLegacyBindingKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createLegacyTableRetention, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createPassedValidationResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filterValidRooms, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLegacySchemaSentinel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inferLegacyGroupRouteModes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isComplexRoom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LEGACY_RETENTION_META_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -43,7 +50,13 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx: Context, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config: Config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defineLegacyMigrationTables(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasSentinel = existsSync(getLegacySchemaSentinel(ctx.baseDir)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasSentinel && !(await hasLegacyMigrationData(ctx))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ensureMigrationValidated(ctx, config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defineLegacyMigrationTables(ctx, hasSentinel) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await readMetaValue< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Awaited<ReturnType<typeof validateRoomMigration>> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,6 +69,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (await readMetaValue<boolean>(ctx, 'message_migration_done')) ?? false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| !hasSentinel && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schemaVersion >= BUILTIN_SCHEMA_VERSION && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (result?.passed === true || (roomDone && messageDone)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -88,6 +102,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('ChatLuna migration validation failed.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Mark completion before purge so a restart after writing the sentinel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // can resume from the finished state instead of re-reading legacy tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationDone(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await purgeLegacyTables(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationFinished(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -99,67 +116,174 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // runRoomToConversationMigration when flags indicate migration is incomplete, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // while runRoomToConversationMigration only calls ensureMigrationValidated when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // flags indicate it IS complete — so the two paths are mutually exclusive. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function ensureMigrationValidated(ctx: Context, config: Config) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasSentinel = existsSync(getLegacySchemaSentinel(ctx.baseDir)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasLegacyData = hasSentinel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? await hasLegacyMigrationData(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasSentinel && hasLegacyData) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.logger.warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Legacy sentinel exists but legacy ChatHub data is still present; continuing migration from legacy tables.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defineLegacyMigrationTables(ctx, true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await readMetaValue< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Awaited<ReturnType<typeof validateRoomMigration>> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| >(ctx, 'validation_result') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const retention = await readMetaValue<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state?: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }>(ctx, LEGACY_RETENTION_META_KEY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasSentinel) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasLegacyData) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return runRoomToConversationMigration(ctx, config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result?.passed === true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'schema_version', BUILTIN_SCHEMA_VERSION) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationDone(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationFinished(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const conversations = (await ctx.database.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'chatluna_conversation', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| limit: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )) as ConversationRecord[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const messages = (await ctx.database.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'chatluna_message', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| limit: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )) as MessageRecord[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const bindings = (await ctx.database.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'chatluna_binding', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| limit: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )) as BindingRecord[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const acl = (await ctx.database.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'chatluna_acl', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| limit: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )) as ACLRecord[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+151
to
+178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These four database queries are executed sequentially, which can be optimized by using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasData = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| conversations.length > 0 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages.length > 0 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bindings.length > 0 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| acl.length > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.logger.warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? 'Legacy sentinel exists and ChatLuna data is present; adopting current ChatLuna state and marking migration finished.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : 'Legacy sentinel exists and ChatLuna data is empty; treating startup as fresh install.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const validated = createPassedValidationResult() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'schema_version', BUILTIN_SCHEMA_VERSION) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'validation_result', validated) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationDone(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationFinished(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return validated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result?.passed === true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'schema_version', BUILTIN_SCHEMA_VERSION) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationDone(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (retention?.state !== 'purged') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await purgeLegacyTables(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationFinished(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const schemaVersion = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (await readMetaValue<number>(ctx, 'schema_version')) ?? 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const roomDone = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (await readMetaValue<boolean>(ctx, 'room_migration_done')) ?? false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const messageDone = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (await readMetaValue<boolean>(ctx, 'message_migration_done')) ?? false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schemaVersion < BUILTIN_SCHEMA_VERSION || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| roomDone !== true || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messageDone !== true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Migration is genuinely incomplete; restart it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // runRoomToConversationMigration will NOT call back into ensureMigrationValidated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // because it only does so when all done-flags are true, which they are not here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return runRoomToConversationMigration(ctx, config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (retention?.state !== 'purged') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defineLegacyMigrationTables(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const validated = await validateRoomMigration(ctx, config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'validation_result', validated) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!validated.passed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('ChatLuna migration validation failed.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationDone(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await purgeLegacyTables(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMigrationFinished(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return validated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function writeMigrationFinished(ctx: Context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'migration_finished_at', new Date().toISOString()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function writeMigrationDone(ctx: Context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'room_migration_done', true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'message_migration_done', true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function writeMigrationFinished(ctx: Context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LEGACY_RETENTION_META_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createLegacyTableRetention('purged') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeMetaValue(ctx, 'migration_finished_at', new Date().toISOString()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function hasLegacyMigrationData(ctx: Context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defineLegacyMigrationTables(ctx, true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const table of LEGACY_MIGRATION_TABLES) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await ctx.database.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| table as never, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| limit: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).length > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!isMissingTableError(error)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // (#6) removed redundant inner `done` check — the caller already guards on room_migration_done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,8 +336,6 @@ export class ConversationService { | |
| } | ||
| } | ||
|
|
||
| await assertManageAllowed(session, resolved.constraint) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the if (resolved.constraint.routeMode !== 'personal') {
await assertManageAllowed(session, resolved.constraint)
} |
||
|
|
||
| if (!resolved.constraint.allowNew) { | ||
| throw new Error('Conversation creation is disabled by constraint.') | ||
| } | ||
|
Comment on lines
339
to
341
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Removing the Useful? React with 👍 / 👎. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call to
defineLegacyMigrationTablesis redundant. ThehasLegacyMigrationDatafunction, which is called just a few lines above at line 122, already ensures that the legacy tables are defined by callingdefineLegacyMigrationTables(ctx, true)internally.