@sonicjs-cms/core 2.0.10 → 2.0.11

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 (67) hide show
  1. package/dist/{chunk-LW33AOBF.js → chunk-5RKQB2JG.js} +6 -222
  2. package/dist/chunk-5RKQB2JG.js.map +1 -0
  3. package/dist/chunk-AMSTLQFI.cjs +801 -0
  4. package/dist/chunk-AMSTLQFI.cjs.map +1 -0
  5. package/dist/{chunk-Z4H6DBVF.js → chunk-CLLJFZ5U.js} +1965 -1043
  6. package/dist/chunk-CLLJFZ5U.js.map +1 -0
  7. package/dist/{chunk-MXJJN4IA.js → chunk-DU7JJZN7.js} +5 -4
  8. package/dist/chunk-DU7JJZN7.js.map +1 -0
  9. package/dist/{chunk-YHG45LMU.js → chunk-FYWJMETG.js} +20 -4
  10. package/dist/chunk-FYWJMETG.js.map +1 -0
  11. package/dist/chunk-I5ZPYKNX.js +787 -0
  12. package/dist/chunk-I5ZPYKNX.js.map +1 -0
  13. package/dist/{chunk-Q7SL7U43.cjs → chunk-IM2LGCYD.cjs} +2114 -1192
  14. package/dist/chunk-IM2LGCYD.cjs.map +1 -0
  15. package/dist/{chunk-3PHG75W4.cjs → chunk-NNXPAPUD.cjs} +5 -4
  16. package/dist/chunk-NNXPAPUD.cjs.map +1 -0
  17. package/dist/{chunk-FTMKKKNH.js → chunk-QNWYQZ55.js} +3 -3
  18. package/dist/{chunk-FTMKKKNH.js.map → chunk-QNWYQZ55.js.map} +1 -1
  19. package/dist/{chunk-COBUPOMD.js → chunk-T7IYBGGO.cjs} +5 -770
  20. package/dist/chunk-T7IYBGGO.cjs.map +1 -0
  21. package/dist/{chunk-HXA5QSI3.cjs → chunk-X2VADBA4.cjs} +22 -6
  22. package/dist/chunk-X2VADBA4.cjs.map +1 -0
  23. package/dist/{chunk-MU3MR2QR.cjs → chunk-YU6QFFI4.cjs} +5 -222
  24. package/dist/chunk-YU6QFFI4.cjs.map +1 -0
  25. package/dist/{chunk-CAP6QQR2.cjs → chunk-ZMSYKV62.cjs} +5 -5
  26. package/dist/{chunk-CAP6QQR2.cjs.map → chunk-ZMSYKV62.cjs.map} +1 -1
  27. package/dist/{chunk-NBDPIRQS.cjs → chunk-ZPMFT2JW.js} +4 -786
  28. package/dist/chunk-ZPMFT2JW.js.map +1 -0
  29. package/dist/index.cjs +475 -104
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.js +385 -10
  32. package/dist/index.js.map +1 -1
  33. package/dist/middleware.cjs +24 -23
  34. package/dist/middleware.js +3 -2
  35. package/dist/migrations-IHERIQVD.js +4 -0
  36. package/dist/migrations-IHERIQVD.js.map +1 -0
  37. package/dist/migrations-POFD5KNG.cjs +13 -0
  38. package/dist/migrations-POFD5KNG.cjs.map +1 -0
  39. package/dist/routes.cjs +25 -28
  40. package/dist/routes.js +6 -5
  41. package/dist/services.cjs +19 -18
  42. package/dist/services.js +2 -1
  43. package/dist/templates.cjs +17 -21
  44. package/dist/templates.js +2 -2
  45. package/dist/utils.cjs +11 -11
  46. package/dist/utils.js +1 -1
  47. package/migrations/001_initial_schema.sql +2 -2
  48. package/migrations/007_demo_login_plugin.sql +1 -1
  49. package/migrations/020_add_email_plugin.sql +22 -0
  50. package/migrations/021_add_magic_link_auth_plugin.sql +42 -0
  51. package/migrations/021_add_otp_login.sql +42 -0
  52. package/migrations/022_add_tinymce_plugin.sql +25 -0
  53. package/migrations/023_add_mdxeditor_plugin.sql +25 -0
  54. package/migrations/024_add_quill_editor_plugin.sql +25 -0
  55. package/migrations/025_add_easymde_plugin.sql +25 -0
  56. package/package.json +3 -2
  57. package/dist/chunk-3PHG75W4.cjs.map +0 -1
  58. package/dist/chunk-COBUPOMD.js.map +0 -1
  59. package/dist/chunk-HXA5QSI3.cjs.map +0 -1
  60. package/dist/chunk-LW33AOBF.js.map +0 -1
  61. package/dist/chunk-MU3MR2QR.cjs.map +0 -1
  62. package/dist/chunk-MXJJN4IA.js.map +0 -1
  63. package/dist/chunk-NBDPIRQS.cjs.map +0 -1
  64. package/dist/chunk-Q7SL7U43.cjs.map +0 -1
  65. package/dist/chunk-YHG45LMU.js.map +0 -1
  66. package/dist/chunk-Z4H6DBVF.js.map +0 -1
  67. package/migrations/002_faq_plugin.sql +0 -86
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/services/migrations.ts"],"names":[],"mappings":";AAsBO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,YAAoB,EAAA,EAAgB;AAAhB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AAAA,EAAiB;AAAA;AAAA;AAAA;AAAA,EAKrC,MAAM,yBAAA,GAA2C;AAC/C,IAAA,MAAM,gBAAA,GAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA;AAUzB,IAAA,MAAM,IAAA,CAAK,EAAA,CAAG,OAAA,CAAQ,gBAAgB,EAAE,GAAA,EAAI;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,sBAAA,GAA+C;AACnD,IAAA,MAAM,aAA0B,EAAC;AAIjC,IAAA,MAAM,cAAA,GAAiB;AAAA,MACrB,EAAE,IAAI,KAAA,EAAO,IAAA,EAAM,kBAAkB,QAAA,EAAU,wBAAA,EAA0B,aAAa,4EAAA,EAA6E;AAAA,MACnK,EAAE,IAAI,KAAA,EAAO,IAAA,EAAM,cAAc,QAAA,EAAU,oBAAA,EAAsB,aAAa,oCAAA,EAAqC;AAAA,MACnH,EAAE,IAAI,KAAA,EAAO,IAAA,EAAM,wBAAwB,QAAA,EAAU,6BAAA,EAA+B,aAAa,gDAAA,EAAiD;AAAA,MAClJ,EAAE,IAAI,KAAA,EAAO,IAAA,EAAM,mBAAmB,QAAA,EAAU,gCAAA,EAAkC,aAAa,qDAAA,EAAsD;AAAA,MACrJ,EAAE,IAAI,KAAA,EAAO,IAAA,EAAM,yBAAyB,QAAA,EAAU,oCAAA,EAAsC,aAAa,0DAAA,EAA2D;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;AAClC,MAAA,IAAI;AACF,QAAA,MAAM,KAAK,EAAA,CAAG,OAAA,CAAQ,wBAAwB,KAAK,CAAA,QAAA,CAAU,EAAE,KAAA,EAAM;AAAA,MACvE,SAAS,KAAA,EAAO;AACd,QAAA,MAAA,CAAO,IAAA,CAAK,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAE,CAAA;AAAA,MACvC;AAAA,IACF;AAEA,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,OAAO,MAAA,KAAW,CAAA;AAAA,MACzB;AAAA,KACF;AAAA,EACF;AACF","file":"chunk-ZPMFT2JW.js","sourcesContent":["import { D1Database } from '@cloudflare/workers-types'\n// Note: fs and path are not available in Cloudflare Workers\n// Migration files should be bundled with the application\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 migrations directory\n */\n async getAvailableMigrations(): Promise<Migration[]> {\n const migrations: Migration[] = []\n \n // In a real implementation, this would read from the migrations directory\n // For now, we'll use a hardcoded list based on the existing migrations\n const migrationFiles = [\n { id: '001', name: 'Initial Schema', filename: '001_initial_schema.sql', description: 'Initial database schema with users, content, collections, and media tables' },\n { id: '002', name: 'FAQ Plugin', filename: '002_faq_plugin.sql', description: 'FAQ plugin tables and initial data' },\n { id: '003', name: 'Stage 5 Enhancements', filename: '003_stage5_enhancements.sql', description: 'Enhanced content management and media handling' },\n { id: '004', name: 'User Management', filename: '004_stage6_user_management.sql', description: 'Advanced user management with roles and permissions' },\n { id: '005', name: 'Workflow & Automation', filename: '005_stage7_workflow_automation.sql', description: 'Workflow states, automation rules, and scheduled content' },\n { id: '006', name: 'Plugin System', filename: '006_plugin_system.sql', description: 'Plugin registration and configuration system' },\n { id: '007', name: 'Demo Login Plugin', filename: '007_demo_login_plugin.sql', description: 'Demo login functionality' },\n { id: '008', name: 'Fix Slug Validation', filename: '008_fix_slug_validation.sql', description: 'Fix slug validation in content' },\n { id: '009', name: 'System Logging', filename: '009_system_logging.sql', description: 'System logging and audit trails' },\n { id: '011', name: 'Config Managed Collections', filename: '011_config_managed_collections.sql', description: 'Configuration for managed collections' },\n { id: '012', name: 'Testimonials Plugin', filename: '012_testimonials_plugin.sql', description: 'Testimonials plugin and collection' },\n { id: '013', name: 'Code Examples Plugin', filename: '013_code_examples_plugin.sql', description: 'Code examples plugin and collection' },\n { id: '014', name: 'Fix Plugin Registry', filename: '014_fix_plugin_registry.sql', description: 'Fix plugin registry issues' },\n { id: '015', name: 'Add Remaining Plugins', filename: '015_add_remaining_plugins.sql', description: 'Add remaining core plugins' },\n { id: '016', name: 'Remove Duplicate Cache Plugin', filename: '016_remove_duplicate_cache_plugin.sql', description: 'Remove duplicate cache plugin entries' },\n { id: '017', name: 'Auth Configurable Fields', filename: '017_auth_configurable_fields.sql', description: 'Configurable authentication fields' }\n ]\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 // Combine with migration files to create complete status\n for (const file of migrationFiles) {\n const applied = appliedMigrations.has(file.id)\n const appliedData = appliedMigrations.get(file.id)\n \n migrations.push({\n id: file.id,\n name: file.name,\n filename: file.filename,\n description: file.description,\n applied,\n appliedAt: applied ? appliedData?.applied_at : undefined,\n size: await this.getMigrationFileSize(file.filename)\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 // Mark as applied in database\n await this.markMigrationApplied('001', 'Initial Schema', '001_initial_schema.sql')\n }\n }\n\n // Check if FAQ tables exist (migration 002) \n if (!appliedMigrations.has('002')) {\n const hasFaqTables = await this.checkTablesExist(['faqs', 'faq_categories'])\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 enhanced tables exist (migration 003)\n if (!appliedMigrations.has('003')) {\n const hasEnhancedTables = await this.checkTablesExist(['content_versions', 'email_themes', 'email_templates'])\n if (hasEnhancedTables) {\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 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\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 * 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 * 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 * Get migration file size (simulated)\n */\n private async getMigrationFileSize(filename: string): Promise<number> {\n // In a real implementation, this would read the actual file size\n // For now, return a simulated size\n const sizesMap: Record<string, number> = {\n '001_initial_schema.sql': 15420,\n '002_faq_plugin.sql': 2340,\n '003_stage5_enhancements.sql': 8920,\n '004_stage6_user_management.sql': 12680,\n '005_stage7_workflow_automation.sql': 18750,\n '006_plugin_system.sql': 5430\n }\n \n return sizesMap[filename] || 1000\n }\n\n /**\n * Run pending migrations\n */\n async runPendingMigrations(): Promise<{ success: boolean; message: string; applied: string[] }> {\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 \n for (const migration of pendingMigrations) {\n try {\n await this.applyMigration(migration)\n await this.markMigrationApplied(migration.id, migration.name, migration.filename)\n applied.push(migration.id)\n } catch (error) {\n console.error(`Failed to apply migration ${migration.id}:`, error)\n // Stop on first failure\n break\n }\n }\n\n return {\n success: true,\n message: `Applied ${applied.length} migration(s)`,\n applied\n }\n }\n\n /**\n * Apply a specific migration\n */\n private async applyMigration(migration: Migration): Promise<void> {\n console.log(`Applying migration ${migration.id}: ${migration.name}`)\n\n // Get the actual migration SQL\n const migrationSQL = await this.getMigrationSQL(migration.id)\n\n if (migrationSQL === null) {\n throw new Error(`Migration SQL not found for ${migration.id}`)\n }\n\n // Skip empty migrations (migrations that are no longer needed)\n if (migrationSQL === '') {\n console.log(`Skipping migration ${migration.id} (empty/obsolete)`)\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 console.error(`Error executing statement: ${statement}`, error)\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 * Get migration SQL by ID\n */\n private async getMigrationSQL(migrationId: string): Promise<string | null> {\n // Import actual migration SQL based on ID\n switch (migrationId) {\n case '001':\n // Initial schema migration\n return `\n-- 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,\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,\n status TEXT NOT NULL DEFAULT 'draft',\n published_at INTEGER,\n author_id TEXT NOT NULL REFERENCES users(id),\n created_by 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,\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,\n public_url TEXT NOT NULL,\n thumbnail_url TEXT,\n alt TEXT,\n caption TEXT,\n tags TEXT,\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,\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-- Insert default admin user (password: sonicjs!)\nINSERT OR IGNORE INTO users (\n id, email, username, first_name, last_name, password_hash,\n role, is_active, created_at, updated_at\n) VALUES (\n 'admin-user-id',\n 'admin@sonicjs.com',\n 'admin',\n 'Admin',\n 'User',\n 'd1c379e871838f44e21d5a55841349e50636f06df139bfef11870eec74c381db',\n 'admin',\n 1,\n strftime('%s', 'now') * 1000,\n strftime('%s', 'now') * 1000\n);\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-- Insert sample content\nINSERT OR IGNORE INTO content (\n id, collection_id, slug, title, data, status,\n author_id, created_by, created_at, updated_at\n) VALUES (\n 'welcome-blog-post',\n 'blog-posts-collection',\n 'welcome-to-sonicjs-ai',\n 'Welcome to SonicJS AI',\n '{\"title\":\"Welcome to SonicJS AI\",\"content\":\"<h1>Welcome to SonicJS AI</h1><p>This is your first blog post created with SonicJS AI, a modern headless CMS built on Cloudflare Workers.</p><h2>Features</h2><ul><li>Cloudflare-native architecture</li><li>TypeScript-first development</li><li>Hono.js framework</li><li>D1 database</li><li>R2 media storage</li><li>Edge computing</li></ul><p>Get started by exploring the admin interface and creating your own content!</p>\",\"excerpt\":\"Welcome to SonicJS AI, a modern headless CMS built on Cloudflare Workers with TypeScript and Hono.js.\",\"status\":\"published\",\"tags\":[\"welcome\",\"cms\",\"cloudflare\"]}',\n 'published',\n 'admin-user-id',\n 'admin-user-id',\n strftime('%s', 'now') * 1000,\n strftime('%s', 'now') * 1000\n);\n `\n case '002':\n // FAQ Plugin migration\n return `\n CREATE 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 INDEX IF NOT EXISTS idx_faqs_category ON faqs(category);\n CREATE INDEX IF NOT EXISTS idx_faqs_published ON faqs(isPublished);\n CREATE INDEX IF NOT EXISTS idx_faqs_sort_order ON faqs(sortOrder);\n\n CREATE TRIGGER IF NOT EXISTS faqs_updated_at\n AFTER UPDATE ON faqs\n BEGIN\n UPDATE faqs SET updated_at = strftime('%s', 'now') WHERE id = NEW.id;\n END;\n `\n case '006':\n // Plugin system migration\n return `\n -- Plugin System Tables\n CREATE 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 CREATE 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 CREATE 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 CREATE 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 CREATE 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\n CREATE INDEX IF NOT EXISTS idx_plugins_status ON plugins(status);\n CREATE INDEX IF NOT EXISTS idx_plugins_category ON plugins(category);\n CREATE INDEX IF NOT EXISTS idx_plugin_hooks_plugin ON plugin_hooks(plugin_id);\n CREATE INDEX IF NOT EXISTS idx_plugin_routes_plugin ON plugin_routes(plugin_id);\n CREATE INDEX IF NOT EXISTS idx_plugin_assets_plugin ON plugin_assets(plugin_id);\n CREATE INDEX IF NOT EXISTS idx_plugin_activity_plugin ON plugin_activity_log(plugin_id);\n CREATE INDEX IF NOT EXISTS idx_plugin_activity_timestamp ON plugin_activity_log(timestamp);\n\n -- Insert core plugins\n INSERT 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 'cache',\n 'cache',\n 'Cache System',\n 'Three-tiered caching system with memory, KV, and database layers',\n '1.0.0',\n 'SonicJS Team',\n 'performance',\n '⚡',\n 'active',\n TRUE,\n '[\"manage:cache\",\"view:stats\"]',\n unixepoch(),\n unixepoch()\n ),\n (\n 'design',\n 'design-plugin',\n 'Design System',\n 'Design system management including themes, components, and UI customization. Provides a visual interface for managing design tokens, typography, colors, and component library.',\n '1.0.0',\n 'SonicJS',\n 'ui',\n '🎨',\n 'active',\n TRUE,\n '[\"design.view\", \"design.edit\"]',\n unixepoch(),\n unixepoch()\n );\n `\n case '003':\n case '004':\n case '005':\n case '007':\n case '008':\n case '009':\n case '011':\n case '012':\n case '013':\n case '014':\n case '015':\n case '016':\n case '017':\n // These migrations are skipped - either obsolete or have errors\n // Migrations should be run via: wrangler d1 migrations apply DB --local\n return ''\n default:\n return null\n }\n }\n\n /**\n * Validate database schema (placeholder)\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', 'sessions'\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 return {\n valid: issues.length === 0,\n issues\n }\n }\n}"]}