{"record":{"id":"b362d8bfcf109099","repo":"paperclipai/paperclip","slug":"destructive-plugin-migrations-are-not-allowed-in-p","errorCode":null,"errorMessage":"Destructive plugin migrations are not allowed in Phase 1","messagePattern":"Destructive plugin migrations are not allowed in Phase 1","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-database.ts","lineNumber":200,"sourceCode":"    /\\bdo\\s+(?:\\$\\$|language\\b)/,\n  ];\n  const matched = banned.find((pattern) => pattern.test(normalized));\n  if (matched) {\n    throw new Error(`Plugin SQL contains a disallowed statement or clause: ${matched.source}`);\n  }\n}\n\nexport function validatePluginMigrationStatement(\n  statement: string,\n  namespace: string,\n  coreReadTables: readonly PluginDatabaseCoreReadTable[] = [],\n): void {\n  assertIdentifier(namespace, \"namespace\");\n  assertNoBannedSql(statement);\n\n  const normalized = normaliseSql(statement);\n  if (/^\\s*(drop|truncate)\\b/.test(normalized)) {\n    throw new Error(\"Destructive plugin migrations are not allowed in Phase 1\");\n  }\n\n  if (/\\bdelete\\s+from\\b/.test(normalized)) {\n    throw new Error(\"Plugin migrations cannot delete data\");\n  }\n\n  const ddlOrBackfillAllowed =\n    /^(create|alter|comment)\\b/.test(normalized) ||\n    /^(insert\\s+into|update)\\b/.test(normalized) ||\n    (normalized.startsWith(\"with \") && /\\b(insert\\s+into|update)\\b/.test(normalized));\n  if (!ddlOrBackfillAllowed) {\n    throw new Error(\"Plugin migrations may contain DDL or namespace-scoped backfill statements only\");\n  }\n\n  const refs = extractQualifiedRefs(statement);\n  if (refs.length === 0 && !normalized.startsWith(\"comment \")) {\n    throw new Error(\"Plugin migration objects must use fully qualified schema names\");\n  }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/services/plugin-database.ts#L182-L218","documentation":"Phase-1 migration policy guard in validatePluginMigrationStatement: the statement begins with DROP or TRUNCATE. Plugin migrations may create and evolve their own namespace objects but may never destroy data or structures; the destructive migration file is at fault.","triggerScenarios":"Thrown at server/src/services/plugin-database.ts:200 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove destructive operations (DROP, TRUNCATE, etc.) from plugin migrations; they are not allowed in Phase 1."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}