Skip to content

test(db): add schema JSON round-trip and validation tests #440

Description

@GaspardKirira

Summary

Add automated tests for database schema JSON serialization and deserialization.

Schema snapshots are used by migration generation and must remain stable, deterministic, and compatible.

Current behavior

The schema system can serialize and deserialize:

  • schemas;
  • tables;
  • columns;
  • indexes;
  • column types;
  • column constraints;
  • raw SQL default values.

No automated tests currently verify snapshot stability or malformed input behavior.

Expected behavior

A schema serialized to JSON and loaded again must preserve all supported information.

Malformed or incomplete snapshots must fail with useful errors.

Scope

  • Test an empty schema.
  • Test one table with multiple columns.
  • Test all supported base types.
  • Test VARCHAR sizes.
  • Test nullable columns.
  • Test primary keys.
  • Test auto-increment columns.
  • Test unique columns.
  • Test default values.
  • Test single-column indexes.
  • Test multi-column indexes.
  • Test compact and pretty JSON output.
  • Test malformed JSON.
  • Test missing required fields.
  • Preserve the existing public DB API and snapshot format.

Suggested files

  • modules/db/tests/schema_json_test.cpp
  • modules/db/src/schema/Json.cpp

Acceptance criteria

  • Round-trip tests preserve all supported schema fields.
  • Pretty output is valid JSON.
  • Compact output is valid JSON.
  • The snapshot version remains present.
  • Unknown base types fail clearly.
  • Missing required table or column fields fail clearly.
  • Serialization output is deterministic for identical input.
  • Existing public APIs remain unchanged.

Non-goals

This issue does not include:

  • changing the snapshot format;
  • adding new schema types;
  • schema semantic validation;
  • migration diff testing.

Suggested labels

  • scope:db
  • type:ci
  • tests
  • good first issue
  • status:ready

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersscope:dbDatabase driversstatus:readyIssue is fully specified and ready for implementationtestsTests, CI coverage and validationtype:ciCI, tests, or tooling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions