liveBook · Manning

Schema

As explained in The Quick Python Book, Fourth Edition

A database schema is the formal definition of a database's tables, fields, data types, relationships, and other structural constraints.

A database schema defines the structure of a relational database: its tables, fields, data types, relationships, and structural constraints. In application development, the schema must stay aligned with the code or ORM that accesses it. section 23.4.2 section 23.9

Schemas commonly change as an application evolves. Adding fields or changing types manually can make versions difficult to track and roll back. Migration tools record each change as code, apply revisions in sequence, and provide a reverse operation for downgrading. section 23.4.2

Creating and reversing an address table

An Alembic revision can create an address table with an integer primary key and required string columns for address, city, and state. Its downgrade removes the table. Running alembic upgrade head produces address alongside the existing people table; alembic downgrade -1 removes it again.

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Explains schema change management through reversible migrations, stopping short of a broad treatment of structural design.
Examples
Demonstrates an address table, revision metadata, Alembic upgrades and downgrades, and table listings before and after migration.
What it assumes
Assumes familiarity with application code and relational database access while demonstrating migration setup and operations.
What you can do after
Operate Alembic to create, apply, inspect, and reverse versioned relational schema changes.
How it connects
Connects schemas with relational databases, ORMs, SQLAlchemy, Alembic, migrations, SQLite, and database versioning.

Also explained in

Compare how 44 books explain schema →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.