django / django/new-features

Allow to create test databases with an unlogged table

Open
#200 6 comments 2 reactions 0 assignees View on GitHub
Testing Third Party Package
Dominant language
No language data
Stars
188
Forks
7
PR merge metrics
No merged PRs in 30d

Description

### Code of Conduct

- [x] I agree to follow Django's Code of Conduct

### Feature Description

One can speedup the tests by creating the test database create tables with [*unlogged* tables](https://www.crunchydata.com/blog/postgresl-unlogged-tables), through a setting for the `test` management command.

### Problem

One usually wants to run the tests as fast as possible. One of the ways to do this is to disable the *write ahead log (WAL)* of the database for a PostgreSQL database.

We can patch the query template, like:

```
from django.db.backends.base.schema import BaseDatabaseSchemaEditor

BaseDatabaseSchemaEditor.sql_create_table = "CREATE UNLOGGED TABLE %(table)s (%(definition)s)"
```

It might be useful to introduce this as a command flag such that by enabling this in the `test` command, it will, if we create a fresh database, create it with unlogged tables.

Depending on whether you run the database on memory or a disk, the performance boost is different.

### Request or proposal

request

### Additional Details

_No response_

### Implementation Suggestions

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_create_table and the test management command path to understand where fresh test databases and tables are created. Compare the proposed setting or command flag with PostgreSQL's unlogged-table behavior; done means the chosen interface creates fresh PostgreSQL test tables as unlogged without changing other database backends.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, postgresql
Domain
databases, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.