Delete All Existing Code and DB Tables (Boilerplate Cleanup)
Inventory of S-AI-CHAT code and Prisma models to remove or replace when using this repo as a boilerplate for the Video Testimonial Collector app.
Delete All Existing Code and DB Tables
Section titled “Delete All Existing Code and DB Tables”This plan assumes you are forking or cloning the current S-AI-CHAT repository and want a slim Shopify app boilerplate aligned with:
01-Post-Purchase-Video-Testimonial-Collector-Plan.md02-Implementation-Blueprint.md
Goal: delete AI chat, RAG / knowledge, and chat widget storefront code/tables that the testimonial product does not need. Keep Shopify session/auth patterns, core Shop tenancy (trimmed for chat-only fields), admin Settings, Promo module, and Support module (feature requests, tickets, roadmap — adapt copy and any chat-specific metrics later). Keep billing primitives you can repurpose, product mirror (optional but recommended for PDP/home widgets and admin pickers), and mandatory compliance webhooks (update their handlers after schema changes).
This document is a checklist, not an executed migration. Perform deletions in a dedicated git branch; generate new Prisma migrations after editing schema.prisma (do not hand-edit production DB without a migration).
1) What the testimonial app still needs (keep conceptually)
Section titled “1) What the testimonial app still needs (keep conceptually)”| Area | Why keep |
|---|---|
Session model | Shopify OAuth session storage (template standard). |
Shop model (slimmed) | Multi-tenant root; testimonial campaigns, submissions, media, billing. |
Product / ProductVariant (optional) | Local catalog mirror helps admin UI, campaign product pickers, and validating shopifyProductId for PDP/home APIs. If you drop these, you must load product titles via Admin API only. |
ShopSubscription / ShopOneTimeCharge | Subscription and one-time purchase patterns from Phase 5; remap limits to testimonial metrics (storage, requests, published clips). |
Product webhooks (products/create, update, delete) | Keeps product mirror in sync if you keep Product tables. |
app/uninstalled, app/scopes_update, app_subscriptions/update | Standard app lifecycle / billing. |
webhooks/compliance | Required for GDPR topics; must be updated after removing tables so redact jobs do not reference missing models. |
Email utility (app/lib/email.server.js pattern) | Request/reminder emails for testimonial collection. |
Admin shell (app/routes/app.jsx, auth routes) | Embedded app framing; replace nav items. |
Settings (app.settings.jsx + Shop fields you add for testimonial) | Merchant config: contacts, branding, integrations, testimonial toggles (extend per 02-Implementation-Blueprint.md). |
| Promo models + admin/send/redeem routes | Incentives (e.g. discount codes for submitting a testimonial per blueprint); repurpose fields if today they are chat-reply-specific (see §2.1). |
Support models + app.support.jsx | In-app support desk, feature voting, roadmap — keep; remove only UI copy/logic that assumes “AI Chat” product. |
2) Prisma models to remove entirely
Section titled “2) Prisma models to remove entirely”These tables exist only for AI chat, RAG, or chat analytics. For a testimonial-focused boilerplate, drop the models and delete all code that imports them.
Do not remove promo or support tables if you are keeping those modules (see §2.1).
RAG / embeddings / ingestion
KnowledgeSourceKnowledgeDocumentKnowledgeChunkEmbedding(pgvector column — after removal you may switch Postgres provider withoutvectorextension)IngestionJobRetrievedChunk
Chat
ChatThreadChatSessionChatMessage
LLM usage logging (chat + embeddings)
OpenRouterCall
RAG “data sync” mirror (not required for testimonial MVP unless you repurpose)
ShopSyncStateCollectionBlogArticleInventoryLevel
2.1) Keep: Promo and Support (repurpose, do not drop)
Section titled “2.1) Keep: Promo and Support (repurpose, do not drop)”These are retained for the Video Testimonial Collector app.
Promo
PromoCode,PromoRedemption,PromoCodeSendLog- Note: Current
PromoCode.freeRepliesand related naming target chat reply credits. Plan a small migration + UI rename when you map promos to testimonial incentives (e.g. “bonus video requests”, “extra published slots”, or generic “credit units”). Until then, keep the tables and routes; only remove references to deleted chat billing (limits.server.js,freeCreditsUsed, etc.) when wiring redemptions.
Support
SupportFeatureRequest,SupportFeatureVote,SupportRoadmapItem,SupportTicket,SupportTicketMessage- Note: Compliance redact flows must continue to respect customer data in tickets when you extend GDPR handling for testimonial submissions.
Chat-centric install / churn analytics snapshots
ShopsInstalledStats(or replace later with testimonial-specific stats)ShopsUninstalled(or replace with a slimmer uninstall archive that does not reference chat counts)
Migration note: remove relations from Shop pointing at the above models before dropping Shop fields that only served chat (see section 3). Use onDelete: Cascade awareness: drop child tables first in SQL if you bypass Prisma migrate.
3) Shop model: fields to remove (chat / RAG / widget / AI credits)
Section titled “3) Shop model: fields to remove (chat / RAG / widget / AI credits)”After removing relations, delete columns that are only for the AI chat widget and RAG pipeline. Grouped for clarity.
Chat widget & appearance
widgetTitle,welcomeMessage,brandColor,bubblePosition,chatbotAvatarPreset,widgetBubbleAnimation,widgetIconInsetPx,widgetEnabled,widgetShowOnAllPagespreChatFormEnabled,guestChatAllowed
AI model / knowledge
aiModelknowledgeDomainUrl,websiteKnowledge
OpenRouter / reply limits / low-balance alerts tied to chat
dailySpendLimitCents,emailAlertOnMinBalance,minBalanceForAlertReplies,minBalanceForAlertCents,lastLowBalanceAlertAtcreditBalance,lastPaidIncludedCreditsPeriodEnd,suppressIncludedCreditsAfterSubscriptionLapsefreeCreditLimit,freeCreditsUsed
Retain (likely still useful for testimonial app)
- Identity:
shopifyShopId,shopDomain,accessToken,shopName,shopEmail,shopPhone - Optional contacts:
supportWhatsappNumber,supportEmail(if you still want merchant-configured support — otherwise drop) plan,status, timestamps- Billing linkage:
subscriptionId,subscriptionLineItemId - Email flags:
welcomeEmailSent,uninstallEmailSent,welcomeEmailSentAt,uninstallEmailSentAt,welcomeEmailError,uninstallEmailError(repurpose copy from “AI Chat” to testimonial branding)
Replace later with testimonial config (per blueprint; add in a future migration, not in this deletion doc):
- Widget layout/colors for video testimonial storefront blocks
testimonialEnabled, moderation flags, consent version, etc.
4) Routes (app/routes/) — remove or replace
Section titled “4) Routes (app/routes/) — remove or replace”4.1 Delete (chat / RAG / chat widget / chat-only billing helpers)
Section titled “4.1 Delete (chat / RAG / chat widget / chat-only billing helpers)”| File | Reason |
|---|---|
api.chat.jsx | Chat API entry. |
api.chat.history.jsx | Chat history for widget. |
api.widget-settings.jsx | Public chat widget settings (appearance). |
api.widget-settings-sync.jsx | Chat widget sync helper. |
api.cron.reset-free-plan-replies.jsx | Free-plan reply counter reset; testimonial app needs different cron jobs (e.g. send scheduled requests). |
app.chat-logs.jsx | Admin chat logs. |
app.knowledge.jsx | Knowledge Hub UI. |
app.data-sync.jsx | RAG data sync UI. |
app.appearance.jsx | Chat widget appearance admin. |
4.1b Keep (adapt for testimonial product)
Section titled “4.1b Keep (adapt for testimonial product)”| File | Action |
|---|---|
app.settings.jsx | Keep. Remove or relocate chat-only Shop fields from the form; add testimonial settings per 02-Implementation-Blueprint.md (widget, moderation, campaigns, etc.). Same route and shell. |
app.support.jsx | Keep. Update strings and any dashboard links that reference “AI Chat”; ensure loaders/actions do not depend on removed chat models. |
app.promo-codes.jsx, app.promo-send.jsx, app.promo-redeem.jsx | Keep. Repurpose labels and redemption wiring from “free chat replies” to testimonial incentive semantics when you change PromoCode meaning. |
4.2 Replace later (keep file name only if you want continuity)
Section titled “4.2 Replace later (keep file name only if you want continuity)”| File | Action |
|---|---|
app._index.jsx | Rewrite dashboard for testimonial KPIs (requests, submissions, moderation queue). Current file queries chatSession, chatMessage, openRouterCall, chunk counts. |
app.billing.jsx, app.billing.confirm.jsx, app.billing.buy-credits.jsx, app.billing.buy-credits.confirm.jsx | Repurpose for testimonial plans/usage; remove imports of chat credit / free-reply logic (limits.server.js, openRouterCall, etc.). |
4.3 Public marketing site
Section titled “4.3 Public marketing site”| File | Action |
|---|---|
_index/route.jsx, _index/styles.module.css | Rebrand copy and links; remove AI chat positioning. |
4.4 Webhooks — delete handlers only if topics removed from shopify.app.toml
Section titled “4.4 Webhooks — delete handlers only if topics removed from shopify.app.toml”Current product webhooks feed product mirror used by RAG. For testimonial:
- Keep
webhooks.products.create.jsx,webhooks.products.update.jsx,webhooks.products.delete.jsxif you keepProduct/ProductVariant. - Keep
webhooks.compliance.jsx,webhooks.app.uninstalled.jsx,webhooks.app.scopes_update.jsx,webhooks.app_subscriptions.update.jsx— but edit compliance + uninstall code paths that aggregate chat/RAG metrics or delete child rows that no longer exist.
Add later (testimonial blueprint):
webhooks.orders.paid.jsxand/orwebhooks.orders.fulfilled.jsx(campaign triggers)
5) Library code (app/lib/) — delete list
Section titled “5) Library code (app/lib/) — delete list”Remove modules that only serve chat/RAG/widget/AI billing. After deletion, run rg (ripgrep) for each basename to fix broken imports.
| File | Role |
|---|---|
rag.server.js | RAG orchestration. |
prompt-builder.server.js | Chat system prompt. |
chat.server.js | OpenRouter chat. |
embeddings.server.js | Embeddings. |
vector-search.server.js | pgvector search. |
chunker.server.js | Chunking for RAG. |
ingestion.server.js | Knowledge ingestion. |
website-knowledge.server.js | Website knowledge fetch. |
order-lookup.server.js | Shopify order lookup for chat. |
limits.server.js | Free reply cap + credit wallet for chat. |
paid-plan-included-credits.server.js | Included USD credits for chat. |
low-balance.server.js, low-balance.js | Chat balance alerts. |
widget-appearance.server.js, widget-appearance.js | Chat widget appearance normalization. |
theme-widget.server.js | Chat theme asset helpers. |
shop-analytics-snapshot.server.js | Likely chat/RAG heavy — review; remove or replace with testimonial snapshot. |
shops-installed-stats.server.js | Chat-centric install stats — remove or rewrite. |
shops-uninstalled-archive.server.js | Uninstall archive — rewrite to stop querying dropped models. |
product-sync.server.js | Only if you remove product mirror; keep if you still sync products for testimonial admin. |
collection-sync.server.js, blog-sync.server.js, inventory-sync.server.js, sync-state.server.js | RAG sync — remove if you drop those tables. |
plans.server.js | Repurpose for testimonial pricing; remove chat reply constants. |
Keep (promo + support)
promo.server.js,promo.shared.js— promo access rules and shared helpers; update naming/semantics when promos mean testimonial incentives, not chat replies.- Support logic lives mainly in
app.support.jsxand Prisma models; no dedicatedsupport.server.jsin current tree — keep those routes when trimming imports.
Keep (generic)
cors.server.js— still useful for public storefront APIs (testimonial widget read, upload URLs).email.server.js— reuse for testimonial request emails.date-format.server.js— generic.
6) Theme extension — remove chat widget
Section titled “6) Theme extension — remove chat widget”Delete the entire workspace:
extensions/appifire-chat/(blocks,chat-widget.js,shopify.extension.toml, locales)
Replace with a new extension per 02-Implementation-Blueprint.md (testimonial-widget-home.liquid, testimonial-widget-pdp.liquid, shared JS).
Update root shopify.app.toml (or multi-env TOMLs) so [extensions] / Shopify CLI discovers the new extension name.
7) Configuration and environment
Section titled “7) Configuration and environment”7.1 shopify.app.toml
Section titled “7.1 shopify.app.toml”- Rename app
name,application_url,redirect_urls, andclient_idto the new Partner app when you create it. - Scopes: testimonial MVP needs at least orders (read or appropriate access for post-purchase triggers), products (read; write only if you still use template metafields), themes (if publishing app blocks), and compliance. Remove scopes that existed only for metaobject demos if unused.
- Remove
[product.metafields.app.demo_info]and[metaobjects.app.example]if they are template noise.
7.2 .env.sample — remove chat/RAG variables
Section titled “7.2 .env.sample — remove chat/RAG variables”Remove or strike through:
OPENROUTER_API_KEY,WEBSITE_KNOWLEDGE_MODELEMBEDDING_MARKUP_FACTOR,CHAT_MARKUP_FACTORORDER_LOOKUP_DEBUG,CHAT_HISTORY_MESSAGESLLM_MODEL_FREE,LLM_MODEL_PAID- Free-reply / chat credit vars tied to
limits.server.js(FREE_PLAN_REPLIES_CAP, paid included credits, low balance USD thresholds) — replace with testimonial-specific limits when you define billing.
Keep:
SHOPIFY_*,DATABASE_URL,DIRECT_URL,SCOPES- Brevo (or your mail provider) keys — update product name in from/reply-to copy
- Optional
VITE_GA_MEASUREMENT_ID
7.3 package.json
Section titled “7.3 package.json”- Rename
namefromappifire-ai-chatto your new package slug. - Dependencies: no OpenRouter SDK in package.json currently; after code removal, if nothing uses
marked/@toast-ui/editor/recharts, consider removing them only after grep confirms zero imports.
8) Database / Postgres
Section titled “8) Database / Postgres”- If you remove
Embeddingand no other extension usesvector, you may drop the pgvector extension in a migration to simplify hosting (optional). - Regenerate Prisma client:
npx prisma generate. - Apply a single coherent migration that:
- Drops foreign keys / tables for removed models.
- Alters
shopsto drop chat columns. - Updates any views or indexes you maintain manually (if applicable).
9) Compliance and uninstall — mandatory follow-ups
Section titled “9) Compliance and uninstall — mandatory follow-ups”webhooks/compliance.jsx and webhooks/app/uninstalled.jsx (and any helper they call) likely:
- Copy metrics into
ShopsUninstalled/ stats tables - Delete tenant rows
After schema deletion, update these routes so they:
- Do not reference
ChatMessage,KnowledgeChunk, etc. - Still satisfy Shopify’s redact expectations for new testimonial tables (e.g. delete
TestimonialSubmissionby customer email when you build that schema)
Until handlers are updated, deploying a half-migrated schema can cause runtime errors on compliance webhooks.
10) Suggested execution order (safe refactor sequence)
Section titled “10) Suggested execution order (safe refactor sequence)”- Create branch
chore/testimonial-boilerplate-cleanup. - Remove theme extension
appifire-chatand all storefront references. - Delete route files listed in §4.1 only; keep §4.1b (settings, support, promos); fix router/build errors.
- Delete
app/libmodules listed in §5 (not promo); fix imports. - Edit
prisma/schema.prisma: remove chat/RAG models + trimShop; retain promo/support tables; runprisma migrate devlocally. - Rewrite compliance + uninstall handlers.
- Update
app.jsxnav (add testimonial entries later); keep Settings, Support, Promo links; adapt dashboard — do not remove the settings route. - Update
shopify.app.toml,.env.sample, and marketing_index. - Full-text search:
rg "chatMessage|KnowledgeChunk|OpenRouter|rag\.server|api/chat"until clean.
11) Explicit non-goals (for this cleanup pass)
Section titled “11) Explicit non-goals (for this cleanup pass)”- Implementing testimonial tables (
TestimonialCampaign,TestimonialSubmission, …) — that belongs in implementation migrations per02-Implementation-Blueprint.md. - Choosing final billing meter (storage minutes vs request count) — only remove chat-specific credit fields now; add testimonial fields when product pricing is fixed.
12) Traceability to future sub-plans
Section titled “12) Traceability to future sub-plans”When you split work into per-topic markdown plans, map cleanup to:
| Sub-plan | Contents |
|---|---|
SP-CLEAN-01 | Prisma: drop chat/RAG models only; trim Shop chat fields; keep promo + support models (optional migration to rename promo fields). |
SP-CLEAN-02 | Remove chat/RAG routes + app/lib modules; keep settings, support, promo routes; fix build. |
SP-CLEAN-03 | Remove extensions/appifire-chat; update shopify.app.toml. |
SP-CLEAN-04 | Rewrite GDPR uninstall + compliance handlers for new schema. |
SP-CLEAN-05 | Rebrand env sample, package name, public index, admin nav shell. |
This file is 04-Delete All Existing Code and DB Tables.md in the Video Testimonial Collector doc set.