Command-Line Interface¶
The Database wrapper registers a fp command group with the
flask CLI. The commands locate your app the same way flask run does,
via --app or the FLASK_APP environment variable.
$ flask fp --help
Tables¶
create-tables creates the table for every model subclassing db.Model,
in foreign-key order. Existing tables are left alone, so it is safe to re-run.
$ flask fp create-tables
created: note
created: user
Users¶
createsuperuser creates an active admin user for the
authentication system. The password prompt hides
input and asks for confirmation. Pass --email to set the email address.
$ flask fp createsuperuser
Username: admin
Password:
Repeat for confirmation:
created superuser: admin
Migrations¶
The migration commands wrap the playhouse.migrations runner,
available in peewee 4.4 or newer, and mirror its pwmigrate verbs.
The database and models come from the app.
statuslists migrations, marking applied ones.up [TARGET]applies pending migrations, optionally stopping afterTARGET.down [TARGET]reverts the newest migration, or back throughTARGET.fake [TARGET]records pending migrations as applied without running them.create NAMEwrites a new empty/skeleton migration.initialwrites a migration creating every model table.generate NAMEwrites a migration from the diff between the models and the database.diffprints that diff without writing anything.
See Migrations for a worked example.
Shell¶
The wrapper also installs a shell context, so flask shell starts with
db, database (the raw peewee database) and every model in scope.