In which we learn to migrate (somewhat).
- Add
playhouse.migrationsfor running migration scripts. Migrations are python files definingup(migrator, db)and optionallydown(...). Migrations are applied in numeric order a-la Django, and stored by name in a history table. CLI viapwmigrateacceptingstatus,up,down,initial,create,generate,fakeanddiff. To run from python,migrations.run(db). - Add basic
playhouse.schema_difffor comparing models against the schema and reporting differences (tables to create, columns added or removed, indexes added or removed). - Allow adding column to existing table as
NOT NULLwith migrator, which allows skipping the 3-step process of add nullable, populate default, set not null. db_url.connect()raisesValueErrorfor a url with no database name, e.g.postgres://dbname(two slashes readsdbnameas the host).- Add a
SchemaMigrator.migration_context()helper for wrapping migrations. This was wanted for SQLite in order to disable FK pragma, which could trigger cascading deletes while recreating tables. - Allow
SchemaMigrator.from_database()to support database proxies. - Add support for newer SQLite ALTER TABLE functionality from 3.53.0.
- Do not allow
delete()method to be called on a model instance.Model.delete()is a classmethod for constructing aDELETEquery, andmodel.delete_instance()has always been the correct path for deleting a model instance. This new check just ensures that a new user cannot accidentally delete their whole table by using the class-version from an instance. Fixes #2277. - Server-side cursors opened inside a transaction on psycopg3 are no longer declared
WITH HOLD. They stream and are scoped to the transaction, rather than spooling their remaining rows server-side at commit. scalar()applies aLIMIT 1viafirst(), rather than running the query unbounded and reading the first value. The query itself is not mutated, the limit is applied only on an internal copy, refs #3068.- Ensure
JSONFieldworks when proxy is already initialized. Thanks @NotAFlightRisk, refs #3070. commit()/rollback()on a closed db will raise rather than silently open a new connection.
