Commit Graph
26 Commits
Author SHA1 Message Date
David Wobrock a856f0d524 Apply updated pre-commit hooks. 2023-07-09 14:42:35 +02:00
David Cain 0c5519d9dc Add new check for indexing with atomic=True
Briefly, this check helps prevent a long-running index creation from
preventing all reads and writes to a table.

This supplements an existing check
==================================
There is an existing check, `CREATE_INDEX` which warns about creating
indices without the `CONCURRENTLY` argument. It's a helpful check!

However, there are some valid reasons to prefer non-concurrent index
creation. For example, concurrent index creation may struggle to
complete when applied to write-heavy tables (since Postgres will have to
make repeated passes on the table to accommodate the new reads since the
last round).

The danger of `EXCLUSIVE` locks
===============================
If you *do* want to create indices nonconcurrently, there is still a
**huge footgun** to be aware of -- locks which are held in a transaction
are not released until the transaction closes.

Dangerous Django defaults
=========================
By default, any time you add a new Django field with `db_index=True` or
`unique=True`, the automatically generated `Migration` has:

- implicit setting of `atomic=True` (transactions are on)
- an `ALTER TABLE...ADD COLUMN` call (exclusively locks the table)
- a `CREATE INDEX` invocation (*hopefully* quick, due to nullable
  columns)

It's even more dangerous if you combine an `ALTER TABLE` call with
`CREATE INDEX` of an existing, non-nullable column.

Favor `atomic=False` if you must index
======================================
Index-creating migrations should have few `operations`. Since index
creation does not modify row-level data (and only requires locking
against writes), there's no reason to use transactions.

It's prudent to bypass the default `atomic=True` for index creation.
2023-07-09 14:42:35 +02:00
Caspar Wylie 2d15ea84f9 Support partial function inspection in data migrations 2023-07-03 21:02:14 +02:00
David Wobrock f511d51d9a Apply pre-commit hooks on all files. 2023-07-02 20:36:03 +02:00
David Wobrock 2ee7dac3b3 Add internal classes and add type hints + mypy. 2022-12-26 16:26:24 +01:00
Sondre Lillebø Gundersen bd4eb89b8c chore: Upgrade Python syntax with pyupgrade
Run with the following pre-commit configuration:

```
repos:
  - repo: https://github.com/asottile/pyupgrade
    rev: v3.1.0
    hooks:
      - id: pyupgrade
        args: [ "--py3-plus", "--py36-plus", "--py37-plus" ]
```

The rationale for every change can be found at https://github.com/asottile/pyupgrade
2022-11-03 22:00:00 +01:00
David Wobrock 74a7ee9239 Remove remaining __future__ imports. 2022-07-23 11:59:50 +02:00
David Wobrock 3fbc720650 Add Django 4.0 support 2022-01-28 21:03:12 +01:00
David Wobrock 062c60cd31 Add DEFAULT_AUTO_FIELD to settings for explicit PK field 2021-05-02 15:07:16 +02:00
David Wobrock c988ee3d51 Delete apps.py files for Django 3.2 automatic discovery 2021-05-02 15:07:16 +02:00
David-Wobrock 6ab1d58c47 Apply isort to the project 2020-11-30 21:46:40 +01:00
David-Wobrock 321b41ddd0 Start using GitHub Actions and remove Travis 2020-11-26 18:43:34 +01:00
David Wobrock c2c26ae106 Add tests for the makemigrations override 2020-07-02 19:15:30 +02:00
David Wobrock f21ff2c278 Add (failing) tests cases for makeing a column not null with a Django default value 2020-06-20 18:08:16 +02:00
David Wobrock d411ea2f6b Unrelated: remove unused Django boilerplate files 2020-06-20 18:08:16 +02:00
David-Wobrock a5e17d0df1 Bump to 2.2.1 and black some files 2020-05-16 21:16:36 +02:00
David Wobrock d01875b3be add warnings and RunPython basic linting 2020-02-07 23:29:15 +01:00
David Wobrock 691b1b82cb Add app_data_migration used for tests 2020-02-07 23:29:15 +01:00
David Wobrock 537542b30d Add manytomany app to test project and integration tests 2019-10-21 22:25:01 +02:00
David Wobrock ca6b623200 Add unused app with manytomany field 2019-10-21 22:25:01 +02:00
David Wobrock 8aac58abbe Add app for unique together testing 2019-07-30 10:47:20 +02:00
David Wobrock f597df779b Black test app migration 2019-07-29 23:14:30 +02:00
Viktor Danyliuk b79f9794ec add testcase: drop table 2019-07-29 23:14:30 +02:00
David Wobrock d02df5d20f Black migration file 2019-07-29 21:05:12 +02:00
Viktor Danyliuk 5e2c7bbfaf add testcase for DROP NOT NULL 2019-07-29 21:05:12 +02:00
David Wobrock 26ed4ecf62 Tests: add test project
* manage.py file at the root of the project
* targetting the project located at tests/test_project/settings.py

That allows testing the linter through just calling it on the project itself.
Using the new method coming soon: `python manage.py lintmigrations`
2019-05-12 15:32:57 +02:00