{
  "schemaVersion": 1,
  "tool": {
    "name": "skewcheck",
    "version": "0.1.0"
  },
  "executionId": "example-J-check-constraint",
  "project": "fixture/J-check-constraint",
  "createdAt": "2026-10-24T18:30:07.504Z",
  "baselineRevision": "shop-v1",
  "candidateRevision": "J-check-constraint",
  "database": {
    "serverVersion": "16.15 (Debian 16.15-1.pgdg12+2)"
  },
  "proposedMigrations": [
    "002_positive_totals.sql"
  ],
  "experiment": [
    "control: old application (shop-v1) × baseline schema (1 migrations)",
    "candidate ×2: old application (shop-v1) × proposed schema (2 migrations)"
  ],
  "verdict": "UNSAFE",
  "blocking": true,
  "exitCode": 1,
  "summary": "The previous application version reproducibly fails against the proposed schema, and the failure is linked to a specific schema change.",
  "reasons": [
    "test/orders.test.js: SQLSTATE 23514 (check_violation) linked to constraint_added:orders.orders_total_positive by R4 constraint violation ↔ added/changed constraint."
  ],
  "recommendedAction": "Make the migration backward compatible (expand/contract: keep the old shape until the old version is retired), then re-run the gate.",
  "complete": true,
  "findings": [
    {
      "kind": "regression",
      "test": "test/orders.test.js",
      "facts": [
        "test/orders.test.js passes on the baseline schema and fails in all 2 candidate runs.",
        "New in every candidate run, absent from the control run: SQLSTATE 23514 (check_violation): new row for relation \"orders\" violates check constraint \"orders_total_positive\" — statement: INSERT INTO orders (customer_id, total_cents) VALUES ($1, $2) RETURNING id, status"
      ],
      "interpretation": "Constraint \"orders_total_positive\" is new or changed in the proposed schema and rejects a write the old application performs.",
      "sqlstate": "23514",
      "changeIds": [
        "constraint_added:orders.orders_total_positive"
      ],
      "rule": "R4 constraint violation ↔ added/changed constraint",
      "strength": "strong",
      "error": {
        "run": "cand1",
        "test": "test/orders.test.js",
        "sqlstate": "23514",
        "message": "new row for relation \"orders\" violates check constraint \"orders_total_positive\"",
        "detail": "Failing row contains (2, 2, 0, new, 2026-10-24 18:30:07.097605+00).",
        "statement": "INSERT INTO orders (customer_id, total_cents) VALUES ($1, $2) RETURNING id, status",
        "fingerprint": "insert into orders ( customer_id , total_cents ) values ( ? ) returning id , status",
        "key": "23514|new row for relation \"orders\" violates check constraint \"orders_total_positive\"|insert into orders ( customer_id , total_cents ) values ( ? ) returning id , status",
        "severity": "ERROR",
        "objects": {
          "relation": "orders",
          "constraint": "orders_total_positive"
        }
      }
    }
  ],
  "schemaChanges": [
    {
      "id": "constraint_added:orders.orders_total_positive",
      "kind": "constraint_added",
      "risk": "breaking",
      "schema": "public",
      "table": "orders",
      "object": "orders_total_positive",
      "after": "CHECK ((total_cents > 0))",
      "exercisedBy": [
        "insert",
        "update"
      ]
    }
  ],
  "coverage": [
    {
      "changeId": "constraint_added:orders.orders_total_positive",
      "target": "orders.orders_total_positive",
      "risk": "breaking",
      "required": true,
      "exercised": true,
      "statementCount": 3,
      "tests": [
        "test/orders.test.js"
      ],
      "staticReferences": [
        "src/orders.js:5",
        "src/orders.js:12",
        "src/orders.js:16",
        "test/orders.test.js:5",
        "test/orders.test.js:9"
      ]
    }
  ],
  "coverageSummary": "1 of 1 risk-bearing schema change(s) were exercised by the old application's tests in the control run.",
  "runs": [
    {
      "id": "ctl",
      "label": "control (old app × baseline schema)",
      "app": "baseline",
      "schema": "baseline",
      "database": "sc_ctl",
      "revision": "shop-v1",
      "completed": true,
      "migrations": [
        {
          "file": "001_init.sql",
          "ok": true
        }
      ],
      "tests": [
        {
          "test": "test/customers.test.js",
          "outcome": "pass",
          "exitCode": 0,
          "durationMs": 104,
          "outputTail": "TAP version 13\n# Subtest: signs up a customer and finds them by email\nok 1 - signs up a customer and finds them by email\n  ---\n  duration_ms: 11.438603\n  ...\n1..1\n# tests 1\n# suites 0\n# pass 1\n# fail 0\n# cancelled 0\n# skipped 0\n# todo 0\n# duration_ms 73.309326\n"
        },
        {
          "test": "test/orders.test.js",
          "outcome": "pass",
          "exitCode": 0,
          "durationMs": 100,
          "outputTail": "TAP version 13\n# Subtest: new orders start in status \"new\" and can be shipped\nok 1 - new orders start in status \"new\" and can be shipped\n  ---\n  duration_ms: 13.211311\n  ...\n1..1\n# tests 1\n# suites 0\n# pass 1\n# fail 0\n# cancelled 0\n# skipped 0\n# todo 0\n# duration_ms 72.886497\n"
        }
      ],
      "errors": [],
      "statements": 7
    },
    {
      "id": "cand1",
      "label": "candidate #1 (old app × proposed schema)",
      "app": "baseline",
      "schema": "candidate",
      "database": "sc_cand1",
      "revision": "shop-v1",
      "completed": true,
      "migrations": [
        {
          "file": "001_init.sql",
          "ok": true
        },
        {
          "file": "002_positive_totals.sql",
          "ok": true
        }
      ],
      "tests": [
        {
          "test": "test/customers.test.js",
          "outcome": "pass",
          "exitCode": 0,
          "durationMs": 103,
          "outputTail": "TAP version 13\n# Subtest: signs up a customer and finds them by email\nok 1 - signs up a customer and finds them by email\n  ---\n  duration_ms: 10.790569\n  ...\n1..1\n# tests 1\n# suites 0\n# pass 1\n# fail 0\n# cancelled 0\n# skipped 0\n# todo 0\n# duration_ms 73.296565\n"
        },
        {
          "test": "test/orders.test.js",
          "outcome": "fail",
          "exitCode": 1,
          "durationMs": 103,
          "outputTail": "TAP version 13\n# Subtest: new orders start in status \"new\" and can be shipped\nnot ok 1 - new orders start in status \"new\" and can be shipped\n  ---\n  duration_ms: 13.356322\n  location: '<app>/test/orders.test.js:9:1'\n  failureType: 'testCodeFailure'\n  error: 'new row for relation \"orders\" violates check constraint \"orders_total_positive\"'\n  code: '23514'\n  name: 'error'\n  stack: |-\n    <skewcheck>/node_modules/pg-pool/index.js:45:11\n    process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    async createOrder (<app>/src/orders.js:4:13)\n    async TestContext.<anonymous> (<app>/test/orders.test.js:14:16)\n    async Test.run (node:internal/test_runner/test:935:9)\n    async startSubtestAfterBootstrap (node:internal/test_runner/harness:296:3)\n  ...\n1..1\n# tests 1\n# suites 0\n# pass 0\n# fail 1\n# cancelled 0\n# skipped 0\n# todo 0\n# duration_ms 74.559866\n"
        }
      ],
      "errors": [
        {
          "run": "cand1",
          "test": "test/orders.test.js",
          "sqlstate": "23514",
          "message": "new row for relation \"orders\" violates check constraint \"orders_total_positive\"",
          "detail": "Failing row contains (2, 2, 0, new, 2026-10-24 18:30:07.097605+00).",
          "statement": "INSERT INTO orders (customer_id, total_cents) VALUES ($1, $2) RETURNING id, status",
          "fingerprint": "insert into orders ( customer_id , total_cents ) values ( ? ) returning id , status",
          "key": "23514|new row for relation \"orders\" violates check constraint \"orders_total_positive\"|insert into orders ( customer_id , total_cents ) values ( ? ) returning id , status",
          "severity": "ERROR",
          "objects": {
            "relation": "orders",
            "constraint": "orders_total_positive"
          }
        }
      ],
      "statements": 6
    },
    {
      "id": "cand2",
      "label": "candidate #2 (old app × proposed schema)",
      "app": "baseline",
      "schema": "candidate",
      "database": "sc_cand2",
      "revision": "shop-v1",
      "completed": true,
      "migrations": [
        {
          "file": "001_init.sql",
          "ok": true
        },
        {
          "file": "002_positive_totals.sql",
          "ok": true
        }
      ],
      "tests": [
        {
          "test": "test/customers.test.js",
          "outcome": "pass",
          "exitCode": 0,
          "durationMs": 97,
          "outputTail": "TAP version 13\n# Subtest: signs up a customer and finds them by email\nok 1 - signs up a customer and finds them by email\n  ---\n  duration_ms: 10.332815\n  ...\n1..1\n# tests 1\n# suites 0\n# pass 1\n# fail 0\n# cancelled 0\n# skipped 0\n# todo 0\n# duration_ms 69.881418\n"
        },
        {
          "test": "test/orders.test.js",
          "outcome": "fail",
          "exitCode": 1,
          "durationMs": 99,
          "outputTail": "TAP version 13\n# Subtest: new orders start in status \"new\" and can be shipped\nnot ok 1 - new orders start in status \"new\" and can be shipped\n  ---\n  duration_ms: 12.777391\n  location: '<app>/test/orders.test.js:9:1'\n  failureType: 'testCodeFailure'\n  error: 'new row for relation \"orders\" violates check constraint \"orders_total_positive\"'\n  code: '23514'\n  name: 'error'\n  stack: |-\n    <skewcheck>/node_modules/pg-pool/index.js:45:11\n    process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    async createOrder (<app>/src/orders.js:4:13)\n    async TestContext.<anonymous> (<app>/test/orders.test.js:14:16)\n    async Test.run (node:internal/test_runner/test:935:9)\n    async startSubtestAfterBootstrap (node:internal/test_runner/harness:296:3)\n  ...\n1..1\n# tests 1\n# suites 0\n# pass 0\n# fail 1\n# cancelled 0\n# skipped 0\n# todo 0\n# duration_ms 72.644171\n"
        }
      ],
      "errors": [
        {
          "run": "cand2",
          "test": "test/orders.test.js",
          "sqlstate": "23514",
          "message": "new row for relation \"orders\" violates check constraint \"orders_total_positive\"",
          "detail": "Failing row contains (2, 2, 0, new, 2026-10-24 18:30:07.337118+00).",
          "statement": "INSERT INTO orders (customer_id, total_cents) VALUES ($1, $2) RETURNING id, status",
          "fingerprint": "insert into orders ( customer_id , total_cents ) values ( ? ) returning id , status",
          "key": "23514|new row for relation \"orders\" violates check constraint \"orders_total_positive\"|insert into orders ( customer_id , total_cents ) values ( ? ) returning id , status",
          "severity": "ERROR",
          "objects": {
            "relation": "orders",
            "constraint": "orders_total_positive"
          }
        }
      ],
      "statements": 6
    }
  ],
  "skippedChecks": [
    "Current application × proposed schema (no current app configured).",
    "Performance / lock-time analysis (out of scope)."
  ],
  "limitations": [
    "Skewcheck only observes code paths that the old application's tests execute; untested paths are reported as coverage gaps, not as safe.",
    "Coverage is identifier-level: a statement \"touches\" a changed object when it names the table (and column, or uses *). It is not a SQL parser.",
    "Correlation between an error and a schema change uses a fixed set of deterministic rules (R1–R6). Anything else is reported as ADVISORY, never UNSAFE.",
    "Performance, locking and migration runtime on production-sized data are not evaluated.",
    "Test files of one run share a database and run sequentially; ordering effects are identical across runs but are not isolated.",
    "Data-only migration effects are detected only when a test asserts on the affected data."
  ],
  "policy": {
    "advisory": "warn",
    "noEvidence": "block",
    "inconclusive": "block",
    "candidateRepeats": 2,
    "testTimeoutMs": 60000,
    "maxBaselineFailureRatio": 0.5,
    "protectedPaths": [],
    "repairBranchPrefixes": [
      "skewcheck-repair/"
    ]
  }
}