feat: implement Phase 4 - Schema Migration

Completed Phase 4 of the schema-of-schemas implementation with successful
migration of all legacy schemas to the new markdown format following the
naming convention.

Migration Script (scripts/migrate_schemas.py - 240 lines):
- Automated schema migration from JSON to markdown format
- Updates version and $id fields to follow conventions
- Generates proper frontmatter metadata
- Dry-run mode for safe testing
- Database cleanup functionality
- Comprehensive progress reporting

Schemas Migrated (2):
- terminology-schema.json → terminology-schema-v1.0.md
  - Fixed missing version field
  - Updated $id from /terminology-v1.json to /terminology/v1.0
  - Validates successfully against metaschema

- api-documentation → api-documentation-schema-v1.0.md
  - Added version: 1.0.0
  - Updated $id to follow /api-documentation/v1.0 format
  - Validates successfully against metaschema

Schemas Deleted (3):
- markdown-manpage (duplicate of manpage-schema-v1.0.md)
- markdown-manpage-schema.json (duplicate of manpage-schema-v1.0.md)
- enhanced-manpage (replaced by manpage-schema-v1.0.md)

CLI Enhancement (markitect/cli.py):
- Updated schema-ingest to support markdown (.md) files
- Auto-detects file type and uses MarkdownSchemaLoader for .md files
- Extracts JSON schema from markdown for database storage
- Maintains backward compatibility with JSON files

Final Schema Registry (4 schemas):
 terminology-schema-v1.0.md - Terminology validation
 api-documentation-schema-v1.0.md - API documentation structure
 manpage-schema-v1.0.md - Unix manual pages
 schema-schema-v1.0.md - Metaschema for validating schemas

All schemas:
- Follow naming convention: {domain}-schema-v{major}.{minor}.md
- Include proper frontmatter with schema-id, version, status
- Validate successfully against schema-schema-v1.0.md metaschema
- Stored in database and ready for use

Progress Tracking:
- Updated TODO.md with Phase 4 completion
- Updated CHANGELOG.md with migration details
- Next: Phase 5 - CLI & Documentation Updates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-05 09:38:43 +01:00
parent f3aaec99bb
commit 60d9f7a2c3
6 changed files with 800 additions and 20 deletions

View File

@@ -1617,33 +1617,52 @@ def validate(config, file_path, schema, schema_json, quiet, detailed_errors, err
@pass_config
def schema_ingest(config, schema_file, name):
"""
Read and store a JSON schema file in the database.
Read and store a schema file in the database.
Supports both JSON (.json) and Markdown (.md) schema files.
Validates schemas against the MarkiTect metaschema to ensure compatibility
with MarkiTect features like heading text capture and content instructions.
Implements Issue #3 and Issue #50 functionality.
SCHEMA_FILE: Path to the JSON schema file to store
SCHEMA_FILE: Path to the schema file to store (.json or .md)
Examples:
markitect schema-ingest my_schema.json
markitect schema-ingest manpage-schema-v1.0.md
markitect schema-ingest external_schema.json --name custom-name
markitect schema-ingest markitect_schema.json -v # Show metaschema validation
"""
try:
# Determine schema name
schema_name = name if name else schema_file.name
# Read schema file content
with open(schema_file, 'r', encoding='utf-8') as f:
schema_content = f.read()
# Load schema based on file type
if schema_file.suffix == '.md':
# Load markdown schema
from .schema_loader import MarkdownSchemaLoader
loader = MarkdownSchemaLoader()
# Validate JSON format
try:
schema_data = json.loads(schema_content)
except json.JSONDecodeError as e:
click.echo(f"Error: Invalid JSON in schema file - {e}", err=True)
sys.exit(1)
try:
schema_data_full = loader.load_schema(schema_file)
schema_data = schema_data_full['schema']
# Store the JSON content for database
schema_content = json.dumps(schema_data, indent=2)
if config.get('verbose'):
click.echo(f"✅ Loaded markdown schema: {schema_file.name}")
except Exception as e:
click.echo(f"Error: Failed to load markdown schema - {e}", err=True)
sys.exit(1)
else:
# Load JSON schema
with open(schema_file, 'r', encoding='utf-8') as f:
schema_content = f.read()
# Validate JSON format
try:
schema_data = json.loads(schema_content)
except json.JSONDecodeError as e:
click.echo(f"Error: Invalid JSON in schema file - {e}", err=True)
sys.exit(1)
# Validate against MarkiTect metaschema
from .metaschema import MetaschemaValidator