MCPcopy Index your code
hub / github.com/simstudioai/sim / assertSchemaCompatibility

Function assertSchemaCompatibility

apps/realtime/src/database/preflight.ts:65–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63 * across {@link MAX_CONNECT_ATTEMPTS} attempts.
64 */
65export async function assertSchemaCompatibility(): Promise<void> {
66 let lastError: unknown
67
68 for (let attempt = 1; attempt <= MAX_CONNECT_ATTEMPTS; attempt++) {
69 try {
70 await db.select().from(workflow).limit(1)
71 logger.info('Schema-compatibility check passed')
72 return
73 } catch (error) {
74 lastError = error
75
76 if (isSchemaMismatch(error)) {
77 throw new Error(
78 `Deployed image is incompatible with the live database schema: ${getErrorMessage(error)}`
79 )
80 }
81
82 if (attempt === MAX_CONNECT_ATTEMPTS) {
83 break
84 }
85
86 const delay = backoffWithJitter(attempt, null)
87 logger.warn(
88 `Schema-compatibility check could not reach the database (attempt ${attempt}/${MAX_CONNECT_ATTEMPTS}), retrying in ${Math.round(delay)}ms`,
89 getErrorMessage(error)
90 )
91 await sleep(delay)
92 }
93 }
94
95 throw new Error(
96 `Schema-compatibility check failed after ${MAX_CONNECT_ATTEMPTS} attempts — database unreachable: ${getErrorMessage(lastError)}`
97 )
98}

Callers 2

mainFunction · 0.90
preflight.test.tsFile · 0.90

Calls 6

getErrorMessageFunction · 0.90
backoffWithJitterFunction · 0.90
sleepFunction · 0.90
isSchemaMismatchFunction · 0.85
infoMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected