Skip to main content

Performing Migrations

Performing Database Migrations

You may choose to edit CTFd's database models. For MySQL, this requires performing a migration.1 CTFd makes use of alembic and Flask-Migrate to perform database migrations.

  1. Make changes to the models file to reflect your desired database schema
  2. Generate the flask migration
flask db migrate -m "<message>"
  1. Upgrade the schema locally
flask db upgrade

To perform a migration for a plugin, see Adding Database Tables.

For additional information, please refer to the official Flask-Migrate documentation.

  1. If you use SQLite, you don’t need to perform a migration. SQLite is easier because it builds from the model classes without migrations. You only need to add the migration if you’re using MySQL. You can change which database you are using in the docker-compose.yml file. If you run without specifying a DATABASE_URL, it will default to SQLite.