UNPKG

carthorse

Version:

A geospatial trail data processing pipeline for building 3D trail databases with elevation data

157 lines • 6.65 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.SchemaVersionChecker = void 0; exports.checkSchemaVersions = checkSchemaVersions; const better_sqlite3_1 = __importDefault(require("better-sqlite3")); const fs = __importStar(require("fs")); class SchemaVersionChecker { /** * Check schema version for SpatiaLite database */ checkSpatiaLiteVersion(filePath) { if (!fs.existsSync(filePath)) { throw new Error(`SpatiaLite database file not found: ${filePath}`); } const db = new better_sqlite3_1.default(filePath, { readonly: true }); try { const result = db.prepare(` SELECT version, description, applied_at FROM schema_version ORDER BY version DESC LIMIT 1 `).get(); if (!result) { throw new Error('No schema version found in SpatiaLite database'); } return { version: result.version, description: result.description, applied_at: result.applied_at }; } finally { db.close(); } } /** * Get expected schema version for current application */ getExpectedSchemaVersion() { // This should match the version in the orchestrator return { version: 14, description: 'Carthorse SQLite Export v14.0 (Enhanced Route Recommendations + Trail Composition)' }; } /** * Validate that a SpatiaLite database has the expected schema version */ validateSpatiaLiteSchema(filePath) { const expected = this.getExpectedSchemaVersion(); try { const actualVersion = this.checkSpatiaLiteVersion(filePath); const valid = actualVersion.version === expected.version; const message = valid ? `āœ… SpatiaLite schema version is correct: ${actualVersion.version}` : `āŒ SpatiaLite schema version mismatch. Expected: ${expected.version}, Actual: ${actualVersion.version}`; return { valid, message, actualVersion }; } catch (error) { return { valid: false, message: `āŒ Failed to check SpatiaLite schema version: ${error instanceof Error ? error.message : 'Unknown error'}` }; } } /** * Print comprehensive schema version information for all databases */ async printSchemaInfo() { const expected = this.getExpectedSchemaVersion(); console.log(`\nšŸŽÆ Expected Schema Version: ${expected.version}`); console.log(`šŸ“ Description: ${expected.description}`); console.log('='.repeat(80)); // Check all existing databases in data/ directory const dataDir = 'data'; if (fs.existsSync(dataDir)) { const files = fs.readdirSync(dataDir); const dbFiles = files.filter(file => file.endsWith('.db')); if (dbFiles.length > 0) { console.log('\nšŸ“Š Existing SpatiaLite Databases:'); for (const dbFile of dbFiles) { const dbPath = `${dataDir}/${dbFile}`; console.log(`\n šŸ“ ${dbFile}:`); try { const validation = this.validateSpatiaLiteSchema(dbPath); console.log(` ${validation.message}`); if (validation.actualVersion) { console.log(` Version: ${validation.actualVersion.version}`); if (validation.actualVersion.description) { console.log(` Description: ${validation.actualVersion.description}`); } if (validation.actualVersion.applied_at) { console.log(` Applied: ${validation.actualVersion.applied_at}`); } } } catch (error) { console.log(` āŒ Error: ${error instanceof Error ? error.message : 'Unknown error'}`); } } } else { console.log('\nšŸ“Š SpatiaLite Databases: ā­ļø No .db files found in data/ directory'); } } // Summary console.log('\n' + '='.repeat(80)); console.log('šŸ“‹ SCHEMA VERSION SUMMARY:'); console.log(` Expected Version: ${expected.version}`); console.log(' Status: Check individual databases above for compatibility'); console.log(' Recommendation: Ensure all databases match expected version before running tests'); } } exports.SchemaVersionChecker = SchemaVersionChecker; exports.default = SchemaVersionChecker; // CLI utility for checking schema versions async function checkSchemaVersions() { const checker = new SchemaVersionChecker(); await checker.printSchemaInfo(); } //# sourceMappingURL=schema-version-checker.js.map