{"record":{"id":"d28ebb04421a636a","repo":"paperclipai/paperclip","slug":"plugin-migrations-cannot-delete-data","errorCode":null,"errorMessage":"Plugin migrations cannot delete data","messagePattern":"Plugin migrations cannot delete data","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-database.ts","lineNumber":204,"sourceCode":"    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  }\n\n  const objectRefKeywords = new Set([\n    \"alter table\",\n    \"create index\",","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/services/plugin-database.ts#L186-L222","documentation":"Migration policy guard: the statement contains DELETE FROM. Phase 1 plugin migrations may only perform DDL or namespace-scoped backfills (insert/update), never row deletion, to guarantee migrations are non-lossy; the deleting migration is at fault.","triggerScenarios":"Thrown at server/src/services/plugin-database.ts:204 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove DELETE/data-deleting statements from the plugin migration."],"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-14T00:17:10.932Z"}