mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-21 21:49:51 +01:00
chore(dev): Introduce django-linear-migrations
(#25989)
This commit is contained in:
parent
cdef644a21
commit
bf1161364b
1
ee/migrations/max_migration.txt
Normal file
1
ee/migrations/max_migration.txt
Normal file
@ -0,0 +1 @@
|
||||
0016_rolemembership_organization_member
|
@ -1,11 +0,0 @@
|
||||
admin: 0003_logentry_add_action_flag_choices
|
||||
auth: 0012_alter_user_first_name_max_length
|
||||
axes: 0006_remove_accesslog_trusted
|
||||
contenttypes: 0002_remove_content_type_name
|
||||
ee: 0016_rolemembership_organization_member
|
||||
otp_static: 0002_throttling
|
||||
otp_totp: 0002_auto_20190420_0723
|
||||
posthog: 0510_salesforce_missing_schemas
|
||||
sessions: 0001_initial
|
||||
social_django: 0010_uid_db_index
|
||||
two_factor: 0007_auto_20201201_1019
|
@ -1,23 +0,0 @@
|
||||
"""Cause git to detect a merge conflict when two branches have migrations."""
|
||||
|
||||
from django.core.management.commands.makemigrations import (
|
||||
Command as MakeMigrationsCommand,
|
||||
)
|
||||
from django.db.migrations.loader import MigrationLoader
|
||||
|
||||
|
||||
class Command(MakeMigrationsCommand):
|
||||
def handle(self, *app_labels, **options):
|
||||
# Generate a migrations manifest with latest migration on each app
|
||||
super().handle(*app_labels, **options)
|
||||
|
||||
loader = MigrationLoader(None, ignore_no_migrations=True)
|
||||
apps = sorted(loader.migrated_apps)
|
||||
graph = loader.graph
|
||||
|
||||
with open("latest_migrations.manifest", "w", encoding="utf_8") as f:
|
||||
for app_name in apps:
|
||||
leaf_nodes = graph.leaf_nodes(app_name)
|
||||
if len(leaf_nodes) != 1:
|
||||
raise Exception("App {} has multiple leaf migrations!".format(app_name))
|
||||
f.write("{}: {}\n".format(app_name, leaf_nodes[0][1]))
|
1
posthog/migrations/max_migration.txt
Normal file
1
posthog/migrations/max_migration.txt
Normal file
@ -0,0 +1 @@
|
||||
0510_salesforce_missing_schemas
|
@ -127,6 +127,8 @@ MIDDLEWARE = [
|
||||
if DEBUG:
|
||||
# Used on local devenv to reverse-proxy all of /i/* to capture-rs on port 3000
|
||||
INSTALLED_APPS.append("revproxy")
|
||||
# rebase_migration command
|
||||
INSTALLED_APPS.append("django_linear_migrations")
|
||||
|
||||
# Append Enterprise Edition as an app if available
|
||||
try:
|
||||
|
@ -1,38 +0,0 @@
|
||||
import glob
|
||||
import os
|
||||
import pathlib
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
class TestLatestMigrations(TestCase):
|
||||
def test_posthog_migration_is_in_sync_with_latest(self) -> None:
|
||||
"""
|
||||
regression test
|
||||
|
||||
when manually merging and updating migrations it is possible for
|
||||
latest_migrations.manifest get out of sync with the migrations files
|
||||
|
||||
this protects against that
|
||||
"""
|
||||
latest_manifest_migration = self._get_latest_migration_from_manifest("posthog")
|
||||
latest_migration_file = self._get_newest_migration_file(f"{pathlib.Path().resolve()}/posthog/migrations/*")
|
||||
self.assertEqual(latest_manifest_migration, latest_migration_file)
|
||||
|
||||
def test_ee_migrations_is_in_sync_with_latest(self):
|
||||
latest_manifest_migration = self._get_latest_migration_from_manifest("ee")
|
||||
latest_migration_file = self._get_newest_migration_file(f"{pathlib.Path().resolve()}/ee/migrations/*")
|
||||
self.assertEqual(latest_manifest_migration, latest_migration_file)
|
||||
|
||||
@staticmethod
|
||||
def _get_newest_migration_file(path: str) -> str:
|
||||
migrations = [file for file in glob.glob(path) if file.endswith(".py") and not file.endswith("__init__.py")]
|
||||
latest_file = max(sorted(migrations))
|
||||
return os.path.basename(latest_file).replace(".py", "")
|
||||
|
||||
@staticmethod
|
||||
def _get_latest_migration_from_manifest(django_app: str) -> str:
|
||||
root = pathlib.Path().resolve()
|
||||
manifest = pathlib.Path(f"{root}/latest_migrations.manifest").read_text()
|
||||
posthog_latest_migration = next(line for line in manifest.splitlines() if line.startswith(f"{django_app}: "))
|
||||
|
||||
return posthog_latest_migration.replace(f"{django_app}: ", "")
|
@ -18,6 +18,7 @@ mypy-extensions==1.0.0
|
||||
datamodel-code-generator==0.26.1
|
||||
djangorestframework-stubs~=3.14.5
|
||||
django-stubs==5.0.4
|
||||
django-linear-migrations==2.16.*
|
||||
Faker==17.5.0
|
||||
fakeredis[lua]==2.23.3
|
||||
freezegun==1.2.2
|
||||
|
@ -74,8 +74,11 @@ datamodel-code-generator==0.26.1
|
||||
django==4.2.15
|
||||
# via
|
||||
# -c requirements.txt
|
||||
# django-linear-migrations
|
||||
# django-stubs
|
||||
# django-stubs-ext
|
||||
django-linear-migrations==2.16.0
|
||||
# via -r requirements-dev.in
|
||||
django-stubs==5.0.4
|
||||
# via
|
||||
# -r requirements-dev.in
|
||||
|
Loading…
Reference in New Issue
Block a user