> For the complete documentation index, see [llms.txt](https://doorkeeper.gitbook.io/guides/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doorkeeper.gitbook.io/guides/internals/rake.md).

# Rake

If you are using `rake`, you can load rake tasks provided by this gem, by adding the following line to your `Rakefile`:

```ruby
Doorkeeper::Rake.load_tasks
```

## Cleaning up the database

By default Doorkeeper is retaining expired and revoked access tokens and grants. This allows to keep an audit log of those records, but it also leads to the corresponding tables to grow large over the lifetime of your application.

If you are concerned about those tables growing too large, you can regularly run the following rake task to remove stale entries from the database:

```
rake doorkeeper:db:cleanup
```

Note that this will remove tokens that are expired according to the configured TTL in `Doorkeeper.configuration.access_token_expires_in`. The specific `expires_in` value of each access token **is not considered**. The same is true for access grants.

Also you could use separate tasks:

```
rake doorkeeper:db:cleanup:revoked_tokens
rake doorkeeper:db:cleanup:expired_tokens
rake doorkeeper:db:cleanup:revoked_grants
rake doorkeeper:db:cleanup:expired_grants
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doorkeeper.gitbook.io/guides/internals/rake.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
