Commit Graph
26 Commits
Author SHA1 Message Date
David Wobrock 18a39cb3fc Support Django 5.0 db_default attribute.
A DB default is not considered backward incompatible, as the default value is kept on DB-level.
See https://docs.djangoproject.com/en/dev/releases/5.0/#database-computed-default-values
2024-03-29 12:39:30 +01:00
David Cain 48fac8856b Downgrade CREATE_INDEX_EXCLUSIVE to a warning
While it's always a dangerous *pattern* to create an index while a
transaction is open & holds an exclusive lock, in practice it's not
always a big deal (for example, indexing a table with very few rows can
be fast). Accordingly, downgrade to a warning.
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
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 bef47906d1 Fix #209 - Raise when getting SQL statements fail. 2022-07-28 23:45:14 +02:00
David Wobrock 6d595f1555 Add support for positional app_label and migration_name arguments 2021-05-26 18:53:19 +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 813c5c8690 Remove apache license headers in each file. The one full copy of the license at the root of the repo shall define the license for all source files. 2020-01-11 22:08:33 +01:00
David Wobrock 537542b30d Add manytomany app to test project and integration tests 2019-10-21 22:25:01 +02:00
David Wobrock 652031ce8d Add failing tests for unique_together condition 2019-07-30 10:47:20 +02:00
Viktor Danyliuk b79f9794ec add testcase: drop table 2019-07-29 23:14:30 +02:00
David Wobrock ef2052a7b0 Work on SQL Analyser module
* With database specific functions
* Functions that analyse the entire transaction
* Unit tests that only test this module
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 5390fd507f Update Tests:
* don't use the project fixtures anymore but the one Django project
* update and refactor cache tests to be less brittle
* explicitly test mysql, postgresql and sqlite3 databases
* remove 'multiple_call' tests since it is not possible anymore
(with the Django singleton)
* update Travis and tox (dropping Python 3.4)
2019-05-12 15:32:57 +02:00
David-Wobrock 5c7dab8db2 Update linter tests for multiple backends
Create a base test class and have 3 different backends for now:
* mysql
* sqlite3
* postgresql
2019-02-24 15:55:05 +01:00
David-Wobrock 952e596d92 Bump copyright version to 2019 in files 2019-01-03 22:05:00 +01:00
Felix 9e3dbf7778 Mark migrations as ignored 2018-12-23 17:46:57 +01:00
David-Wobrock e4880c5600 Consider altering a column as backward incompatible
* Resolves #9
* With test
* For mysql only currently
2018-01-14 15:52:46 +01:00
David-Wobrock 55e1e13ad5 Update copyright year to 2018 2018-01-07 12:15:23 +01:00
David Wobrock 15b2fbb9e1 Add tests from command line directly
* Test options
* Syntax error fix
* Ajust the commit id for a test (was wrongly set)
2017-11-30 17:44:12 +01:00
David-Wobrock fc8f405801 Fix tests, flake8 and update README 2017-11-30 00:09:18 +01:00
David Wobrock 50ce4f4cad Large code refactoring
* Add tests
* Remove git dependency (only needed when a git identifier is specified)
2017-11-29 23:57:23 +01:00
David-Wobrock 8f01e1e99d Add basic travis.yml and refactor some tests 2017-11-20 23:11:33 +01:00
David-Wobrock 6f84056aeb Change git fixtures, do not use submodule or subtree
Just rename git folder when testing and delete them at the end
2017-11-01 15:28:17 +01:00
David-Wobrock 1cd36825c1 Start large refactoring of tests and project structure
* Put tests in tests/ diretory
* Write functional tests
* Create setup.py
* Put sources into django_migration_linter folder (for future PyPi publishing)
2017-10-30 23:31:13 +01:00