pypi peewee 4.4.0

3 hours ago

In which we learn to migrate (somewhat).

  • Add playhouse.migrations for running migration scripts. Migrations are python files defining up(migrator, db) and optionally down(...). Migrations are applied in numeric order a-la Django, and stored by name in a history table. CLI via pwmigrate accepting status, up, down, initial, create, generate, fake and diff. To run from python, migrations.run(db).
  • Add basic playhouse.schema_diff for 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 NULL with migrator, which allows skipping the 3-step process of add nullable, populate default, set not null.
  • db_url.connect() raises ValueError for a url with no database name, e.g. postgres://dbname (two slashes reads dbname as 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 a DELETE query, and model.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 a LIMIT 1 via first(), 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 JSONField works when proxy is already initialized. Thanks @NotAFlightRisk, refs #3070.
  • commit() / rollback() on a closed db will raise rather than silently open a new connection.

View commits

E1iyHHcXIAMp4J9 IMG_4630

Don't miss a new peewee release

NewReleases is sending notifications on new releases.