Skip to content

Commit

Permalink
chore: Silence Django warning on new non-nullable column with default
Browse files Browse the repository at this point in the history
Postgres 11+ can easily add a new non-nullable column with a default using nothing but an extremely short lock.

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=16828d5c0273b4fe5f10f42588005f16b415b2d8
  • Loading branch information
rafaeelaudibert committed Jan 6, 2025
1 parent b5730a2 commit 06711be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
from django.db import migrations, models


# :KLUDGE: Work around test_migrations_are_safe
class AddFieldNullSafe(migrations.AddField):
def describe(self):
return super().describe() + " -- not-null-ignore"


class Migration(migrations.Migration):
dependencies = [
("posthog", "0538_experiment_stats_config"),
]

operations = [
migrations.AddField(
AddFieldNullSafe(
model_name="team",
name="human_friendly_comparison_periods",
field=models.BooleanField(default=False),
Expand Down
7 changes: 7 additions & 0 deletions posthog/settings/data_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def postgres_config(host: str) -> dict:
}


# Skip the check for non-nullable fields with default because we're on PG11+
# and Postgres can easily add new non-nullable columns with a default value.
SILENCED_SYSTEM_CHECKS = [
"migrations.W004" # Silence the non-null field warning
]


if TEST or DEBUG:
PG_HOST: str = os.getenv("PGHOST", "localhost")
PG_USER: str = os.getenv("PGUSER", "posthog")
Expand Down

0 comments on commit 06711be

Please sign in to comment.