@sonicjs-cms/core 2.3.12 → 2.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/{chunk-EIE35JCC.js → chunk-2NTBZ2Y7.js} +3 -3
  2. package/dist/{chunk-EIE35JCC.js.map → chunk-2NTBZ2Y7.js.map} +1 -1
  3. package/dist/{chunk-OJ5WUCSH.cjs → chunk-5NCBFP37.cjs} +4 -4
  4. package/dist/{chunk-OJ5WUCSH.cjs.map → chunk-5NCBFP37.cjs.map} +1 -1
  5. package/dist/{chunk-HTJLBF6F.cjs → chunk-ARLXQU2S.cjs} +247 -165
  6. package/dist/chunk-ARLXQU2S.cjs.map +1 -0
  7. package/dist/{chunk-KQCYQKSV.js → chunk-DN45O5XV.js} +2 -2
  8. package/dist/chunk-DN45O5XV.js.map +1 -0
  9. package/dist/{chunk-REY542YK.js → chunk-F56JKQTA.js} +3 -3
  10. package/dist/{chunk-REY542YK.js.map → chunk-F56JKQTA.js.map} +1 -1
  11. package/dist/{chunk-74RYBO6J.js → chunk-FHCN7KR2.js} +10 -5
  12. package/dist/chunk-FHCN7KR2.js.map +1 -0
  13. package/dist/{chunk-RIOIKM3Y.cjs → chunk-MF7DWI5P.cjs} +2 -2
  14. package/dist/chunk-MF7DWI5P.cjs.map +1 -0
  15. package/dist/{chunk-HDSRB23N.js → chunk-RP66TPEJ.js} +101 -19
  16. package/dist/chunk-RP66TPEJ.js.map +1 -0
  17. package/dist/{chunk-NTXPL746.js → chunk-VMEBHBYY.js} +34 -2
  18. package/dist/chunk-VMEBHBYY.js.map +1 -0
  19. package/dist/{chunk-IB6UBZVD.cjs → chunk-W2IAEG4W.cjs} +10 -5
  20. package/dist/chunk-W2IAEG4W.cjs.map +1 -0
  21. package/dist/{chunk-P6NMVNJJ.cjs → chunk-W4CE7XME.cjs} +34 -2
  22. package/dist/chunk-W4CE7XME.cjs.map +1 -0
  23. package/dist/{chunk-K6BFUYJH.cjs → chunk-XR6XACXJ.cjs} +5 -5
  24. package/dist/{chunk-K6BFUYJH.cjs.map → chunk-XR6XACXJ.cjs.map} +1 -1
  25. package/dist/index.cjs +87 -87
  26. package/dist/index.js +10 -10
  27. package/dist/middleware.cjs +23 -23
  28. package/dist/middleware.js +2 -2
  29. package/dist/migrations-43GTELB5.js +4 -0
  30. package/dist/{migrations-YAFC5JVO.js.map → migrations-43GTELB5.js.map} +1 -1
  31. package/dist/migrations-ZAYXZXON.cjs +13 -0
  32. package/dist/{migrations-DQ74P6V4.cjs.map → migrations-ZAYXZXON.cjs.map} +1 -1
  33. package/dist/routes.cjs +25 -25
  34. package/dist/routes.js +5 -5
  35. package/dist/services.cjs +2 -2
  36. package/dist/services.js +1 -1
  37. package/dist/templates.cjs +17 -17
  38. package/dist/templates.js +2 -2
  39. package/dist/utils.cjs +11 -11
  40. package/dist/utils.js +1 -1
  41. package/migrations/025_add_easymde_plugin.sql +25 -0
  42. package/package.json +8 -3
  43. package/dist/chunk-74RYBO6J.js.map +0 -1
  44. package/dist/chunk-HDSRB23N.js.map +0 -1
  45. package/dist/chunk-HTJLBF6F.cjs.map +0 -1
  46. package/dist/chunk-IB6UBZVD.cjs.map +0 -1
  47. package/dist/chunk-KQCYQKSV.js.map +0 -1
  48. package/dist/chunk-NTXPL746.js.map +0 -1
  49. package/dist/chunk-P6NMVNJJ.cjs.map +0 -1
  50. package/dist/chunk-RIOIKM3Y.cjs.map +0 -1
  51. package/dist/migrations-DQ74P6V4.cjs +0 -13
  52. package/dist/migrations-YAFC5JVO.js +0 -4
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/db/migrations-bundle.ts","../src/services/migrations.ts"],"names":[],"mappings":";AAiBO,IAAM,iBAAA,GAAwC;AAAA,EACnD;AAAA,IACE,EAAA,EAAI,KAAA;AAAA,IACJ,IAAA,EAAM,gBAAA;AAAA,IACN,QAAA,EAAU,wBAAA;AAAA,IACV,WAAA,EAAa,+BAAA;AAAA,IACb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,MACzB;AAAA,KACF;AAAA,EACF;AACF","file":"chunk-NTXPL746.js","sourcesContent":["/**\n * AUTO-GENERATED FILE - DO NOT EDIT\n * Generated by: scripts/generate-migrations.ts\n * Generated at: 2025-12-10T20:44:19.716Z\n *\n * This file contains all migration SQL bundled for use in Cloudflare Workers\n * where filesystem access is not available at runtime.\n */\n\nexport interface BundledMigration {\n id: string\n name: string\n filename: string\n description: string\n sql: string\n}\n\nexport const bundledMigrations: BundledMigration[] = [\n {\n id: '001',\n name: 'Initial Schema',\n filename: '001_initial_schema.sql',\n description: 'Migration 001: Initial Schema',\n sql: \"-- Initial schema for SonicJS AI\\n-- Create users table for authentication\\nCREATE TABLE IF NOT EXISTS users (\\n id TEXT PRIMARY KEY,\\n email TEXT NOT NULL UNIQUE,\\n username TEXT NOT NULL UNIQUE,\\n first_name TEXT NOT NULL,\\n last_name TEXT NOT NULL,\\n password_hash TEXT,\\n role TEXT NOT NULL DEFAULT 'viewer',\\n avatar TEXT,\\n is_active INTEGER NOT NULL DEFAULT 1,\\n last_login_at INTEGER,\\n created_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL\\n);\\n\\n-- Create collections table for content schema definitions\\nCREATE TABLE IF NOT EXISTS collections (\\n id TEXT PRIMARY KEY,\\n name TEXT NOT NULL UNIQUE,\\n display_name TEXT NOT NULL,\\n description TEXT,\\n schema TEXT NOT NULL, -- JSON schema definition\\n is_active INTEGER NOT NULL DEFAULT 1,\\n created_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL\\n);\\n\\n-- Create content table for actual content data\\nCREATE TABLE IF NOT EXISTS content (\\n id TEXT PRIMARY KEY,\\n collection_id TEXT NOT NULL REFERENCES collections(id),\\n slug TEXT NOT NULL,\\n title TEXT NOT NULL,\\n data TEXT NOT NULL, -- JSON content data\\n status TEXT NOT NULL DEFAULT 'draft',\\n published_at INTEGER,\\n author_id TEXT NOT NULL REFERENCES users(id),\\n created_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL\\n);\\n\\n-- Create content_versions table for versioning\\nCREATE TABLE IF NOT EXISTS content_versions (\\n id TEXT PRIMARY KEY,\\n content_id TEXT NOT NULL REFERENCES content(id),\\n version INTEGER NOT NULL,\\n data TEXT NOT NULL, -- JSON data\\n author_id TEXT NOT NULL REFERENCES users(id),\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Create media/files table with comprehensive R2 integration\\nCREATE TABLE IF NOT EXISTS media (\\n id TEXT PRIMARY KEY,\\n filename TEXT NOT NULL,\\n original_name TEXT NOT NULL,\\n mime_type TEXT NOT NULL,\\n size INTEGER NOT NULL,\\n width INTEGER,\\n height INTEGER,\\n folder TEXT NOT NULL DEFAULT 'uploads',\\n r2_key TEXT NOT NULL, -- R2 storage key\\n public_url TEXT NOT NULL, -- CDN URL\\n thumbnail_url TEXT, -- Cloudflare Images URL\\n alt TEXT,\\n caption TEXT,\\n tags TEXT, -- JSON array of tags\\n uploaded_by TEXT NOT NULL REFERENCES users(id),\\n uploaded_at INTEGER NOT NULL,\\n updated_at INTEGER,\\n published_at INTEGER,\\n scheduled_at INTEGER,\\n archived_at INTEGER,\\n deleted_at INTEGER\\n);\\n\\n-- Create API tokens table for programmatic access\\nCREATE TABLE IF NOT EXISTS api_tokens (\\n id TEXT PRIMARY KEY,\\n name TEXT NOT NULL,\\n token TEXT NOT NULL UNIQUE,\\n user_id TEXT NOT NULL REFERENCES users(id),\\n permissions TEXT NOT NULL, -- JSON array of permissions\\n expires_at INTEGER,\\n last_used_at INTEGER,\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Create workflow history table for content workflow tracking\\nCREATE TABLE IF NOT EXISTS workflow_history (\\n id TEXT PRIMARY KEY,\\n content_id TEXT NOT NULL REFERENCES content(id),\\n action TEXT NOT NULL,\\n from_status TEXT NOT NULL,\\n to_status TEXT NOT NULL,\\n user_id TEXT NOT NULL REFERENCES users(id),\\n comment TEXT,\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Create indexes for better performance\\nCREATE INDEX IF NOT EXISTS idx_users_email ON users(email);\\nCREATE INDEX IF NOT EXISTS idx_users_username ON users(username);\\nCREATE INDEX IF NOT EXISTS idx_users_role ON users(role);\\n\\nCREATE INDEX IF NOT EXISTS idx_collections_name ON collections(name);\\nCREATE INDEX IF NOT EXISTS idx_collections_active ON collections(is_active);\\n\\nCREATE INDEX IF NOT EXISTS idx_content_collection ON content(collection_id);\\nCREATE INDEX IF NOT EXISTS idx_content_author ON content(author_id);\\nCREATE INDEX IF NOT EXISTS idx_content_status ON content(status);\\nCREATE INDEX IF NOT EXISTS idx_content_published ON content(published_at);\\nCREATE INDEX IF NOT EXISTS idx_content_slug ON content(slug);\\n\\nCREATE INDEX IF NOT EXISTS idx_content_versions_content ON content_versions(content_id);\\nCREATE INDEX IF NOT EXISTS idx_content_versions_version ON content_versions(version);\\n\\nCREATE INDEX IF NOT EXISTS idx_media_folder ON media(folder);\\nCREATE INDEX IF NOT EXISTS idx_media_type ON media(mime_type);\\nCREATE INDEX IF NOT EXISTS idx_media_uploaded_by ON media(uploaded_by);\\nCREATE INDEX IF NOT EXISTS idx_media_uploaded_at ON media(uploaded_at);\\nCREATE INDEX IF NOT EXISTS idx_media_deleted ON media(deleted_at);\\n\\nCREATE INDEX IF NOT EXISTS idx_api_tokens_user ON api_tokens(user_id);\\nCREATE INDEX IF NOT EXISTS idx_api_tokens_token ON api_tokens(token);\\n\\nCREATE INDEX IF NOT EXISTS idx_workflow_history_content ON workflow_history(content_id);\\nCREATE INDEX IF NOT EXISTS idx_workflow_history_user ON workflow_history(user_id);\\n\\n-- Note: Admin user is created via the seed script with user-provided credentials\\n-- Run 'npm run seed' after migrations to create the admin user\\n\\n-- Insert sample collections\\nINSERT OR IGNORE INTO collections (\\n id, name, display_name, description, schema, \\n is_active, created_at, updated_at\\n) VALUES (\\n 'blog-posts-collection',\\n 'blog_posts',\\n 'Blog Posts',\\n 'Blog post content collection',\\n '{\\\"type\\\":\\\"object\\\",\\\"properties\\\":{\\\"title\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Title\\\",\\\"required\\\":true},\\\"content\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Content\\\",\\\"format\\\":\\\"richtext\\\"},\\\"excerpt\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Excerpt\\\"},\\\"featured_image\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Featured Image\\\",\\\"format\\\":\\\"media\\\"},\\\"tags\\\":{\\\"type\\\":\\\"array\\\",\\\"title\\\":\\\"Tags\\\",\\\"items\\\":{\\\"type\\\":\\\"string\\\"}},\\\"status\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Status\\\",\\\"enum\\\":[\\\"draft\\\",\\\"published\\\",\\\"archived\\\"],\\\"default\\\":\\\"draft\\\"}},\\\"required\\\":[\\\"title\\\"]}',\\n 1,\\n strftime('%s', 'now') * 1000,\\n strftime('%s', 'now') * 1000\\n),\\n(\\n 'pages-collection',\\n 'pages',\\n 'Pages',\\n 'Static page content collection',\\n '{\\\"type\\\":\\\"object\\\",\\\"properties\\\":{\\\"title\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Title\\\",\\\"required\\\":true},\\\"content\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Content\\\",\\\"format\\\":\\\"richtext\\\"},\\\"slug\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Slug\\\"},\\\"meta_description\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Meta Description\\\"},\\\"featured_image\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Featured Image\\\",\\\"format\\\":\\\"media\\\"}},\\\"required\\\":[\\\"title\\\"]}',\\n 1,\\n strftime('%s', 'now') * 1000,\\n strftime('%s', 'now') * 1000\\n),\\n(\\n 'news-collection',\\n 'news',\\n 'News',\\n 'News article content collection',\\n '{\\\"type\\\":\\\"object\\\",\\\"properties\\\":{\\\"title\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Title\\\",\\\"required\\\":true},\\\"content\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Content\\\",\\\"format\\\":\\\"richtext\\\"},\\\"publish_date\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Publish Date\\\",\\\"format\\\":\\\"date\\\"},\\\"author\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Author\\\"},\\\"category\\\":{\\\"type\\\":\\\"string\\\",\\\"title\\\":\\\"Category\\\",\\\"enum\\\":[\\\"technology\\\",\\\"business\\\",\\\"general\\\"]}},\\\"required\\\":[\\\"title\\\"]}',\\n 1,\\n strftime('%s', 'now') * 1000,\\n strftime('%s', 'now') * 1000\\n);\\n\\n-- Note: Sample content can be created via the admin interface after the admin user is seeded\"\n },\n {\n id: '002',\n name: 'Faq Plugin',\n filename: '002_faq_plugin.sql',\n description: 'Migration 002: Faq Plugin',\n sql: \"-- FAQ Plugin Migration (DEPRECATED - Now managed by third-party plugin)\\n-- Creates FAQ table for the FAQ plugin\\n-- NOTE: This migration is kept for historical purposes. \\n-- The FAQ functionality is now provided by the faq-plugin third-party plugin.\\n\\nCREATE TABLE IF NOT EXISTS faqs (\\n id INTEGER PRIMARY KEY AUTOINCREMENT,\\n question TEXT NOT NULL,\\n answer TEXT NOT NULL,\\n category TEXT,\\n tags TEXT,\\n isPublished INTEGER NOT NULL DEFAULT 1,\\n sortOrder INTEGER NOT NULL DEFAULT 0,\\n created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),\\n updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))\\n);\\n\\n-- Create indexes for better performance\\nCREATE INDEX IF NOT EXISTS idx_faqs_category ON faqs(category);\\nCREATE INDEX IF NOT EXISTS idx_faqs_published ON faqs(isPublished);\\nCREATE INDEX IF NOT EXISTS idx_faqs_sort_order ON faqs(sortOrder);\\n\\n-- Create trigger to update updated_at timestamp\\nCREATE TRIGGER IF NOT EXISTS faqs_updated_at\\n AFTER UPDATE ON faqs\\nBEGIN\\n UPDATE faqs SET updated_at = strftime('%s', 'now') WHERE id = NEW.id;\\nEND;\\n\\n-- Insert sample FAQ data\\nINSERT OR IGNORE INTO faqs (question, answer, category, tags, isPublished, sortOrder) VALUES \\n('What is SonicJS AI?', \\n'SonicJS AI is a modern, TypeScript-first headless CMS built for Cloudflare''s edge platform. It provides a complete content management system with admin interface, API endpoints, and plugin architecture.',\\n'general',\\n'sonicjs, cms, cloudflare',\\n1,\\n1),\\n\\n('How do I get started with SonicJS AI?',\\n'To get started: 1) Clone the repository, 2) Install dependencies with npm install, 3) Set up your Cloudflare account and services, 4) Run the development server with npm run dev, 5) Access the admin interface at /admin.',\\n'general',\\n'getting-started, setup',\\n1,\\n2),\\n\\n('What technologies does SonicJS AI use?',\\n'SonicJS AI is built with: TypeScript for type safety, Hono.js as the web framework, Cloudflare D1 for the database, Cloudflare R2 for media storage, Cloudflare Workers for serverless execution, and Tailwind CSS for styling.',\\n'technical',\\n'technology-stack, typescript, cloudflare',\\n1,\\n3),\\n\\n('How do I create content in SonicJS AI?',\\n'Content creation is done through the admin interface. Navigate to /admin, log in with your credentials, go to Content section, select a collection, and click \\\"New Content\\\" to create articles, pages, or other content types.',\\n'general',\\n'content-creation, admin',\\n1,\\n4),\\n\\n('Is SonicJS AI free to use?',\\n'SonicJS AI is open source and free to use. You only pay for the Cloudflare services you consume (D1 database, R2 storage, Workers execution time). Cloudflare offers generous free tiers for development and small projects.',\\n'billing',\\n'pricing, open-source, cloudflare',\\n1,\\n5),\\n\\n('How do I add custom functionality?',\\n'SonicJS AI features a plugin system that allows you to extend functionality. You can create plugins using the PluginBuilder API, add custom routes, models, admin pages, and integrate with external services.',\\n'technical',\\n'plugins, customization, development',\\n1,\\n6),\\n\\n('Can I customize the admin interface?',\\n'Yes! The admin interface is built with TypeScript templates and can be customized. You can modify existing templates, create new components, add custom pages, and integrate your own styling while maintaining the dark theme.',\\n'technical',\\n'admin-interface, customization, templates',\\n1,\\n7),\\n\\n('How does authentication work?',\\n'SonicJS AI includes a built-in authentication system with JWT tokens, role-based access control (admin, editor, viewer), secure password hashing, and session management. Users can be managed through the admin interface.',\\n'technical',\\n'authentication, security, users',\\n1,\\n8);\"\n },\n {\n id: '003',\n name: 'Stage5 Enhancements',\n filename: '003_stage5_enhancements.sql',\n description: 'Migration 003: Stage5 Enhancements',\n sql: \"-- Stage 5: Advanced Content Management enhancements\\n-- Add scheduling and workflow features to content table\\n\\n-- Add content scheduling columns\\nALTER TABLE content ADD COLUMN scheduled_publish_at INTEGER;\\nALTER TABLE content ADD COLUMN scheduled_unpublish_at INTEGER;\\n\\n-- Add workflow and review columns\\nALTER TABLE content ADD COLUMN review_status TEXT DEFAULT 'none'; -- none, pending, approved, rejected\\nALTER TABLE content ADD COLUMN reviewer_id TEXT REFERENCES users(id);\\nALTER TABLE content ADD COLUMN reviewed_at INTEGER;\\nALTER TABLE content ADD COLUMN review_notes TEXT;\\n\\n-- Add content metadata\\nALTER TABLE content ADD COLUMN meta_title TEXT;\\nALTER TABLE content ADD COLUMN meta_description TEXT;\\nALTER TABLE content ADD COLUMN featured_image_id TEXT REFERENCES media(id);\\nALTER TABLE content ADD COLUMN content_type TEXT DEFAULT 'standard'; -- standard, template, component\\n\\n-- Create content_fields table for dynamic field definitions\\nCREATE TABLE IF NOT EXISTS content_fields (\\n id TEXT PRIMARY KEY,\\n collection_id TEXT NOT NULL REFERENCES collections(id),\\n field_name TEXT NOT NULL,\\n field_type TEXT NOT NULL, -- text, richtext, number, boolean, date, select, media, relationship\\n field_label TEXT NOT NULL,\\n field_options TEXT, -- JSON for select options, validation rules, etc.\\n field_order INTEGER NOT NULL DEFAULT 0,\\n is_required INTEGER NOT NULL DEFAULT 0,\\n is_searchable INTEGER NOT NULL DEFAULT 0,\\n created_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL,\\n UNIQUE(collection_id, field_name)\\n);\\n\\n-- Create content_relationships table for content relationships\\nCREATE TABLE IF NOT EXISTS content_relationships (\\n id TEXT PRIMARY KEY,\\n source_content_id TEXT NOT NULL REFERENCES content(id),\\n target_content_id TEXT NOT NULL REFERENCES content(id),\\n relationship_type TEXT NOT NULL, -- references, tags, categories\\n created_at INTEGER NOT NULL,\\n UNIQUE(source_content_id, target_content_id, relationship_type)\\n);\\n\\n-- Create workflow_templates table for reusable workflows\\nCREATE TABLE IF NOT EXISTS workflow_templates (\\n id TEXT PRIMARY KEY,\\n name TEXT NOT NULL,\\n description TEXT,\\n collection_id TEXT REFERENCES collections(id), -- null means applies to all collections\\n workflow_steps TEXT NOT NULL, -- JSON array of workflow steps\\n is_active INTEGER NOT NULL DEFAULT 1,\\n created_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL\\n);\\n\\n-- Add indexes for new columns\\nCREATE INDEX IF NOT EXISTS idx_content_scheduled_publish ON content(scheduled_publish_at);\\nCREATE INDEX IF NOT EXISTS idx_content_scheduled_unpublish ON content(scheduled_unpublish_at);\\nCREATE INDEX IF NOT EXISTS idx_content_review_status ON content(review_status);\\nCREATE INDEX IF NOT EXISTS idx_content_reviewer ON content(reviewer_id);\\nCREATE INDEX IF NOT EXISTS idx_content_content_type ON content(content_type);\\n\\nCREATE INDEX IF NOT EXISTS idx_content_fields_collection ON content_fields(collection_id);\\nCREATE INDEX IF NOT EXISTS idx_content_fields_name ON content_fields(field_name);\\nCREATE INDEX IF NOT EXISTS idx_content_fields_type ON content_fields(field_type);\\nCREATE INDEX IF NOT EXISTS idx_content_fields_order ON content_fields(field_order);\\n\\nCREATE INDEX IF NOT EXISTS idx_content_relationships_source ON content_relationships(source_content_id);\\nCREATE INDEX IF NOT EXISTS idx_content_relationships_target ON content_relationships(target_content_id);\\nCREATE INDEX IF NOT EXISTS idx_content_relationships_type ON content_relationships(relationship_type);\\n\\nCREATE INDEX IF NOT EXISTS idx_workflow_templates_collection ON workflow_templates(collection_id);\\nCREATE INDEX IF NOT EXISTS idx_workflow_templates_active ON workflow_templates(is_active);\\n\\n-- Insert default workflow template\\nINSERT OR IGNORE INTO workflow_templates (\\n id, name, description, workflow_steps, is_active, created_at, updated_at\\n) VALUES (\\n 'default-content-workflow',\\n 'Default Content Workflow',\\n 'Standard content workflow: Draft → Review → Published',\\n '[\\n {\\\"step\\\": \\\"draft\\\", \\\"name\\\": \\\"Draft\\\", \\\"description\\\": \\\"Content is being created\\\", \\\"permissions\\\": [\\\"author\\\", \\\"editor\\\", \\\"admin\\\"]},\\n {\\\"step\\\": \\\"review\\\", \\\"name\\\": \\\"Under Review\\\", \\\"description\\\": \\\"Content is pending review\\\", \\\"permissions\\\": [\\\"editor\\\", \\\"admin\\\"]},\\n {\\\"step\\\": \\\"published\\\", \\\"name\\\": \\\"Published\\\", \\\"description\\\": \\\"Content is live\\\", \\\"permissions\\\": [\\\"editor\\\", \\\"admin\\\"]},\\n {\\\"step\\\": \\\"archived\\\", \\\"name\\\": \\\"Archived\\\", \\\"description\\\": \\\"Content is archived\\\", \\\"permissions\\\": [\\\"admin\\\"]}\\n ]',\\n 1,\\n strftime('%s', 'now') * 1000,\\n strftime('%s', 'now') * 1000\\n);\\n\\n-- Insert enhanced field definitions for existing collections\\nINSERT OR IGNORE INTO content_fields (\\n id, collection_id, field_name, field_type, field_label, field_options, field_order, is_required, is_searchable, created_at, updated_at\\n) VALUES \\n-- Blog Posts fields\\n('blog-title-field', 'blog-posts-collection', 'title', 'text', 'Title', '{\\\"maxLength\\\": 200, \\\"placeholder\\\": \\\"Enter blog post title\\\"}', 1, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('blog-content-field', 'blog-posts-collection', 'content', 'richtext', 'Content', '{\\\"toolbar\\\": \\\"full\\\", \\\"height\\\": 400}', 2, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('blog-excerpt-field', 'blog-posts-collection', 'excerpt', 'text', 'Excerpt', '{\\\"maxLength\\\": 500, \\\"rows\\\": 3, \\\"placeholder\\\": \\\"Brief description of the post\\\"}', 3, 0, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('blog-tags-field', 'blog-posts-collection', 'tags', 'select', 'Tags', '{\\\"multiple\\\": true, \\\"options\\\": [\\\"technology\\\", \\\"business\\\", \\\"tutorial\\\", \\\"news\\\", \\\"update\\\"], \\\"allowCustom\\\": true}', 4, 0, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('blog-featured-image-field', 'blog-posts-collection', 'featured_image', 'media', 'Featured Image', '{\\\"accept\\\": \\\"image/*\\\", \\\"maxSize\\\": \\\"5MB\\\"}', 5, 0, 0, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('blog-publish-date-field', 'blog-posts-collection', 'publish_date', 'date', 'Publish Date', '{\\\"format\\\": \\\"YYYY-MM-DD\\\", \\\"defaultToday\\\": true}', 6, 0, 0, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('blog-featured-field', 'blog-posts-collection', 'is_featured', 'boolean', 'Featured Post', '{\\\"default\\\": false}', 7, 0, 0, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n\\n-- Pages fields\\n('pages-title-field', 'pages-collection', 'title', 'text', 'Title', '{\\\"maxLength\\\": 200, \\\"placeholder\\\": \\\"Enter page title\\\"}', 1, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('pages-content-field', 'pages-collection', 'content', 'richtext', 'Content', '{\\\"toolbar\\\": \\\"full\\\", \\\"height\\\": 500}', 2, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('pages-slug-field', 'pages-collection', 'slug', 'text', 'URL Slug', '{\\\"pattern\\\": \\\"^[a-z0-9-]+$\\\", \\\"placeholder\\\": \\\"url-friendly-slug\\\"}', 3, 1, 0, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('pages-meta-desc-field', 'pages-collection', 'meta_description', 'text', 'Meta Description', '{\\\"maxLength\\\": 160, \\\"rows\\\": 2, \\\"placeholder\\\": \\\"SEO description for search engines\\\"}', 4, 0, 0, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('pages-template-field', 'pages-collection', 'template', 'select', 'Page Template', '{\\\"options\\\": [\\\"default\\\", \\\"landing\\\", \\\"contact\\\", \\\"about\\\"], \\\"default\\\": \\\"default\\\"}', 5, 0, 0, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n\\n-- News fields\\n('news-title-field', 'news-collection', 'title', 'text', 'Title', '{\\\"maxLength\\\": 200, \\\"placeholder\\\": \\\"Enter news title\\\"}', 1, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('news-content-field', 'news-collection', 'content', 'richtext', 'Content', '{\\\"toolbar\\\": \\\"news\\\", \\\"height\\\": 400}', 2, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('news-category-field', 'news-collection', 'category', 'select', 'Category', '{\\\"options\\\": [\\\"technology\\\", \\\"business\\\", \\\"politics\\\", \\\"sports\\\", \\\"entertainment\\\", \\\"health\\\"], \\\"required\\\": true}', 3, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('news-author-field', 'news-collection', 'author', 'text', 'Author', '{\\\"placeholder\\\": \\\"Author name\\\"}', 4, 1, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('news-source-field', 'news-collection', 'source', 'text', 'Source', '{\\\"placeholder\\\": \\\"News source\\\"}', 5, 0, 1, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000),\\n('news-priority-field', 'news-collection', 'priority', 'select', 'Priority', '{\\\"options\\\": [\\\"low\\\", \\\"normal\\\", \\\"high\\\", \\\"breaking\\\"], \\\"default\\\": \\\"normal\\\"}', 6, 0, 0, strftime('%s', 'now') * 1000, strftime('%s', 'now') * 1000);\"\n },\n {\n id: '004',\n name: 'Stage6 User Management',\n filename: '004_stage6_user_management.sql',\n description: 'Migration 004: Stage6 User Management',\n sql: \"-- Stage 6: User Management & Permissions enhancements\\n-- Enhanced user system with profiles, teams, permissions, and activity logging\\n\\n-- Add user profile and preferences columns\\nALTER TABLE users ADD COLUMN phone TEXT;\\nALTER TABLE users ADD COLUMN bio TEXT;\\nALTER TABLE users ADD COLUMN avatar_url TEXT;\\nALTER TABLE users ADD COLUMN timezone TEXT DEFAULT 'UTC';\\nALTER TABLE users ADD COLUMN language TEXT DEFAULT 'en';\\nALTER TABLE users ADD COLUMN email_notifications INTEGER DEFAULT 1;\\nALTER TABLE users ADD COLUMN theme TEXT DEFAULT 'dark';\\nALTER TABLE users ADD COLUMN two_factor_enabled INTEGER DEFAULT 0;\\nALTER TABLE users ADD COLUMN two_factor_secret TEXT;\\nALTER TABLE users ADD COLUMN password_reset_token TEXT;\\nALTER TABLE users ADD COLUMN password_reset_expires INTEGER;\\nALTER TABLE users ADD COLUMN email_verified INTEGER DEFAULT 0;\\nALTER TABLE users ADD COLUMN email_verification_token TEXT;\\nALTER TABLE users ADD COLUMN invitation_token TEXT;\\nALTER TABLE users ADD COLUMN invited_by TEXT REFERENCES users(id);\\nALTER TABLE users ADD COLUMN invited_at INTEGER;\\nALTER TABLE users ADD COLUMN accepted_invitation_at INTEGER;\\n\\n-- Create teams table for team-based collaboration\\nCREATE TABLE IF NOT EXISTS teams (\\n id TEXT PRIMARY KEY,\\n name TEXT NOT NULL,\\n description TEXT,\\n slug TEXT NOT NULL UNIQUE,\\n owner_id TEXT NOT NULL REFERENCES users(id),\\n settings TEXT, -- JSON for team settings\\n is_active INTEGER NOT NULL DEFAULT 1,\\n created_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL\\n);\\n\\n-- Create team memberships table\\nCREATE TABLE IF NOT EXISTS team_memberships (\\n id TEXT PRIMARY KEY,\\n team_id TEXT NOT NULL REFERENCES teams(id) ON DELETE CASCADE,\\n user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,\\n role TEXT NOT NULL DEFAULT 'member', -- owner, admin, editor, member, viewer\\n permissions TEXT, -- JSON for specific permissions\\n joined_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL,\\n UNIQUE(team_id, user_id)\\n);\\n\\n-- Create permissions table for granular access control\\nCREATE TABLE IF NOT EXISTS permissions (\\n id TEXT PRIMARY KEY,\\n name TEXT NOT NULL UNIQUE,\\n description TEXT,\\n category TEXT NOT NULL, -- content, users, collections, media, settings\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Create role permissions mapping\\nCREATE TABLE IF NOT EXISTS role_permissions (\\n id TEXT PRIMARY KEY,\\n role TEXT NOT NULL,\\n permission_id TEXT NOT NULL REFERENCES permissions(id),\\n created_at INTEGER NOT NULL,\\n UNIQUE(role, permission_id)\\n);\\n\\n-- Create user sessions table for better session management\\nCREATE TABLE IF NOT EXISTS user_sessions (\\n id TEXT PRIMARY KEY,\\n user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,\\n token_hash TEXT NOT NULL,\\n ip_address TEXT,\\n user_agent TEXT,\\n is_active INTEGER NOT NULL DEFAULT 1,\\n expires_at INTEGER NOT NULL,\\n created_at INTEGER NOT NULL,\\n last_used_at INTEGER\\n);\\n\\n-- Create activity log table for audit trails\\nCREATE TABLE IF NOT EXISTS activity_logs (\\n id TEXT PRIMARY KEY,\\n user_id TEXT REFERENCES users(id),\\n action TEXT NOT NULL,\\n resource_type TEXT, -- users, content, collections, media, etc.\\n resource_id TEXT,\\n details TEXT, -- JSON with additional details\\n ip_address TEXT,\\n user_agent TEXT,\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Create password history table for security\\nCREATE TABLE IF NOT EXISTS password_history (\\n id TEXT PRIMARY KEY,\\n user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,\\n password_hash TEXT NOT NULL,\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Insert default permissions\\nINSERT OR IGNORE INTO permissions (id, name, description, category, created_at) VALUES\\n ('perm_content_create', 'content.create', 'Create new content', 'content', strftime('%s', 'now') * 1000),\\n ('perm_content_read', 'content.read', 'View content', 'content', strftime('%s', 'now') * 1000),\\n ('perm_content_update', 'content.update', 'Edit existing content', 'content', strftime('%s', 'now') * 1000),\\n ('perm_content_delete', 'content.delete', 'Delete content', 'content', strftime('%s', 'now') * 1000),\\n ('perm_content_publish', 'content.publish', 'Publish/unpublish content', 'content', strftime('%s', 'now') * 1000),\\n \\n ('perm_collections_create', 'collections.create', 'Create new collections', 'collections', strftime('%s', 'now') * 1000),\\n ('perm_collections_read', 'collections.read', 'View collections', 'collections', strftime('%s', 'now') * 1000),\\n ('perm_collections_update', 'collections.update', 'Edit collections', 'collections', strftime('%s', 'now') * 1000),\\n ('perm_collections_delete', 'collections.delete', 'Delete collections', 'collections', strftime('%s', 'now') * 1000),\\n ('perm_collections_fields', 'collections.fields', 'Manage collection fields', 'collections', strftime('%s', 'now') * 1000),\\n \\n ('perm_media_upload', 'media.upload', 'Upload media files', 'media', strftime('%s', 'now') * 1000),\\n ('perm_media_read', 'media.read', 'View media files', 'media', strftime('%s', 'now') * 1000),\\n ('perm_media_update', 'media.update', 'Edit media metadata', 'media', strftime('%s', 'now') * 1000),\\n ('perm_media_delete', 'media.delete', 'Delete media files', 'media', strftime('%s', 'now') * 1000),\\n \\n ('perm_users_create', 'users.create', 'Invite new users', 'users', strftime('%s', 'now') * 1000),\\n ('perm_users_read', 'users.read', 'View user profiles', 'users', strftime('%s', 'now') * 1000),\\n ('perm_users_update', 'users.update', 'Edit user profiles', 'users', strftime('%s', 'now') * 1000),\\n ('perm_users_delete', 'users.delete', 'Deactivate users', 'users', strftime('%s', 'now') * 1000),\\n ('perm_users_roles', 'users.roles', 'Manage user roles', 'users', strftime('%s', 'now') * 1000),\\n \\n ('perm_settings_read', 'settings.read', 'View system settings', 'settings', strftime('%s', 'now') * 1000),\\n ('perm_settings_update', 'settings.update', 'Modify system settings', 'settings', strftime('%s', 'now') * 1000),\\n ('perm_activity_read', 'activity.read', 'View activity logs', 'settings', strftime('%s', 'now') * 1000);\\n\\n-- Assign permissions to default roles\\nINSERT OR IGNORE INTO role_permissions (id, role, permission_id, created_at) VALUES\\n -- Admin has all permissions\\n ('rp_admin_content_create', 'admin', 'perm_content_create', strftime('%s', 'now') * 1000),\\n ('rp_admin_content_read', 'admin', 'perm_content_read', strftime('%s', 'now') * 1000),\\n ('rp_admin_content_update', 'admin', 'perm_content_update', strftime('%s', 'now') * 1000),\\n ('rp_admin_content_delete', 'admin', 'perm_content_delete', strftime('%s', 'now') * 1000),\\n ('rp_admin_content_publish', 'admin', 'perm_content_publish', strftime('%s', 'now') * 1000),\\n ('rp_admin_collections_create', 'admin', 'perm_collections_create', strftime('%s', 'now') * 1000),\\n ('rp_admin_collections_read', 'admin', 'perm_collections_read', strftime('%s', 'now') * 1000),\\n ('rp_admin_collections_update', 'admin', 'perm_collections_update', strftime('%s', 'now') * 1000),\\n ('rp_admin_collections_delete', 'admin', 'perm_collections_delete', strftime('%s', 'now') * 1000),\\n ('rp_admin_collections_fields', 'admin', 'perm_collections_fields', strftime('%s', 'now') * 1000),\\n ('rp_admin_media_upload', 'admin', 'perm_media_upload', strftime('%s', 'now') * 1000),\\n ('rp_admin_media_read', 'admin', 'perm_media_read', strftime('%s', 'now') * 1000),\\n ('rp_admin_media_update', 'admin', 'perm_media_update', strftime('%s', 'now') * 1000),\\n ('rp_admin_media_delete', 'admin', 'perm_media_delete', strftime('%s', 'now') * 1000),\\n ('rp_admin_users_create', 'admin', 'perm_users_create', strftime('%s', 'now') * 1000),\\n ('rp_admin_users_read', 'admin', 'perm_users_read', strftime('%s', 'now') * 1000),\\n ('rp_admin_users_update', 'admin', 'perm_users_update', strftime('%s', 'now') * 1000),\\n ('rp_admin_users_delete', 'admin', 'perm_users_delete', strftime('%s', 'now') * 1000),\\n ('rp_admin_users_roles', 'admin', 'perm_users_roles', strftime('%s', 'now') * 1000),\\n ('rp_admin_settings_read', 'admin', 'perm_settings_read', strftime('%s', 'now') * 1000),\\n ('rp_admin_settings_update', 'admin', 'perm_settings_update', strftime('%s', 'now') * 1000),\\n ('rp_admin_activity_read', 'admin', 'perm_activity_read', strftime('%s', 'now') * 1000),\\n \\n -- Editor permissions\\n ('rp_editor_content_create', 'editor', 'perm_content_create', strftime('%s', 'now') * 1000),\\n ('rp_editor_content_read', 'editor', 'perm_content_read', strftime('%s', 'now') * 1000),\\n ('rp_editor_content_update', 'editor', 'perm_content_update', strftime('%s', 'now') * 1000),\\n ('rp_editor_content_publish', 'editor', 'perm_content_publish', strftime('%s', 'now') * 1000),\\n ('rp_editor_collections_read', 'editor', 'perm_collections_read', strftime('%s', 'now') * 1000),\\n ('rp_editor_media_upload', 'editor', 'perm_media_upload', strftime('%s', 'now') * 1000),\\n ('rp_editor_media_read', 'editor', 'perm_media_read', strftime('%s', 'now') * 1000),\\n ('rp_editor_media_update', 'editor', 'perm_media_update', strftime('%s', 'now') * 1000),\\n ('rp_editor_users_read', 'editor', 'perm_users_read', strftime('%s', 'now') * 1000),\\n \\n -- Viewer permissions\\n ('rp_viewer_content_read', 'viewer', 'perm_content_read', strftime('%s', 'now') * 1000),\\n ('rp_viewer_collections_read', 'viewer', 'perm_collections_read', strftime('%s', 'now') * 1000),\\n ('rp_viewer_media_read', 'viewer', 'perm_media_read', strftime('%s', 'now') * 1000),\\n ('rp_viewer_users_read', 'viewer', 'perm_users_read', strftime('%s', 'now') * 1000);\\n\\n-- Create indexes for performance\\nCREATE INDEX IF NOT EXISTS idx_team_memberships_team_id ON team_memberships(team_id);\\nCREATE INDEX IF NOT EXISTS idx_team_memberships_user_id ON team_memberships(user_id);\\nCREATE INDEX IF NOT EXISTS idx_user_sessions_user_id ON user_sessions(user_id);\\nCREATE INDEX IF NOT EXISTS idx_user_sessions_token_hash ON user_sessions(token_hash);\\nCREATE INDEX IF NOT EXISTS idx_activity_logs_user_id ON activity_logs(user_id);\\nCREATE INDEX IF NOT EXISTS idx_activity_logs_created_at ON activity_logs(created_at);\\nCREATE INDEX IF NOT EXISTS idx_activity_logs_resource ON activity_logs(resource_type, resource_id);\\nCREATE INDEX IF NOT EXISTS idx_password_history_user_id ON password_history(user_id);\\nCREATE INDEX IF NOT EXISTS idx_users_email_verification_token ON users(email_verification_token);\\nCREATE INDEX IF NOT EXISTS idx_users_password_reset_token ON users(password_reset_token);\\nCREATE INDEX IF NOT EXISTS idx_users_invitation_token ON users(invitation_token);\"\n },\n {\n id: '005',\n name: 'Stage7 Workflow Automation',\n filename: '005_stage7_workflow_automation.sql',\n description: 'Migration 005: Stage7 Workflow Automation',\n sql: \"-- Stage 7: Workflow & Automation Migration\\n-- This migration adds workflow and automation capabilities to SonicJS\\n\\n-- Workflow States Table\\nCREATE TABLE IF NOT EXISTS workflow_states (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n name TEXT NOT NULL,\\n description TEXT,\\n color TEXT DEFAULT '#6B7280',\\n is_initial INTEGER DEFAULT 0,\\n is_final INTEGER DEFAULT 0,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP\\n);\\n\\n-- Insert default workflow states\\nINSERT OR IGNORE INTO workflow_states (id, name, description, color, is_initial, is_final) VALUES\\n('draft', 'Draft', 'Content is being worked on', '#F59E0B', 1, 0),\\n('pending-review', 'Pending Review', 'Content is waiting for review', '#3B82F6', 0, 0),\\n('approved', 'Approved', 'Content has been approved', '#10B981', 0, 0),\\n('published', 'Published', 'Content is live', '#059669', 0, 1),\\n('rejected', 'Rejected', 'Content was rejected', '#EF4444', 0, 1),\\n('archived', 'Archived', 'Content has been archived', '#6B7280', 0, 1);\\n\\n-- Workflows Table\\nCREATE TABLE IF NOT EXISTS workflows (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n name TEXT NOT NULL,\\n description TEXT,\\n collection_id TEXT,\\n is_active INTEGER DEFAULT 1,\\n auto_publish INTEGER DEFAULT 0,\\n require_approval INTEGER DEFAULT 1,\\n approval_levels INTEGER DEFAULT 1,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (collection_id) REFERENCES collections(id) ON DELETE CASCADE\\n);\\n\\n-- Workflow Transitions Table\\nCREATE TABLE IF NOT EXISTS workflow_transitions (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n workflow_id TEXT NOT NULL,\\n from_state_id TEXT NOT NULL,\\n to_state_id TEXT NOT NULL,\\n required_permission TEXT,\\n auto_transition INTEGER DEFAULT 0,\\n transition_conditions TEXT, -- JSON\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (workflow_id) REFERENCES workflows(id) ON DELETE CASCADE,\\n FOREIGN KEY (from_state_id) REFERENCES workflow_states(id),\\n FOREIGN KEY (to_state_id) REFERENCES workflow_states(id)\\n);\\n\\n-- Content Workflow Status Table\\nCREATE TABLE IF NOT EXISTS content_workflow_status (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n content_id TEXT NOT NULL,\\n workflow_id TEXT NOT NULL,\\n current_state_id TEXT NOT NULL,\\n assigned_to TEXT,\\n due_date DATETIME,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (content_id) REFERENCES content(id) ON DELETE CASCADE,\\n FOREIGN KEY (workflow_id) REFERENCES workflows(id),\\n FOREIGN KEY (current_state_id) REFERENCES workflow_states(id),\\n FOREIGN KEY (assigned_to) REFERENCES users(id),\\n UNIQUE(content_id, workflow_id)\\n);\\n\\n-- Workflow History Table\\nCREATE TABLE IF NOT EXISTS workflow_history (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n content_id TEXT NOT NULL,\\n workflow_id TEXT NOT NULL,\\n from_state_id TEXT,\\n to_state_id TEXT NOT NULL,\\n user_id TEXT NOT NULL,\\n comment TEXT,\\n metadata TEXT, -- JSON\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (content_id) REFERENCES content(id) ON DELETE CASCADE,\\n FOREIGN KEY (workflow_id) REFERENCES workflows(id),\\n FOREIGN KEY (from_state_id) REFERENCES workflow_states(id),\\n FOREIGN KEY (to_state_id) REFERENCES workflow_states(id),\\n FOREIGN KEY (user_id) REFERENCES users(id)\\n);\\n\\n-- Scheduled Content Table\\nCREATE TABLE IF NOT EXISTS scheduled_content (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n content_id TEXT NOT NULL,\\n action TEXT NOT NULL, -- 'publish', 'unpublish', 'archive'\\n scheduled_at DATETIME NOT NULL,\\n timezone TEXT DEFAULT 'UTC',\\n user_id TEXT NOT NULL,\\n status TEXT DEFAULT 'pending', -- 'pending', 'completed', 'failed', 'cancelled'\\n executed_at DATETIME,\\n error_message TEXT,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (content_id) REFERENCES content(id) ON DELETE CASCADE,\\n FOREIGN KEY (user_id) REFERENCES users(id)\\n);\\n\\n-- Notifications Table\\nCREATE TABLE IF NOT EXISTS notifications (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n user_id TEXT NOT NULL,\\n type TEXT NOT NULL, -- 'workflow', 'schedule', 'system'\\n title TEXT NOT NULL,\\n message TEXT NOT NULL,\\n data TEXT, -- JSON\\n is_read INTEGER DEFAULT 0,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE\\n);\\n\\n-- Notification Preferences Table\\nCREATE TABLE IF NOT EXISTS notification_preferences (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n user_id TEXT NOT NULL,\\n notification_type TEXT NOT NULL,\\n email_enabled INTEGER DEFAULT 1,\\n in_app_enabled INTEGER DEFAULT 1,\\n digest_frequency TEXT DEFAULT 'daily', -- 'immediate', 'hourly', 'daily', 'weekly'\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,\\n UNIQUE(user_id, notification_type)\\n);\\n\\n-- Webhooks Table\\nCREATE TABLE IF NOT EXISTS webhooks (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n name TEXT NOT NULL,\\n url TEXT NOT NULL,\\n secret TEXT,\\n events TEXT NOT NULL, -- JSON array of event types\\n is_active INTEGER DEFAULT 1,\\n retry_count INTEGER DEFAULT 3,\\n timeout_seconds INTEGER DEFAULT 30,\\n last_success_at DATETIME,\\n last_failure_at DATETIME,\\n failure_count INTEGER DEFAULT 0,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP\\n);\\n\\n-- Webhook Deliveries Table\\nCREATE TABLE IF NOT EXISTS webhook_deliveries (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n webhook_id TEXT NOT NULL,\\n event_type TEXT NOT NULL,\\n payload TEXT NOT NULL, -- JSON\\n response_status INTEGER,\\n response_body TEXT,\\n attempt_count INTEGER DEFAULT 1,\\n delivered_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (webhook_id) REFERENCES webhooks(id) ON DELETE CASCADE\\n);\\n\\n-- Content Versions Table (for rollback functionality)\\nCREATE TABLE IF NOT EXISTS content_versions (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n content_id TEXT NOT NULL,\\n version_number INTEGER NOT NULL,\\n title TEXT NOT NULL,\\n content TEXT NOT NULL,\\n fields TEXT, -- JSON\\n user_id TEXT NOT NULL,\\n change_summary TEXT,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (content_id) REFERENCES content(id) ON DELETE CASCADE,\\n FOREIGN KEY (user_id) REFERENCES users(id),\\n UNIQUE(content_id, version_number)\\n);\\n\\n-- Automation Rules Table\\nCREATE TABLE IF NOT EXISTS automation_rules (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n name TEXT NOT NULL,\\n description TEXT,\\n trigger_type TEXT NOT NULL, -- 'content_created', 'content_updated', 'workflow_transition', 'schedule'\\n trigger_conditions TEXT, -- JSON\\n action_type TEXT NOT NULL, -- 'workflow_transition', 'send_notification', 'webhook_call', 'auto_save'\\n action_config TEXT, -- JSON\\n is_active INTEGER DEFAULT 1,\\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP\\n);\\n\\n-- Auto-save Drafts Table\\nCREATE TABLE IF NOT EXISTS auto_save_drafts (\\n id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\\n content_id TEXT,\\n user_id TEXT NOT NULL,\\n title TEXT,\\n content TEXT,\\n fields TEXT, -- JSON\\n last_saved_at DATETIME DEFAULT CURRENT_TIMESTAMP,\\n FOREIGN KEY (content_id) REFERENCES content(id) ON DELETE CASCADE,\\n FOREIGN KEY (user_id) REFERENCES users(id),\\n UNIQUE(content_id, user_id)\\n);\\n\\n-- Add workflow-related columns to existing content table (skip existing columns)\\nALTER TABLE content ADD COLUMN workflow_state_id TEXT DEFAULT 'draft';\\nALTER TABLE content ADD COLUMN embargo_until DATETIME;\\nALTER TABLE content ADD COLUMN expires_at DATETIME;\\nALTER TABLE content ADD COLUMN version_number INTEGER DEFAULT 1;\\nALTER TABLE content ADD COLUMN is_auto_saved INTEGER DEFAULT 0;\\n\\n-- Create indexes for performance\\nCREATE INDEX IF NOT EXISTS idx_content_workflow_status_content_id ON content_workflow_status(content_id);\\nCREATE INDEX IF NOT EXISTS idx_content_workflow_status_workflow_id ON content_workflow_status(workflow_id);\\nCREATE INDEX IF NOT EXISTS idx_workflow_history_content_id ON workflow_history(content_id);\\nCREATE INDEX IF NOT EXISTS idx_scheduled_content_scheduled_at ON scheduled_content(scheduled_at);\\nCREATE INDEX IF NOT EXISTS idx_scheduled_content_status ON scheduled_content(status);\\nCREATE INDEX IF NOT EXISTS idx_notifications_user_id ON notifications(user_id);\\nCREATE INDEX IF NOT EXISTS idx_notifications_is_read ON notifications(is_read);\\nCREATE INDEX IF NOT EXISTS idx_content_versions_content_id ON content_versions(content_id);\\nCREATE INDEX IF NOT EXISTS idx_auto_save_drafts_user_id ON auto_save_drafts(user_id);\\nCREATE INDEX IF NOT EXISTS idx_content_workflow_state ON content(workflow_state_id);\\nCREATE INDEX IF NOT EXISTS idx_content_scheduled_publish ON content(scheduled_publish_at);\\n\\n-- Insert default workflow for collections\\nINSERT OR IGNORE INTO workflows (id, name, description, collection_id, is_active, require_approval, approval_levels) \\nSELECT \\n 'default-' || id,\\n 'Default Workflow for ' || name,\\n 'Standard content approval workflow',\\n id,\\n 1,\\n 1,\\n 1\\nFROM collections;\\n\\n-- Insert default workflow transitions\\nINSERT OR IGNORE INTO workflow_transitions (workflow_id, from_state_id, to_state_id, required_permission) \\nSELECT \\n w.id,\\n 'draft',\\n 'pending-review',\\n 'content:submit'\\nFROM workflows w;\\n\\nINSERT OR IGNORE INTO workflow_transitions (workflow_id, from_state_id, to_state_id, required_permission) \\nSELECT \\n w.id,\\n 'pending-review',\\n 'approved',\\n 'content:approve'\\nFROM workflows w;\\n\\nINSERT OR IGNORE INTO workflow_transitions (workflow_id, from_state_id, to_state_id, required_permission) \\nSELECT \\n w.id,\\n 'approved',\\n 'published',\\n 'content:publish'\\nFROM workflows w;\\n\\nINSERT OR IGNORE INTO workflow_transitions (workflow_id, from_state_id, to_state_id, required_permission) \\nSELECT \\n w.id,\\n 'pending-review',\\n 'rejected',\\n 'content:approve'\\nFROM workflows w;\\n\\n-- Insert default notification preferences for all users\\nINSERT OR IGNORE INTO notification_preferences (user_id, notification_type, email_enabled, in_app_enabled)\\nSELECT \\n id,\\n 'workflow_assigned',\\n 1,\\n 1\\nFROM users;\\n\\nINSERT OR IGNORE INTO notification_preferences (user_id, notification_type, email_enabled, in_app_enabled)\\nSELECT \\n id,\\n 'workflow_status_change',\\n 1,\\n 1\\nFROM users;\\n\\nINSERT OR IGNORE INTO notification_preferences (user_id, notification_type, email_enabled, in_app_enabled)\\nSELECT \\n id,\\n 'content_scheduled',\\n 1,\\n 1\\nFROM users;\"\n },\n {\n id: '006',\n name: 'Plugin System',\n filename: '006_plugin_system.sql',\n description: 'Migration 006: Plugin System',\n sql: \"-- Plugin System Tables\\n-- Migration: 006_plugin_system\\n-- Description: Add plugin management system tables\\n\\n-- Plugins table\\nCREATE TABLE IF NOT EXISTS plugins (\\n id TEXT PRIMARY KEY,\\n name TEXT NOT NULL UNIQUE,\\n display_name TEXT NOT NULL,\\n description TEXT,\\n version TEXT NOT NULL,\\n author TEXT NOT NULL,\\n category TEXT NOT NULL,\\n icon TEXT,\\n status TEXT DEFAULT 'inactive' CHECK (status IN ('active', 'inactive', 'error')),\\n is_core BOOLEAN DEFAULT FALSE,\\n settings JSON,\\n permissions JSON,\\n dependencies JSON,\\n download_count INTEGER DEFAULT 0,\\n rating REAL DEFAULT 0,\\n installed_at INTEGER NOT NULL,\\n activated_at INTEGER,\\n last_updated INTEGER NOT NULL,\\n error_message TEXT,\\n created_at INTEGER DEFAULT (unixepoch()),\\n updated_at INTEGER DEFAULT (unixepoch())\\n);\\n\\n-- Plugin hooks table (registered hooks by plugins)\\nCREATE TABLE IF NOT EXISTS plugin_hooks (\\n id TEXT PRIMARY KEY,\\n plugin_id TEXT NOT NULL,\\n hook_name TEXT NOT NULL,\\n handler_name TEXT NOT NULL,\\n priority INTEGER DEFAULT 10,\\n is_active BOOLEAN DEFAULT TRUE,\\n created_at INTEGER DEFAULT (unixepoch()),\\n FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE,\\n UNIQUE(plugin_id, hook_name, handler_name)\\n);\\n\\n-- Plugin routes table\\nCREATE TABLE IF NOT EXISTS plugin_routes (\\n id TEXT PRIMARY KEY,\\n plugin_id TEXT NOT NULL,\\n path TEXT NOT NULL,\\n method TEXT NOT NULL,\\n handler_name TEXT NOT NULL,\\n middleware JSON,\\n is_active BOOLEAN DEFAULT TRUE,\\n created_at INTEGER DEFAULT (unixepoch()),\\n FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE,\\n UNIQUE(plugin_id, path, method)\\n);\\n\\n-- Plugin assets table (CSS, JS files provided by plugins)\\nCREATE TABLE IF NOT EXISTS plugin_assets (\\n id TEXT PRIMARY KEY,\\n plugin_id TEXT NOT NULL,\\n asset_type TEXT NOT NULL CHECK (asset_type IN ('css', 'js', 'image', 'font')),\\n asset_path TEXT NOT NULL,\\n load_order INTEGER DEFAULT 100,\\n load_location TEXT DEFAULT 'footer' CHECK (load_location IN ('header', 'footer')),\\n is_active BOOLEAN DEFAULT TRUE,\\n created_at INTEGER DEFAULT (unixepoch()),\\n FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE\\n);\\n\\n-- Plugin activity log\\nCREATE TABLE IF NOT EXISTS plugin_activity_log (\\n id TEXT PRIMARY KEY,\\n plugin_id TEXT NOT NULL,\\n action TEXT NOT NULL,\\n user_id TEXT,\\n details JSON,\\n timestamp INTEGER DEFAULT (unixepoch()),\\n FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE\\n);\\n\\n-- Create indexes\\nCREATE INDEX IF NOT EXISTS idx_plugins_status ON plugins(status);\\nCREATE INDEX IF NOT EXISTS idx_plugins_category ON plugins(category);\\nCREATE INDEX IF NOT EXISTS idx_plugin_hooks_plugin ON plugin_hooks(plugin_id);\\nCREATE INDEX IF NOT EXISTS idx_plugin_routes_plugin ON plugin_routes(plugin_id);\\nCREATE INDEX IF NOT EXISTS idx_plugin_assets_plugin ON plugin_assets(plugin_id);\\nCREATE INDEX IF NOT EXISTS idx_plugin_activity_plugin ON plugin_activity_log(plugin_id);\\nCREATE INDEX IF NOT EXISTS idx_plugin_activity_timestamp ON plugin_activity_log(timestamp);\\n\\n-- Insert core plugins\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, installed_at, last_updated\\n) VALUES \\n(\\n 'core-auth',\\n 'core-auth',\\n 'Authentication System',\\n 'Core authentication and user management system',\\n '1.0.0',\\n 'SonicJS Team',\\n 'security',\\n '🔐',\\n 'active',\\n TRUE,\\n '[\\\"manage:users\\\", \\\"manage:roles\\\", \\\"manage:permissions\\\"]',\\n unixepoch(),\\n unixepoch()\\n),\\n(\\n 'core-media',\\n 'core-media', \\n 'Media Manager',\\n 'Core media upload and management system',\\n '1.0.0',\\n 'SonicJS Team',\\n 'media',\\n '📸',\\n 'active',\\n TRUE,\\n '[\\\"manage:media\\\", \\\"upload:files\\\"]',\\n unixepoch(),\\n unixepoch()\\n),\\n(\\n 'core-workflow',\\n 'core-workflow',\\n 'Workflow Engine',\\n 'Content workflow and approval system',\\n '1.0.0',\\n 'SonicJS Team',\\n 'content',\\n '🔄',\\n 'active',\\n TRUE,\\n '[\\\"manage:workflows\\\", \\\"approve:content\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\\n-- FAQ Plugin will be added as a third-party plugin through the admin interface\\n\\n-- Add plugin management permission\\nINSERT OR IGNORE INTO permissions (id, name, description, category, created_at)\\nVALUES (\\n 'manage:plugins',\\n 'Manage Plugins',\\n 'Install, uninstall, activate, and configure plugins',\\n 'system',\\n unixepoch()\\n);\\n\\n-- Grant plugin management permission to admin role\\nINSERT OR IGNORE INTO role_permissions (id, role, permission_id, created_at)\\nVALUES ('role-perm-manage-plugins', 'admin', 'manage:plugins', unixepoch());\"\n },\n {\n id: '007',\n name: 'Demo Login Plugin',\n filename: '007_demo_login_plugin.sql',\n description: 'Migration 007: Demo Login Plugin',\n sql: \"-- Demo Login Plugin Migration\\n-- Migration: 007_demo_login_plugin\\n-- Description: Add demo login prefill plugin to the plugin registry\\n\\n-- Insert demo login plugin\\nINSERT INTO plugins (\\n id, name, display_name, description, version, author, category, icon, \\n status, is_core, permissions, installed_at, last_updated\\n) VALUES (\\n 'demo-login-prefill',\\n 'demo-login-plugin',\\n 'Demo Login Prefill',\\n 'Prefills login form with demo credentials (admin@sonicjs.com/sonicjs!) for easy site demonstration',\\n '1.0.0',\\n 'SonicJS',\\n 'demo',\\n '🎯',\\n 'inactive',\\n TRUE,\\n '[]',\\n unixepoch(),\\n unixepoch()\\n);\"\n },\n {\n id: '008',\n name: 'Fix Slug Validation',\n filename: '008_fix_slug_validation.sql',\n description: 'Migration 008: Fix Slug Validation',\n sql: \"-- Migration: Fix overly restrictive slug validation patterns\\n-- This migration relaxes the slug field validation to be more user-friendly\\n\\n-- Update the pages collection slug field to allow underscores and be less restrictive\\nUPDATE content_fields \\nSET field_options = '{\\\"pattern\\\": \\\"^[a-zA-Z0-9_-]+$\\\", \\\"placeholder\\\": \\\"url-friendly-slug\\\", \\\"help\\\": \\\"Use letters, numbers, underscores, and hyphens only\\\"}'\\nWHERE field_name = 'slug' AND collection_id = 'pages-collection';\\n\\n-- Update blog posts slug field if it exists\\nUPDATE content_fields \\nSET field_options = '{\\\"pattern\\\": \\\"^[a-zA-Z0-9_-]+$\\\", \\\"placeholder\\\": \\\"url-friendly-slug\\\", \\\"help\\\": \\\"Use letters, numbers, underscores, and hyphens only\\\"}'\\nWHERE field_name = 'slug' AND collection_id = 'blog-posts-collection';\\n\\n-- Update news slug field if it exists\\nUPDATE content_fields \\nSET field_options = '{\\\"pattern\\\": \\\"^[a-zA-Z0-9_-]+$\\\", \\\"placeholder\\\": \\\"url-friendly-slug\\\", \\\"help\\\": \\\"Use letters, numbers, underscores, and hyphens only\\\"}'\\nWHERE field_name = 'slug' AND collection_id = 'news-collection';\\n\\n-- Update any other slug fields with the restrictive pattern\\nUPDATE content_fields \\nSET field_options = REPLACE(field_options, '\\\"pattern\\\": \\\"^[a-z0-9-]+$\\\"', '\\\"pattern\\\": \\\"^[a-zA-Z0-9_-]+$\\\"')\\nWHERE field_options LIKE '%\\\"pattern\\\": \\\"^[a-z0-9-]+$\\\"%';\"\n },\n {\n id: '009',\n name: 'System Logging',\n filename: '009_system_logging.sql',\n description: 'Migration 009: System Logging',\n sql: \"-- System Logging Tables\\n-- Migration: 009_system_logging\\n-- Description: Add system logging and configuration tables\\n\\n-- System logs table for tracking application events\\nCREATE TABLE IF NOT EXISTS system_logs (\\n id TEXT PRIMARY KEY,\\n level TEXT NOT NULL CHECK (level IN ('debug', 'info', 'warn', 'error', 'fatal')),\\n category TEXT NOT NULL CHECK (category IN ('auth', 'api', 'workflow', 'plugin', 'media', 'system', 'security', 'error')),\\n message TEXT NOT NULL,\\n data TEXT, -- JSON data\\n user_id TEXT,\\n session_id TEXT,\\n request_id TEXT,\\n ip_address TEXT,\\n user_agent TEXT,\\n method TEXT,\\n url TEXT,\\n status_code INTEGER,\\n duration INTEGER, -- milliseconds\\n stack_trace TEXT,\\n tags TEXT, -- JSON array\\n source TEXT, -- source of the log entry\\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\\n FOREIGN KEY (user_id) REFERENCES users(id)\\n);\\n\\n-- Log configuration table for managing log settings per category\\nCREATE TABLE IF NOT EXISTS log_config (\\n id TEXT PRIMARY KEY,\\n category TEXT NOT NULL UNIQUE CHECK (category IN ('auth', 'api', 'workflow', 'plugin', 'media', 'system', 'security', 'error')),\\n enabled BOOLEAN NOT NULL DEFAULT TRUE,\\n level TEXT NOT NULL DEFAULT 'info' CHECK (level IN ('debug', 'info', 'warn', 'error', 'fatal')),\\n retention_days INTEGER NOT NULL DEFAULT 30,\\n max_size_mb INTEGER NOT NULL DEFAULT 100,\\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\\n updated_at INTEGER NOT NULL DEFAULT (unixepoch())\\n);\\n\\n-- Create indexes for better performance\\nCREATE INDEX IF NOT EXISTS idx_system_logs_level ON system_logs(level);\\nCREATE INDEX IF NOT EXISTS idx_system_logs_category ON system_logs(category);\\nCREATE INDEX IF NOT EXISTS idx_system_logs_created_at ON system_logs(created_at);\\nCREATE INDEX IF NOT EXISTS idx_system_logs_user_id ON system_logs(user_id);\\nCREATE INDEX IF NOT EXISTS idx_system_logs_status_code ON system_logs(status_code);\\nCREATE INDEX IF NOT EXISTS idx_system_logs_source ON system_logs(source);\\n\\n-- Insert default log configurations\\nINSERT OR IGNORE INTO log_config (id, category, enabled, level, retention_days, max_size_mb) VALUES\\n('log-config-auth', 'auth', TRUE, 'info', 90, 50),\\n('log-config-api', 'api', TRUE, 'info', 30, 100),\\n('log-config-workflow', 'workflow', TRUE, 'info', 60, 50),\\n('log-config-plugin', 'plugin', TRUE, 'warn', 30, 25),\\n('log-config-media', 'media', TRUE, 'info', 30, 50),\\n('log-config-system', 'system', TRUE, 'info', 90, 100),\\n('log-config-security', 'security', TRUE, 'warn', 180, 100),\\n('log-config-error', 'error', TRUE, 'error', 90, 200);\"\n },\n {\n id: '011',\n name: 'Config Managed Collections',\n filename: '011_config_managed_collections.sql',\n description: 'Migration 011: Config Managed Collections',\n sql: \"-- Migration: Add Config-Managed Collections Support\\n-- Description: Add 'managed' column to collections table to support config-based collection definitions\\n-- Created: 2025-10-03\\n\\n-- Add 'managed' column to collections table\\n-- This column indicates whether a collection is managed by configuration files (true) or user-created (false)\\n-- Managed collections cannot be edited through the admin UI\\n-- Use a safe approach to add the column only if it doesn't exist\\nALTER TABLE collections ADD COLUMN managed INTEGER DEFAULT 0 NOT NULL;\\n\\n-- Create an index on the managed column for faster queries\\nCREATE INDEX IF NOT EXISTS idx_collections_managed ON collections(managed);\\n\\n-- Create an index on managed + is_active for efficient filtering\\nCREATE INDEX IF NOT EXISTS idx_collections_managed_active ON collections(managed, is_active);\\n\"\n },\n {\n id: '012',\n name: 'Testimonials Plugin',\n filename: '012_testimonials_plugin.sql',\n description: 'Migration 012: Testimonials Plugin',\n sql: \"-- Testimonials Plugin Migration\\n-- Creates testimonials table for the testimonials plugin\\n-- This demonstrates a code-based collection defined in src/plugins/core-plugins/testimonials-plugin.ts\\n\\nCREATE TABLE IF NOT EXISTS testimonials (\\n id INTEGER PRIMARY KEY AUTOINCREMENT,\\n author_name TEXT NOT NULL,\\n author_title TEXT,\\n author_company TEXT,\\n testimonial_text TEXT NOT NULL,\\n rating INTEGER CHECK(rating >= 1 AND rating <= 5),\\n isPublished INTEGER NOT NULL DEFAULT 1,\\n sortOrder INTEGER NOT NULL DEFAULT 0,\\n created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),\\n updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))\\n);\\n\\n-- Create indexes for better performance\\nCREATE INDEX IF NOT EXISTS idx_testimonials_published ON testimonials(isPublished);\\nCREATE INDEX IF NOT EXISTS idx_testimonials_sort_order ON testimonials(sortOrder);\\nCREATE INDEX IF NOT EXISTS idx_testimonials_rating ON testimonials(rating);\\n\\n-- Create trigger to update updated_at timestamp\\nCREATE TRIGGER IF NOT EXISTS testimonials_updated_at\\n AFTER UPDATE ON testimonials\\nBEGIN\\n UPDATE testimonials SET updated_at = strftime('%s', 'now') WHERE id = NEW.id;\\nEND;\\n\\n-- Insert plugin record\\nINSERT OR IGNORE INTO plugins (name, display_name, description, version, status, category, settings) VALUES\\n('testimonials',\\n 'Customer Testimonials',\\n 'Manage customer testimonials and reviews with rating support. This is a code-based collection example.',\\n '1.0.0',\\n 'active',\\n 'content',\\n '{\\\"defaultPublished\\\": true, \\\"requireRating\\\": false}');\\n\\n-- Insert sample testimonial data\\nINSERT OR IGNORE INTO testimonials (author_name, author_title, author_company, testimonial_text, rating, isPublished, sortOrder) VALUES\\n('Jane Smith',\\n 'CTO',\\n 'TechStartup Inc',\\n 'SonicJS AI has transformed how we manage our content. The plugin architecture is brilliant and the edge deployment is blazing fast.',\\n 5,\\n 1,\\n 1),\\n\\n('Michael Chen',\\n 'Lead Developer',\\n 'Digital Agency Co',\\n 'We migrated from WordPress to SonicJS AI and couldn''t be happier. The TypeScript-first approach and modern tooling make development a joy.',\\n 5,\\n 1,\\n 2),\\n\\n('Sarah Johnson',\\n 'Product Manager',\\n 'E-commerce Solutions',\\n 'The headless CMS approach combined with Cloudflare Workers gives us unmatched performance. Our content is served globally with minimal latency.',\\n 4,\\n 1,\\n 3),\\n\\n('David Rodriguez',\\n 'Full Stack Developer',\\n 'Creative Studio',\\n 'Great CMS for modern web applications. The admin interface is clean and the API is well-designed. Plugin system is very flexible.',\\n 5,\\n 1,\\n 4),\\n\\n('Emily Watson',\\n 'Technical Director',\\n 'Media Company',\\n 'SonicJS AI solved our content distribution challenges. The R2 integration for media storage works flawlessly and scales effortlessly.',\\n 4,\\n 1,\\n 5);\\n\"\n },\n {\n id: '013',\n name: 'Code Examples Plugin',\n filename: '013_code_examples_plugin.sql',\n description: 'Migration 013: Code Examples Plugin',\n sql: \"-- Code Examples Plugin Migration\\n-- Creates code_examples table for the code examples plugin\\n-- This demonstrates a code-based collection for storing and managing code snippets\\n\\nCREATE TABLE IF NOT EXISTS code_examples (\\n id INTEGER PRIMARY KEY AUTOINCREMENT,\\n title TEXT NOT NULL,\\n description TEXT,\\n code TEXT NOT NULL,\\n language TEXT NOT NULL,\\n category TEXT,\\n tags TEXT,\\n isPublished INTEGER NOT NULL DEFAULT 1,\\n sortOrder INTEGER NOT NULL DEFAULT 0,\\n created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),\\n updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))\\n);\\n\\n-- Create indexes for better performance\\nCREATE INDEX IF NOT EXISTS idx_code_examples_published ON code_examples(isPublished);\\nCREATE INDEX IF NOT EXISTS idx_code_examples_sort_order ON code_examples(sortOrder);\\nCREATE INDEX IF NOT EXISTS idx_code_examples_language ON code_examples(language);\\nCREATE INDEX IF NOT EXISTS idx_code_examples_category ON code_examples(category);\\n\\n-- Create trigger to update updated_at timestamp\\nCREATE TRIGGER IF NOT EXISTS code_examples_updated_at\\n AFTER UPDATE ON code_examples\\nBEGIN\\n UPDATE code_examples SET updated_at = strftime('%s', 'now') WHERE id = NEW.id;\\nEND;\\n\\n-- Insert plugin record\\nINSERT OR IGNORE INTO plugins (name, display_name, description, version, status, category, settings) VALUES\\n('code-examples',\\n 'Code Examples',\\n 'Manage code snippets and examples with syntax highlighting support. Perfect for documentation and tutorials.',\\n '1.0.0',\\n 'active',\\n 'content',\\n '{\\\"defaultPublished\\\": true, \\\"supportedLanguages\\\": [\\\"javascript\\\", \\\"typescript\\\", \\\"python\\\", \\\"go\\\", \\\"rust\\\", \\\"java\\\", \\\"php\\\", \\\"ruby\\\", \\\"sql\\\"]}');\\n\\n-- Insert sample code examples\\nINSERT OR IGNORE INTO code_examples (title, description, code, language, category, tags, isPublished, sortOrder) VALUES\\n('React useState Hook',\\n 'Basic example of using the useState hook in React for managing component state.',\\n 'import { useState } from ''react'';\\n\\nfunction Counter() {\\n const [count, setCount] = useState(0);\\n\\n return (\\n <div>\\n <p>Count: {count}</p>\\n <button onClick={() => setCount(count + 1)}>\\n Increment\\n </button>\\n </div>\\n );\\n}\\n\\nexport default Counter;',\\n 'javascript',\\n 'frontend',\\n 'react,hooks,state',\\n 1,\\n 1),\\n\\n('TypeScript Interface Example',\\n 'Defining a TypeScript interface for type-safe objects.',\\n 'interface User {\\n id: string;\\n email: string;\\n name: string;\\n role: ''admin'' | ''editor'' | ''viewer'';\\n createdAt: Date;\\n}\\n\\nfunction greetUser(user: User): string {\\n return `Hello, ${user.name}!`;\\n}\\n\\nconst user: User = {\\n id: ''123'',\\n email: ''user@example.com'',\\n name: ''John Doe'',\\n role: ''admin'',\\n createdAt: new Date()\\n};\\n\\nconsole.log(greetUser(user));',\\n 'typescript',\\n 'backend',\\n 'typescript,types,interface',\\n 1,\\n 2),\\n\\n('Python List Comprehension',\\n 'Elegant way to create lists in Python using list comprehensions.',\\n '# Basic list comprehension\\nsquares = [x**2 for x in range(10)]\\nprint(squares) # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\\n\\n# With condition\\neven_squares = [x**2 for x in range(10) if x % 2 == 0]\\nprint(even_squares) # [0, 4, 16, 36, 64]\\n\\n# Nested list comprehension\\nmatrix = [[i+j for j in range(3)] for i in range(3)]\\nprint(matrix) # [[0, 1, 2], [1, 2, 3], [2, 3, 4]]',\\n 'python',\\n 'general',\\n 'python,lists,comprehension',\\n 1,\\n 3),\\n\\n('SQL Join Example',\\n 'Common SQL JOIN patterns for combining data from multiple tables.',\\n '-- INNER JOIN: Returns only matching rows\\nSELECT users.name, orders.total\\nFROM users\\nINNER JOIN orders ON users.id = orders.user_id;\\n\\n-- LEFT JOIN: Returns all users, even without orders\\nSELECT users.name, orders.total\\nFROM users\\nLEFT JOIN orders ON users.id = orders.user_id;\\n\\n-- Multiple JOINs\\nSELECT\\n users.name,\\n orders.order_date,\\n products.name AS product_name\\nFROM users\\nINNER JOIN orders ON users.id = orders.user_id\\nINNER JOIN order_items ON orders.id = order_items.order_id\\nINNER JOIN products ON order_items.product_id = products.id;',\\n 'sql',\\n 'database',\\n 'sql,joins,queries',\\n 1,\\n 4),\\n\\n('Go Error Handling',\\n 'Idiomatic error handling pattern in Go.',\\n 'package main\\n\\nimport (\\n\\t\\\"errors\\\"\\n\\t\\\"fmt\\\"\\n)\\n\\nfunc divide(a, b float64) (float64, error) {\\n\\tif b == 0 {\\n\\t\\treturn 0, errors.New(\\\"division by zero\\\")\\n\\t}\\n\\treturn a / b, nil\\n}\\n\\nfunc main() {\\n\\tresult, err := divide(10, 2)\\n\\tif err != nil {\\n\\t\\tfmt.Println(\\\"Error:\\\", err)\\n\\t\\treturn\\n\\t}\\n\\tfmt.Printf(\\\"Result: %.2f\\\\n\\\", result)\\n\\n\\t// This will error\\n\\t_, err = divide(10, 0)\\n\\tif err != nil {\\n\\t\\tfmt.Println(\\\"Error:\\\", err)\\n\\t}\\n}',\\n 'go',\\n 'backend',\\n 'go,error-handling,functions',\\n 1,\\n 5);\\n\"\n },\n {\n id: '014',\n name: 'Fix Plugin Registry',\n filename: '014_fix_plugin_registry.sql',\n description: 'Migration 014: Fix Plugin Registry',\n sql: \"-- Fix Plugin Registry\\n-- Migration: 014_fix_plugin_registry\\n-- Description: Add missing plugins and fix plugin name mismatches\\n\\n-- Note: Cannot easily update plugin names as they may be referenced elsewhere\\n-- Instead we'll add the missing plugins with correct names\\n\\n-- Insert missing plugins\\n\\n-- Core Analytics Plugin\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, installed_at, last_updated\\n) VALUES (\\n 'core-analytics',\\n 'core-analytics',\\n 'Analytics & Tracking',\\n 'Core analytics tracking and reporting plugin with page views and event tracking',\\n '1.0.0',\\n 'SonicJS Team',\\n 'analytics',\\n '📊',\\n 'active',\\n TRUE,\\n '[\\\"view:analytics\\\", \\\"manage:tracking\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\\n-- FAQ Plugin\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, installed_at, last_updated\\n) VALUES (\\n 'faq-plugin',\\n 'faq-plugin',\\n 'FAQ Management',\\n 'Frequently Asked Questions management plugin with categories, search, and custom styling',\\n '1.0.0',\\n 'SonicJS',\\n 'content',\\n '❓',\\n 'active',\\n FALSE,\\n '[\\\"manage:faqs\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\\n-- Seed Data Plugin\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, installed_at, last_updated\\n) VALUES (\\n 'seed-data',\\n 'seed-data',\\n 'Seed Data Generator',\\n 'Generate realistic example users and content for testing and development',\\n '1.0.0',\\n 'SonicJS Team',\\n 'development',\\n '🌱',\\n 'inactive',\\n FALSE,\\n '[\\\"admin\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\\n-- Database Tools Plugin\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, installed_at, last_updated\\n) VALUES (\\n 'database-tools',\\n 'database-tools',\\n 'Database Tools',\\n 'Database management tools including truncate, backup, and validation',\\n '1.0.0',\\n 'SonicJS Team',\\n 'system',\\n '🗄️',\\n 'active',\\n FALSE,\\n '[\\\"manage:database\\\", \\\"admin\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n },\n {\n id: '015',\n name: 'Add Remaining Plugins',\n filename: '015_add_remaining_plugins.sql',\n description: 'Migration 015: Add Remaining Plugins',\n sql: \"-- Add Remaining Plugins\\n-- Migration: 015_add_remaining_plugins\\n-- Description: Add all remaining core plugins that were missing from the registry\\n\\n-- Testimonials Plugin (with correct name)\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, settings, installed_at, last_updated\\n) VALUES (\\n 'testimonials-plugin',\\n 'testimonials-plugin',\\n 'Customer Testimonials',\\n 'Manage customer testimonials and reviews with rating support',\\n '1.0.0',\\n 'SonicJS',\\n 'content',\\n '⭐',\\n 'active',\\n FALSE,\\n '[\\\"manage:testimonials\\\"]',\\n '[]',\\n '{\\\"defaultPublished\\\": true, \\\"requireRating\\\": false}',\\n unixepoch(),\\n unixepoch()\\n);\\n\\n-- Code Examples Plugin (with correct name)\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, settings, installed_at, last_updated\\n) VALUES (\\n 'code-examples-plugin',\\n 'code-examples-plugin',\\n 'Code Examples',\\n 'Manage code snippets and examples with syntax highlighting support',\\n '1.0.0',\\n 'SonicJS',\\n 'content',\\n '💻',\\n 'active',\\n FALSE,\\n '[\\\"manage:code-examples\\\"]',\\n '[]',\\n '{\\\"defaultPublished\\\": true, \\\"supportedLanguages\\\": [\\\"javascript\\\", \\\"typescript\\\", \\\"python\\\", \\\"go\\\", \\\"rust\\\", \\\"java\\\", \\\"php\\\", \\\"ruby\\\", \\\"sql\\\"]}',\\n unixepoch(),\\n unixepoch()\\n);\\n\\n-- Workflow Plugin (with correct name)\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, installed_at, last_updated\\n) VALUES (\\n 'workflow-plugin',\\n 'workflow-plugin',\\n 'Workflow Engine',\\n 'Content workflow management with approval chains, scheduling, and automation',\\n '1.0.0',\\n 'SonicJS Team',\\n 'content',\\n '🔄',\\n 'active',\\n TRUE,\\n '[\\\"manage:workflows\\\", \\\"approve:content\\\"]',\\n '[]',\\n unixepoch(),\\n unixepoch()\\n);\\n\\n-- Demo Login Plugin (already exists with correct name from migration 007, but let's ensure it's there)\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, installed_at, last_updated\\n) VALUES (\\n 'demo-login-plugin',\\n 'demo-login-plugin',\\n 'Demo Login Prefill',\\n 'Prefills login form with demo credentials for easy site demonstration',\\n '1.0.0',\\n 'SonicJS',\\n 'demo',\\n '🎯',\\n 'active',\\n FALSE,\\n '[]',\\n '[]',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n },\n {\n id: '016',\n name: 'Remove Duplicate Cache Plugin',\n filename: '016_remove_duplicate_cache_plugin.sql',\n description: 'Migration 016: Remove Duplicate Cache Plugin',\n sql: \"-- Migration: Remove duplicate cache plugin entry\\n-- Description: Removes the old 'cache' plugin (id: 'cache') that is a duplicate of 'core-cache'\\n-- This fixes the issue where Cache System appears twice in the plugins list\\n-- Created: 2025-10-14\\n\\n-- Remove the old 'cache' plugin entry if it exists\\n-- The correct plugin is 'core-cache' which is managed by plugin-bootstrap.ts\\nDELETE FROM plugins WHERE id = 'cache' AND name = 'cache';\\n\\n-- Clean up any related entries in plugin activity log\\nDELETE FROM plugin_activity_log WHERE plugin_id = 'cache';\\n\\n-- Clean up any related entries in plugin hooks\\nDELETE FROM plugin_hooks WHERE plugin_id = 'cache';\\n\\n-- Clean up any related entries in plugin routes\\nDELETE FROM plugin_routes WHERE plugin_id = 'cache';\\n\"\n },\n {\n id: '017',\n name: 'Auth Configurable Fields',\n filename: '017_auth_configurable_fields.sql',\n description: 'Migration 017: Auth Configurable Fields',\n sql: \"-- Migration: Make authentication fields configurable\\n-- This migration updates the core-auth plugin to support configurable required fields\\n\\n-- The settings will be stored in the plugins table as JSON\\n-- Default settings for core-auth plugin include:\\n-- {\\n-- \\\"requiredFields\\\": {\\n-- \\\"email\\\": { \\\"required\\\": true, \\\"minLength\\\": 5 },\\n-- \\\"password\\\": { \\\"required\\\": true, \\\"minLength\\\": 8 },\\n-- \\\"username\\\": { \\\"required\\\": true, \\\"minLength\\\": 3 },\\n-- \\\"firstName\\\": { \\\"required\\\": true, \\\"minLength\\\": 1 },\\n-- \\\"lastName\\\": { \\\"required\\\": true, \\\"minLength\\\": 1 }\\n-- },\\n-- \\\"validation\\\": {\\n-- \\\"emailFormat\\\": true,\\n-- \\\"allowDuplicateUsernames\\\": false\\n-- }\\n-- }\\n\\n-- Update core-auth plugin settings with configurable field requirements\\nUPDATE plugins\\nSET settings = json_object(\\n 'requiredFields', json_object(\\n 'email', json_object('required', 1, 'minLength', 5, 'label', 'Email', 'type', 'email'),\\n 'password', json_object('required', 1, 'minLength', 8, 'label', 'Password', 'type', 'password'),\\n 'username', json_object('required', 1, 'minLength', 3, 'label', 'Username', 'type', 'text'),\\n 'firstName', json_object('required', 1, 'minLength', 1, 'label', 'First Name', 'type', 'text'),\\n 'lastName', json_object('required', 1, 'minLength', 1, 'label', 'Last Name', 'type', 'text')\\n ),\\n 'validation', json_object(\\n 'emailFormat', 1,\\n 'allowDuplicateUsernames', 0,\\n 'passwordRequirements', json_object(\\n 'requireUppercase', 0,\\n 'requireLowercase', 0,\\n 'requireNumbers', 0,\\n 'requireSpecialChars', 0\\n )\\n ),\\n 'registration', json_object(\\n 'enabled', 1,\\n 'requireEmailVerification', 0,\\n 'defaultRole', 'viewer'\\n )\\n)\\nWHERE id = 'core-auth';\\n\\n-- If core-auth plugin doesn't exist, this migration will be handled by bootstrap\\n-- No need to insert here as plugin bootstrap handles initial plugin creation\\n\"\n },\n {\n id: '018',\n name: 'Settings Table',\n filename: '018_settings_table.sql',\n description: 'Migration 018: Settings Table',\n sql: \"-- Create settings table for storing application settings\\nCREATE TABLE IF NOT EXISTS settings (\\n id TEXT PRIMARY KEY,\\n category TEXT NOT NULL, -- 'general', 'appearance', 'security', etc.\\n key TEXT NOT NULL,\\n value TEXT NOT NULL, -- JSON value\\n created_at INTEGER NOT NULL,\\n updated_at INTEGER NOT NULL,\\n UNIQUE(category, key)\\n);\\n\\n-- Insert default general settings\\nINSERT OR IGNORE INTO settings (id, category, key, value, created_at, updated_at)\\nVALUES\\n (lower(hex(randomblob(16))), 'general', 'siteName', '\\\"SonicJS AI\\\"', unixepoch() * 1000, unixepoch() * 1000),\\n (lower(hex(randomblob(16))), 'general', 'siteDescription', '\\\"A modern headless CMS powered by AI\\\"', unixepoch() * 1000, unixepoch() * 1000),\\n (lower(hex(randomblob(16))), 'general', 'timezone', '\\\"UTC\\\"', unixepoch() * 1000, unixepoch() * 1000),\\n (lower(hex(randomblob(16))), 'general', 'language', '\\\"en\\\"', unixepoch() * 1000, unixepoch() * 1000),\\n (lower(hex(randomblob(16))), 'general', 'maintenanceMode', 'false', unixepoch() * 1000, unixepoch() * 1000);\\n\\n-- Create index for faster lookups\\nCREATE INDEX IF NOT EXISTS idx_settings_category ON settings(category);\\nCREATE INDEX IF NOT EXISTS idx_settings_category_key ON settings(category, key);\\n\"\n },\n {\n id: '019',\n name: 'Remove Blog Posts Collection',\n filename: '019_remove_blog_posts_collection.sql',\n description: 'Migration 019: Remove Blog Posts Collection',\n sql: \"-- Migration: Remove blog_posts from database-managed collections\\n-- Description: Remove blog-posts-collection from the database so it can be managed by code-based collection\\n-- Created: 2025-11-04\\n\\n-- Delete content associated with blog-posts-collection\\nDELETE FROM content WHERE collection_id = 'blog-posts-collection';\\n\\n-- Delete content fields for blog-posts-collection\\nDELETE FROM content_fields WHERE collection_id = 'blog-posts-collection';\\n\\n-- Delete the blog-posts collection itself\\nDELETE FROM collections WHERE id = 'blog-posts-collection';\\n\\n-- The blog-posts collection will now be managed by the code-based collection\\n-- in src/collections/blog-posts.collection.ts\\n\"\n },\n {\n id: '020',\n name: 'Add Email Plugin',\n filename: '020_add_email_plugin.sql',\n description: 'Migration 020: Add Email Plugin',\n sql: \"-- Add Email Plugin\\n-- Migration: 020_add_email_plugin\\n-- Description: Add email plugin for transactional emails via Resend\\n\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, installed_at, last_updated\\n) VALUES (\\n 'email',\\n 'email',\\n 'Email',\\n 'Send transactional emails using Resend',\\n '1.0.0-beta.1',\\n 'SonicJS Team',\\n 'communication',\\n '📧',\\n 'inactive',\\n TRUE,\\n '[\\\"email:manage\\\", \\\"email:send\\\", \\\"email:view-logs\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n },\n {\n id: '021',\n name: 'Add Magic Link Auth Plugin',\n filename: '021_add_magic_link_auth_plugin.sql',\n description: 'Migration 021: Add Magic Link Auth Plugin',\n sql: \"-- Add Magic Link Authentication Plugin\\n-- Migration: 021_add_magic_link_auth_plugin\\n-- Description: Add magic link authentication plugin for passwordless login\\n\\n-- Create magic_links table\\nCREATE TABLE IF NOT EXISTS magic_links (\\n id TEXT PRIMARY KEY,\\n user_email TEXT NOT NULL,\\n token TEXT NOT NULL UNIQUE,\\n expires_at INTEGER NOT NULL,\\n used INTEGER DEFAULT 0,\\n used_at INTEGER,\\n ip_address TEXT,\\n user_agent TEXT,\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Create indexes for performance\\nCREATE INDEX IF NOT EXISTS idx_magic_links_token ON magic_links(token);\\nCREATE INDEX IF NOT EXISTS idx_magic_links_email ON magic_links(user_email);\\nCREATE INDEX IF NOT EXISTS idx_magic_links_expires ON magic_links(expires_at);\\n\\n-- Register the plugin\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, installed_at, last_updated\\n) VALUES (\\n 'magic-link-auth',\\n 'magic-link-auth',\\n 'Magic Link Authentication',\\n 'Passwordless authentication via email magic links. Users receive a secure one-time link to sign in without entering a password.',\\n '1.0.0',\\n 'SonicJS Team',\\n 'security',\\n '🔗',\\n 'inactive',\\n FALSE,\\n '[\\\"auth:manage\\\", \\\"auth:magic-link\\\"]',\\n '[\\\"email\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n },\n {\n id: '022',\n name: 'Add Tinymce Plugin',\n filename: '022_add_tinymce_plugin.sql',\n description: 'Migration 022: Add Tinymce Plugin',\n sql: \"-- Add TinyMCE Rich Text Editor Plugin\\n-- Migration: 022_add_tinymce_plugin\\n-- Description: Add TinyMCE plugin for WYSIWYG rich text editing\\n\\n-- Register the plugin (active by default since it replaces hardcoded TinyMCE)\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, settings, installed_at, last_updated\\n) VALUES (\\n 'tinymce-plugin',\\n 'tinymce-plugin',\\n 'TinyMCE Rich Text Editor',\\n 'Powerful WYSIWYG rich text editor for content creation. Provides a full-featured editor with formatting, media embedding, and customizable toolbars for richtext fields.',\\n '1.0.0',\\n 'SonicJS Team',\\n 'editor',\\n '✏️',\\n 'active',\\n FALSE,\\n '[]',\\n '[]',\\n '{\\\"apiKey\\\":\\\"no-api-key\\\",\\\"defaultHeight\\\":300,\\\"defaultToolbar\\\":\\\"full\\\",\\\"skin\\\":\\\"oxide-dark\\\"}',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n },\n {\n id: '023',\n name: 'Add Easy Mdx Plugin',\n filename: '023_add_easy_mdx_plugin.sql',\n description: 'Migration 023: Add Easy Mdx Plugin',\n sql: \"-- Add EasyMDE Markdown Editor Plugin\\n-- Migration: 023_add_easy_mdx_plugin\\n-- Description: Add EasyMDE plugin for lightweight markdown editing\\n\\n-- Register the plugin (active by default)\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, settings, installed_at, last_updated\\n) VALUES (\\n 'easy-mdx',\\n 'easy-mdx',\\n 'EasyMDE Markdown Editor',\\n 'Lightweight markdown editor with live preview. Provides a simple and efficient editor with markdown support for richtext fields.',\\n '1.0.0',\\n 'SonicJS Team',\\n 'editor',\\n '📝',\\n 'active',\\n FALSE,\\n '[]',\\n '[]',\\n '{\\\"defaultHeight\\\":400,\\\"theme\\\":\\\"dark\\\",\\\"toolbar\\\":\\\"full\\\",\\\"placeholder\\\":\\\"Start writing your content...\\\"}',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n },\n {\n id: '024',\n name: 'Add Quill Editor Plugin',\n filename: '024_add_quill_editor_plugin.sql',\n description: 'Migration 024: Add Quill Editor Plugin',\n sql: \"-- Add Quill Rich Text Editor Plugin\\n-- Migration: 024_add_quill_editor_plugin\\n-- Description: Add Quill plugin for modern rich text editing\\n\\n-- Register the plugin (active by default)\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, dependencies, settings, installed_at, last_updated\\n) VALUES (\\n 'quill-editor',\\n 'quill-editor',\\n 'Quill Rich Text Editor',\\n 'Modern rich text editor for content creation. Provides a clean, intuitive WYSIWYG editor with customizable toolbars for richtext fields.',\\n '1.0.0',\\n 'SonicJS Team',\\n 'editor',\\n '✍️',\\n 'active',\\n FALSE,\\n '[]',\\n '[]',\\n '{\\\"theme\\\":\\\"snow\\\",\\\"defaultHeight\\\":300,\\\"defaultToolbar\\\":\\\"full\\\",\\\"placeholder\\\":\\\"Start writing your content...\\\"}',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n },\n {\n id: '025',\n name: 'Rename Mdxeditor To Easy Mdx',\n filename: '025_rename_mdxeditor_to_easy_mdx.sql',\n description: 'Migration 025: Rename Mdxeditor To Easy Mdx',\n sql: \"-- Rename mdxeditor-plugin to easy-mdx\\n-- Migration: 025_rename_mdxeditor_to_easy_mdx\\n-- Description: Update plugin ID from mdxeditor-plugin to easy-mdx to reflect the change to EasyMDE editor\\n\\n-- Update the plugin record if it exists with the old ID\\nUPDATE plugins\\nSET\\n id = 'easy-mdx',\\n name = 'easy-mdx',\\n display_name = 'EasyMDE Markdown Editor',\\n description = 'Lightweight markdown editor with live preview. Provides a simple and efficient editor with markdown support for richtext fields.'\\nWHERE id = 'mdxeditor-plugin';\\n\\n-- Update any plugin_hooks references\\nUPDATE plugin_hooks\\nSET plugin_id = 'easy-mdx'\\nWHERE plugin_id = 'mdxeditor-plugin';\\n\\n-- Update any plugin_activity_log references\\nUPDATE plugin_activity_log\\nSET plugin_id = 'easy-mdx'\\nWHERE plugin_id = 'mdxeditor-plugin';\\n\"\n },\n {\n id: '026',\n name: 'Add Otp Login',\n filename: '026_add_otp_login.sql',\n description: 'Migration 026: Add Otp Login',\n sql: \"-- Add OTP Login Plugin\\n-- Migration: 021_add_otp_login\\n-- Description: Add OTP login plugin for passwordless authentication via email codes\\n\\n-- Create table for OTP codes\\nCREATE TABLE IF NOT EXISTS otp_codes (\\n id TEXT PRIMARY KEY,\\n user_email TEXT NOT NULL,\\n code TEXT NOT NULL,\\n expires_at INTEGER NOT NULL,\\n used INTEGER DEFAULT 0,\\n used_at INTEGER,\\n ip_address TEXT,\\n user_agent TEXT,\\n attempts INTEGER DEFAULT 0,\\n created_at INTEGER NOT NULL\\n);\\n\\n-- Create indexes for performance\\nCREATE INDEX IF NOT EXISTS idx_otp_email_code ON otp_codes(user_email, code);\\nCREATE INDEX IF NOT EXISTS idx_otp_expires ON otp_codes(expires_at);\\nCREATE INDEX IF NOT EXISTS idx_otp_used ON otp_codes(used);\\n\\n-- Add plugin record\\nINSERT OR IGNORE INTO plugins (\\n id, name, display_name, description, version, author, category, icon,\\n status, is_core, permissions, installed_at, last_updated\\n) VALUES (\\n 'otp-login',\\n 'otp-login',\\n 'OTP Login',\\n 'Passwordless authentication via email one-time codes',\\n '1.0.0-beta.1',\\n 'SonicJS Team',\\n 'authentication',\\n '🔢',\\n 'inactive',\\n TRUE,\\n '[\\\"otp:manage\\\", \\\"otp:request\\\", \\\"otp:verify\\\"]',\\n unixepoch(),\\n unixepoch()\\n);\\n\"\n }\n]\n\n// Map for quick lookup by ID\nexport const migrationsByIdMap = new Map<string, BundledMigration>(\n bundledMigrations.map(m => [m.id, m])\n)\n\n// Get migration SQL by ID\nexport function getMigrationSQLById(id: string): string | null {\n return migrationsByIdMap.get(id)?.sql ?? null\n}\n\n// Get all migration info (without SQL for lighter payloads)\nexport function getMigrationList(): Array<Omit<BundledMigration, 'sql'>> {\n return bundledMigrations.map(({ sql, ...rest }) => rest)\n}\n","import { D1Database } from '@cloudflare/workers-types'\nimport { bundledMigrations, getMigrationSQLById, type BundledMigration } from '../db/migrations-bundle'\n\nexport interface Migration {\n id: string\n name: string\n filename: string\n description?: string\n applied: boolean\n appliedAt?: string\n size?: number\n}\n\nexport interface MigrationStatus {\n totalMigrations: number\n appliedMigrations: number\n pendingMigrations: number\n lastApplied?: string\n migrations: Migration[]\n}\n\nexport class MigrationService {\n constructor(private db: D1Database) {}\n\n /**\n * Initialize the migrations tracking table\n */\n async initializeMigrationsTable(): Promise<void> {\n const createTableQuery = `\n CREATE TABLE IF NOT EXISTS migrations (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n filename TEXT NOT NULL,\n applied_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n checksum TEXT\n )\n `\n\n await this.db.prepare(createTableQuery).run()\n }\n\n /**\n * Get all available migrations from the bundled migrations\n */\n async getAvailableMigrations(): Promise<Migration[]> {\n const migrations: Migration[] = []\n\n // Get applied migrations from database\n const appliedResult = await this.db.prepare(\n 'SELECT id, name, filename, applied_at FROM migrations ORDER BY applied_at ASC'\n ).all()\n\n const appliedMigrations = new Map(\n appliedResult.results?.map((row: any) => [row.id, row]) || []\n )\n\n // Auto-detect applied migrations by checking if their tables exist\n await this.autoDetectAppliedMigrations(appliedMigrations)\n\n // Use bundled migrations as the source of truth\n for (const bundled of bundledMigrations) {\n const applied = appliedMigrations.has(bundled.id)\n const appliedData = appliedMigrations.get(bundled.id)\n\n migrations.push({\n id: bundled.id,\n name: bundled.name,\n filename: bundled.filename,\n description: bundled.description,\n applied,\n appliedAt: applied ? appliedData?.applied_at : undefined,\n size: bundled.sql.length\n })\n }\n\n return migrations\n }\n\n /**\n * Auto-detect applied migrations by checking if their tables exist\n */\n private async autoDetectAppliedMigrations(appliedMigrations: Map<string, any>): Promise<void> {\n // Check if basic schema tables exist (migration 001)\n if (!appliedMigrations.has('001')) {\n const hasBasicTables = await this.checkTablesExist(['users', 'content', 'collections', 'media'])\n if (hasBasicTables) {\n appliedMigrations.set('001', {\n id: '001',\n applied_at: new Date().toISOString(),\n name: 'Initial Schema',\n filename: '001_initial_schema.sql'\n })\n await this.markMigrationApplied('001', 'Initial Schema', '001_initial_schema.sql')\n }\n }\n\n // Check if FAQ tables exist (migration 002)\n // Migration 002 creates only the 'faqs' table\n if (!appliedMigrations.has('002')) {\n const hasFaqTables = await this.checkTablesExist(['faqs'])\n if (hasFaqTables) {\n appliedMigrations.set('002', {\n id: '002',\n applied_at: new Date().toISOString(),\n name: 'Faq Plugin',\n filename: '002_faq_plugin.sql'\n })\n await this.markMigrationApplied('002', 'Faq Plugin', '002_faq_plugin.sql')\n }\n }\n\n // Check if stage 5 enhancement tables exist (migration 003)\n // Migration 003 creates content_fields, content_relationships, workflow_templates tables\n if (!appliedMigrations.has('003')) {\n const hasStage5Tables = await this.checkTablesExist(['content_fields', 'content_relationships', 'workflow_templates'])\n if (hasStage5Tables) {\n appliedMigrations.set('003', {\n id: '003',\n applied_at: new Date().toISOString(),\n name: 'Stage 5 Enhancements',\n filename: '003_stage5_enhancements.sql'\n })\n await this.markMigrationApplied('003', 'Stage 5 Enhancements', '003_stage5_enhancements.sql')\n }\n }\n\n // Check if testimonials table exists (migration 012)\n if (!appliedMigrations.has('012')) {\n const hasTestimonialsTables = await this.checkTablesExist(['testimonials'])\n if (hasTestimonialsTables) {\n appliedMigrations.set('012', {\n id: '012',\n applied_at: new Date().toISOString(),\n name: 'Testimonials Plugin',\n filename: '012_testimonials_plugin.sql'\n })\n await this.markMigrationApplied('012', 'Testimonials Plugin', '012_testimonials_plugin.sql')\n }\n }\n\n // Check if code_examples table exists (migration 013)\n if (!appliedMigrations.has('013')) {\n const hasCodeExamplesTables = await this.checkTablesExist(['code_examples'])\n if (hasCodeExamplesTables) {\n appliedMigrations.set('013', {\n id: '013',\n applied_at: new Date().toISOString(),\n name: 'Code Examples Plugin',\n filename: '013_code_examples_plugin.sql'\n })\n await this.markMigrationApplied('013', 'Code Examples Plugin', '013_code_examples_plugin.sql')\n }\n }\n\n // Check if user management tables exist (migration 004)\n if (!appliedMigrations.has('004')) {\n const hasUserTables = await this.checkTablesExist(['api_tokens', 'workflow_history'])\n if (hasUserTables) {\n appliedMigrations.set('004', {\n id: '004',\n applied_at: new Date().toISOString(),\n name: 'User Management',\n filename: '004_stage6_user_management.sql'\n })\n await this.markMigrationApplied('004', 'User Management', '004_stage6_user_management.sql')\n }\n }\n\n // Check if plugin system tables exist (migration 006)\n if (!appliedMigrations.has('006')) {\n const hasPluginTables = await this.checkTablesExist(['plugins', 'plugin_hooks'])\n if (hasPluginTables) {\n appliedMigrations.set('006', {\n id: '006',\n applied_at: new Date().toISOString(),\n name: 'Plugin System',\n filename: '006_plugin_system.sql'\n })\n await this.markMigrationApplied('006', 'Plugin System', '006_plugin_system.sql')\n }\n }\n\n // Check if managed column exists (migration 011)\n // This handles both cases:\n // 1. Migration not marked as applied but column exists -> mark as applied\n // 2. Migration marked as applied but column doesn't exist -> remove from applied (will re-run)\n const hasManagedColumn = await this.checkColumnExists('collections', 'managed')\n if (!appliedMigrations.has('011') && hasManagedColumn) {\n appliedMigrations.set('011', {\n id: '011',\n applied_at: new Date().toISOString(),\n name: 'Config Managed Collections',\n filename: '011_config_managed_collections.sql'\n })\n await this.markMigrationApplied('011', 'Config Managed Collections', '011_config_managed_collections.sql')\n } else if (appliedMigrations.has('011') && !hasManagedColumn) {\n // Migration was marked as applied but column doesn't exist - remove it so it will re-run\n console.log('[Migration] Migration 011 marked as applied but managed column missing - will re-run')\n appliedMigrations.delete('011')\n await this.removeMigrationApplied('011')\n }\n\n // Check if system_logs table exists (migration 009)\n if (!appliedMigrations.has('009')) {\n const hasLoggingTables = await this.checkTablesExist(['system_logs', 'log_config'])\n if (hasLoggingTables) {\n appliedMigrations.set('009', {\n id: '009',\n applied_at: new Date().toISOString(),\n name: 'System Logging',\n filename: '009_system_logging.sql'\n })\n await this.markMigrationApplied('009', 'System Logging', '009_system_logging.sql')\n }\n }\n\n // Check if settings table exists (migration 018)\n if (!appliedMigrations.has('018')) {\n const hasSettingsTable = await this.checkTablesExist(['settings'])\n if (hasSettingsTable) {\n appliedMigrations.set('018', {\n id: '018',\n applied_at: new Date().toISOString(),\n name: 'Settings Table',\n filename: '018_settings_table.sql'\n })\n await this.markMigrationApplied('018', 'Settings Table', '018_settings_table.sql')\n }\n }\n }\n\n /**\n * Check if specific tables exist in the database\n */\n private async checkTablesExist(tableNames: string[]): Promise<boolean> {\n try {\n for (const tableName of tableNames) {\n const result = await this.db.prepare(\n `SELECT name FROM sqlite_master WHERE type='table' AND name=?`\n ).bind(tableName).first()\n\n if (!result) {\n return false\n }\n }\n return true\n } catch (error) {\n return false\n }\n }\n\n /**\n * Check if a specific column exists in a table\n */\n private async checkColumnExists(tableName: string, columnName: string): Promise<boolean> {\n try {\n const result = await this.db.prepare(\n `SELECT * FROM pragma_table_info(?) WHERE name = ?`\n ).bind(tableName, columnName).first()\n\n return !!result\n } catch (error) {\n return false\n }\n }\n\n /**\n * Get migration status summary\n */\n async getMigrationStatus(): Promise<MigrationStatus> {\n await this.initializeMigrationsTable()\n\n const migrations = await this.getAvailableMigrations()\n const appliedMigrations = migrations.filter(m => m.applied)\n const pendingMigrations = migrations.filter(m => !m.applied)\n\n const lastApplied = appliedMigrations.length > 0\n ? appliedMigrations[appliedMigrations.length - 1]?.appliedAt\n : undefined\n\n return {\n totalMigrations: migrations.length,\n appliedMigrations: appliedMigrations.length,\n pendingMigrations: pendingMigrations.length,\n lastApplied,\n migrations\n }\n }\n\n /**\n * Mark a migration as applied\n */\n async markMigrationApplied(migrationId: string, name: string, filename: string): Promise<void> {\n await this.initializeMigrationsTable()\n\n await this.db.prepare(\n 'INSERT OR REPLACE INTO migrations (id, name, filename, applied_at) VALUES (?, ?, ?, CURRENT_TIMESTAMP)'\n ).bind(migrationId, name, filename).run()\n }\n\n /**\n * Remove a migration from the applied list (so it can be re-run)\n */\n async removeMigrationApplied(migrationId: string): Promise<void> {\n await this.initializeMigrationsTable()\n\n await this.db.prepare(\n 'DELETE FROM migrations WHERE id = ?'\n ).bind(migrationId).run()\n }\n\n /**\n * Check if a specific migration has been applied\n */\n async isMigrationApplied(migrationId: string): Promise<boolean> {\n await this.initializeMigrationsTable()\n\n const result = await this.db.prepare(\n 'SELECT COUNT(*) as count FROM migrations WHERE id = ?'\n ).bind(migrationId).first()\n\n return (result?.count as number) > 0\n }\n\n /**\n * Get the last applied migration\n */\n async getLastAppliedMigration(): Promise<Migration | null> {\n await this.initializeMigrationsTable()\n\n const result = await this.db.prepare(\n 'SELECT id, name, filename, applied_at FROM migrations ORDER BY applied_at DESC LIMIT 1'\n ).first()\n\n if (!result) return null\n\n return {\n id: result.id as string,\n name: result.name as string,\n filename: result.filename as string,\n applied: true,\n appliedAt: result.applied_at as string\n }\n }\n\n /**\n * Run pending migrations\n */\n async runPendingMigrations(): Promise<{ success: boolean; message: string; applied: string[] }> {\n await this.initializeMigrationsTable()\n\n const status = await this.getMigrationStatus()\n const pendingMigrations = status.migrations.filter(m => !m.applied)\n\n if (pendingMigrations.length === 0) {\n return {\n success: true,\n message: 'All migrations are up to date',\n applied: []\n }\n }\n\n // Actually execute the migration files\n const applied: string[] = []\n const errors: string[] = []\n\n for (const migration of pendingMigrations) {\n try {\n console.log(`[Migration] Applying ${migration.id}: ${migration.name}`)\n await this.applyMigration(migration)\n await this.markMigrationApplied(migration.id, migration.name, migration.filename)\n applied.push(migration.id)\n console.log(`[Migration] Successfully applied ${migration.id}`)\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n console.error(`[Migration] Failed to apply migration ${migration.id}:`, errorMessage)\n errors.push(`${migration.id}: ${errorMessage}`)\n // Continue with other migrations instead of stopping on first failure\n // This allows independent migrations to still be applied\n }\n }\n\n if (errors.length > 0 && applied.length === 0) {\n return {\n success: false,\n message: `Failed to apply migrations: ${errors.join('; ')}`,\n applied\n }\n }\n\n return {\n success: true,\n message: applied.length > 0\n ? `Applied ${applied.length} migration(s)${errors.length > 0 ? ` (${errors.length} failed)` : ''}`\n : 'No migrations applied',\n applied\n }\n }\n\n /**\n * Apply a specific migration\n */\n private async applyMigration(migration: Migration): Promise<void> {\n // Get the actual migration SQL from the bundle\n const migrationSQL = getMigrationSQLById(migration.id)\n\n if (migrationSQL === null) {\n throw new Error(`Migration SQL not found for ${migration.id}`)\n }\n\n if (migrationSQL.trim() === '') {\n console.log(`[Migration] Skipping empty migration ${migration.id}`)\n return\n }\n\n // Split SQL into individual statements, handling triggers properly\n const statements = this.splitSQLStatements(migrationSQL)\n\n for (const statement of statements) {\n if (statement.trim()) {\n try {\n await this.db.prepare(statement).run()\n } catch (error) {\n // Check if it's a \"already exists\" type error and skip it\n const errorMessage = error instanceof Error ? error.message : String(error)\n if (errorMessage.includes('already exists') ||\n errorMessage.includes('duplicate column name') ||\n errorMessage.includes('UNIQUE constraint failed')) {\n console.log(`[Migration] Skipping (already exists): ${statement.substring(0, 50)}...`)\n continue\n }\n console.error(`[Migration] Error executing statement: ${statement.substring(0, 100)}...`)\n throw error\n }\n }\n }\n }\n\n /**\n * Split SQL into statements, handling CREATE TRIGGER properly\n */\n private splitSQLStatements(sql: string): string[] {\n const statements: string[] = []\n let current = ''\n let inTrigger = false\n\n const lines = sql.split('\\n')\n\n for (const line of lines) {\n const trimmed = line.trim()\n\n // Skip comments and empty lines\n if (trimmed.startsWith('--') || trimmed.length === 0) {\n continue\n }\n\n // Check if we're entering a trigger\n if (trimmed.toUpperCase().includes('CREATE TRIGGER')) {\n inTrigger = true\n }\n\n current += line + '\\n'\n\n // Check if we're exiting a trigger\n if (inTrigger && trimmed.toUpperCase() === 'END;') {\n statements.push(current.trim())\n current = ''\n inTrigger = false\n }\n // Check for regular statement end (not in trigger)\n else if (!inTrigger && trimmed.endsWith(';')) {\n statements.push(current.trim())\n current = ''\n }\n }\n\n // Add any remaining statement\n if (current.trim()) {\n statements.push(current.trim())\n }\n\n return statements.filter(s => s.length > 0)\n }\n\n /**\n * Validate database schema\n */\n async validateSchema(): Promise<{ valid: boolean; issues: string[] }> {\n const issues: string[] = []\n\n // Basic table existence checks\n const requiredTables = [\n 'users', 'content', 'collections', 'media'\n ]\n\n for (const table of requiredTables) {\n try {\n await this.db.prepare(`SELECT COUNT(*) FROM ${table} LIMIT 1`).first()\n } catch (error) {\n issues.push(`Missing table: ${table}`)\n }\n }\n\n // Check for managed column in collections\n const hasManagedColumn = await this.checkColumnExists('collections', 'managed')\n if (!hasManagedColumn) {\n issues.push('Missing column: collections.managed')\n }\n\n return {\n valid: issues.length === 0,\n issues\n }\n }\n}\n"]}