Skip to content

Commit

Permalink
post-migrate hook to Dolt commit django migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-wm-arthur committed Aug 16, 2021
1 parent b81a8da commit 2732434
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions dolt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.db.models.signals import post_migrate

from nautobot.extras.plugins import PluginConfig

from dolt.migrations import dolt_autocommit_migration


class NautobotDolt(PluginConfig):
name = "dolt"
Expand All @@ -22,6 +26,10 @@ class NautobotDolt(PluginConfig):
"dolt.middleware.DoltAutoCommitMiddleware",
]

def ready(self):
super().ready()
post_migrate.connect(dolt_autocommit_migration, sender=self)


# Registry of Content Types of models that should be under version control.
# Top-level dict keys are app_labels. If the top-level dict value is `True`,
Expand Down
17 changes: 17 additions & 0 deletions dolt/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.db import connection


def dolt_autocommit_migration(sender, **kwargs):
msg = "created dolt commit for database migration"
author = "nautobot <nautobot@ntc.com>"
with connection.cursor() as cursor:
cursor.execute("SELECT dolt_add('-A') FROM dual;")
cursor.execute(
f"""
SELECT dolt_commit(
'--all',
'--allow-empty',
'--message', '{msg}',
'--author', '{author}')
FROM dual;"""
)
1 change: 0 additions & 1 deletion dolt/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.conf import settings
from django.db import connection, connections, transaction
from django.db.models.signals import m2m_changed, pre_delete, post_save

from nautobot.extras.models.change_logging import ObjectChange

Expand Down

0 comments on commit 2732434

Please sign in to comment.