Skip to main content

Crate fse_schema

Crate fse_schema 

Source
Expand description

fse-schema — the shared schema layer of the fse ORM.

One schema model with three consumers:

  • fse-orm-macros parses a single #[derive(Table)] struct into a TableDef to generate compile-time-checked sqlx queries,
  • fse-cli parses the whole tables folder into a Schema, diffs it against the committed snapshot and emits plain sqlx migration files,
  • the snapshot file (.fse/schema.json) is just this model as JSON.

Nothing in this crate knows about any concrete application: table names, column names and constraints all come from the parsed structs.

Re-exports§

pub use diff::Migration;
pub use diff::diff_schemas;
pub use model::ColumnDef;
pub use model::DefaultValue;
pub use model::EnumDef;
pub use model::ForeignKey;
pub use model::OnDelete;
pub use model::RelationDef;
pub use model::Schema;
pub use model::SqlType;
pub use model::TableDef;

Modules§

diff
Schema diffing: old snapshot + new structs → one migration file.
model
The schema model — the single source of truth for what a #[derive(Table)] struct means in SQL. Everything is serde-serializable because the snapshot file is this model as JSON.
parse
syn-based parsing of #[derive(Table)] structs and #[derive(DbEnum)] enums into the schema model. This is the only place #[orm(...)] attribute semantics are defined — the derive macro and the CLI both call into here, so they can never drift apart.
snapshot
The snapshot file (.fse/schema.json): the schema state the last generated migration brought the database to. Committed to git so migration generation is deterministic and reviewable.
sql
SQLite DDL generation from the schema model. Kept dialect-shaped (every statement goes through this module) so a second backend is a new module, not a rewrite.

Structs§

Error
A schema error: unparseable source, an unsupported type, an invalid attribute combination or an unresolvable reference. Always carries a message that names the offending struct/field so the CLI and the derive can surface it directly.