{
  "schemaVersion": "0.1",
  "id": "first-paid-pilot-d1-persistence-migration-pack-20260817",
  "generatedAt": "2026-08-17T22:44:00+08:00",
  "status": "d1-persistence-migration-pack-ready-not-executed",
  "purpose": "Prepare the first paid pilot service-confirmation workflow for Cloudflare D1 persistence after the browser localStorage ledger prototype. This package defines the minimum server-side tables, API contract, migration runbook and closed commercial gates without creating a database, binding a Worker, collecting payment, publishing articles or claiming AI adoption.",
  "productionPage": "/reports/first-paid-pilot-d1-persistence-migration-pack-20260817.html",
  "humanReport": "/docs/FIRST_PAID_PILOT_D1_PERSISTENCE_MIGRATION_PACK_20260817.md",
  "sqlMigration": "/migrations/0001_first_paid_pilot_service_confirmations.sql",
  "sourcePrototype": {
    "ledgerPrototype": "/reports/first-paid-pilot-service-confirmation-ledger-prototype-20260817.html",
    "ledgerPrototypeData": "/data/first-paid-pilot-service-confirmation-ledger-prototype-20260817.json",
    "formPrototype": "/reports/first-paid-pilot-service-confirmation-form-prototype-20260817.html",
    "formSchema": "/data/first-paid-pilot-service-confirmation-form-schema-20260817.json"
  },
  "decision": {
    "recommendedNextBuildStep": "Only after explicit user authorization, create a Cloudflare D1 database, apply the migration locally first, bind it to a protected internal Pages Function or Worker, and move the localStorage ledger import/export flow behind staff-only authentication.",
    "notRecommendedNow": [
      "Do not open self-service recharge publishing.",
      "Do not create public customer login before contract/payment/legal review gates are signed off.",
      "Do not treat payment_status=paid in any form as payment proof.",
      "Do not promise AI indexing, natural recommendation, ranking or model training absorption.",
      "Do not create or mutate Cloudflare D1/KV/Worker resources without a separate explicit authorization."
    ]
  },
  "tables": [
    {
      "name": "geo_service_confirmations",
      "purpose": "One service confirmation record per first paid pilot or internal sample.",
      "keyFields": [
        "service_confirmation_id",
        "service_mode",
        "service_provider_legal_entity",
        "customer_legal_entity",
        "customer_brand_name",
        "brand_authorization_scope",
        "public_material_scope_json",
        "sponsored_disclosure_accepted",
        "no_ai_outcome_guarantee_accepted",
        "external_action_authorization_json",
        "selected_tier",
        "quoted_amount_cny",
        "payment_status",
        "invoice_status",
        "target_question",
        "target_platforms_json",
        "deliverable_units_json",
        "acceptance_evidence_paths_json",
        "blocked_claims",
        "p0_evidence_status",
        "client_written_confirmation",
        "legal_finance_review_status",
        "readiness_status"
      ]
    },
    {
      "name": "geo_service_confirmation_units",
      "purpose": "Track the promised diagnostic, content, verification and report units under a service confirmation."
    },
    {
      "name": "geo_service_confirmation_authorizations",
      "purpose": "Store brand-material-public-use, sponsored-disclosure, no-AI-guarantee, external-action and service-terms acceptance records."
    },
    {
      "name": "geo_service_confirmation_ai_test_plan",
      "purpose": "Schedule and preserve Day1/Day3/Day7 platform-question verification rows without claiming that planned rows are evidence."
    },
    {
      "name": "geo_service_confirmation_acceptance",
      "purpose": "Record human acceptance of deliverables and evidence paths; not a payment or AI outcome proof."
    },
    {
      "name": "geo_service_confirmation_audit_logs",
      "purpose": "Append-only audit trail for staff actions, import/export and readiness changes."
    }
  ],
  "fieldMappingFrom25FieldSchema": {
    "service_confirmation_id": "geo_service_confirmations.service_confirmation_id",
    "service_mode": "geo_service_confirmations.service_mode",
    "service_provider_legal_entity": "geo_service_confirmations.service_provider_legal_entity",
    "customer_legal_entity": "geo_service_confirmations.customer_legal_entity",
    "customer_brand_name": "geo_service_confirmations.customer_brand_name",
    "customer_contact_person_redacted": "geo_service_confirmations.customer_contact_person_redacted",
    "brand_authorization_scope": "geo_service_confirmations.brand_authorization_scope",
    "public_material_scope": "geo_service_confirmations.public_material_scope_json",
    "sponsored_disclosure_accepted": "geo_service_confirmations.sponsored_disclosure_accepted",
    "no_ai_outcome_guarantee_accepted": "geo_service_confirmations.no_ai_outcome_guarantee_accepted",
    "external_action_authorization": "geo_service_confirmations.external_action_authorization_json",
    "selected_tier": "geo_service_confirmations.selected_tier",
    "quoted_amount_cny": "geo_service_confirmations.quoted_amount_cny",
    "payment_status": "geo_service_confirmations.payment_status",
    "invoice_status": "geo_service_confirmations.invoice_status",
    "service_start_date": "geo_service_confirmations.service_start_date",
    "service_end_date": "geo_service_confirmations.service_end_date",
    "target_question": "geo_service_confirmations.target_question",
    "target_platforms": "geo_service_confirmations.target_platforms_json",
    "deliverable_units": "geo_service_confirmations.deliverable_units_json",
    "acceptance_evidence_paths": "geo_service_confirmations.acceptance_evidence_paths_json",
    "blocked_claims": "geo_service_confirmations.blocked_claims",
    "p0_evidence_status": "geo_service_confirmations.p0_evidence_status",
    "client_written_confirmation": "geo_service_confirmations.client_written_confirmation",
    "legal_finance_review_status": "geo_service_confirmations.legal_finance_review_status"
  },
  "apiContractDraft": [
    {
      "method": "POST",
      "path": "/api/internal/service-confirmations",
      "purpose": "Create a draft service confirmation from form JSON or imported ledger JSON.",
      "auth": "staff-only",
      "writes": [
        "geo_service_confirmations",
        "geo_service_confirmation_audit_logs"
      ]
    },
    {
      "method": "GET",
      "path": "/api/internal/service-confirmations",
      "purpose": "List internal service confirmations with readiness/payment/legal filters.",
      "auth": "staff-only"
    },
    {
      "method": "GET",
      "path": "/api/internal/service-confirmations/:id",
      "purpose": "Read one service confirmation, its units, authorizations, AI test plan, acceptance rows and audit trail.",
      "auth": "staff-only"
    },
    {
      "method": "POST",
      "path": "/api/internal/service-confirmations/:id/recompute-readiness",
      "purpose": "Recompute readiness_status, readiness_blockers_json and readiness_warnings_json from hard gates.",
      "auth": "staff-only",
      "writes": [
        "geo_service_confirmations",
        "geo_service_confirmation_audit_logs"
      ]
    },
    {
      "method": "POST",
      "path": "/api/internal/service-confirmations/:id/export",
      "purpose": "Export a signed-off JSON snapshot for manual archive; export is not contract, payment or AI proof.",
      "auth": "staff-only"
    }
  ],
  "readinessGates": [
    {
      "gate": "sponsoredDisclosure",
      "rule": "sponsored_disclosure_accepted must be 1 before any paid customer content can be published."
    },
    {
      "gate": "noAiOutcomeGuarantee",
      "rule": "no_ai_outcome_guarantee_accepted must be 1 before quote, payment, service start or report delivery."
    },
    {
      "gate": "clientWrittenConfirmation",
      "rule": "client_written_confirmation must be 1 before real paid service starts."
    },
    {
      "gate": "legalFinanceReview",
      "rule": "legal_finance_review_status must be approved before real payment or invoicing starts."
    },
    {
      "gate": "p0Evidence",
      "rule": "p0_evidence_status not accepted blocks strong promotional claims and natural recommendation success claims."
    },
    {
      "gate": "externalAction",
      "rule": "external_action_authorization_json must explicitly list each allowed external action before search submission, official-site publication, external media submission, payment or DNS work."
    }
  ],
  "closedGates": [
    "Self-service recharge publishing remains closed.",
    "Automatic article publishing remains closed.",
    "AI indexing, ranking, natural recommendation and model cognition guarantees remain closed.",
    "D1 creation, migration execution, Worker/Pages Function binding and auth setup are not executed by this package.",
    "Payment, invoice, contract signing, official-site publication, search-console submission, external media submission and DNS/ICP actions are not authorized by this package."
  ],
  "deploymentRunbook": [
    "Ask the user for explicit authorization to create a Cloudflare D1 database and apply this migration.",
    "Run wrangler d1 create lucheng_geo_pilot and record the returned database_id.",
    "Bind the database as LUCHENG_GEO_DB in the Cloudflare Pages or Worker environment.",
    "Apply migrations locally first with wrangler d1 migrations apply lucheng_geo_pilot --local.",
    "Only after local API tests pass, request separate approval to apply the production migration.",
    "Implement staff-only auth before exposing any write endpoint.",
    "Import localStorage ledger exports only as draft rows and preserve the raw source_payload_json.",
    "Keep public pages static and crawlable; keep service confirmations and customer data private."
  ],
  "currentExecutionState": {
    "databaseCreated": false,
    "migrationAppliedLocal": false,
    "migrationAppliedProduction": false,
    "workerOrPagesFunctionBound": false,
    "authConfigured": false,
    "customerDataStoredServerSide": false,
    "paymentCollectionEnabled": false,
    "publicCustomerPortalEnabled": false
  },
  "commercialBoundary": "This pack converts the localStorage prototype into a D1-ready backend design and migration. It does not create backend infrastructure, store customer data, collect money, publish articles, submit search tools, prove AI indexing/recommendation or authorize any external platform action."
}
