Skip to content

Commit

Permalink
Closes #36: Execute all branch provisioning operations inside a Postg…
Browse files Browse the repository at this point in the history
…reSQL transaction
  • Loading branch information
jeremystretch committed Aug 9, 2024
1 parent 3dac852 commit f971fb0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions netbox_branching/models/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ def provision(self, user):
with connection.cursor() as cursor:
schema = self.schema_name

# Start a transaction
cursor.execute('BEGIN')

# Create the new schema
logger.debug(f'Creating schema {schema}')
try:
Expand Down Expand Up @@ -435,6 +438,9 @@ def provision(self, user):
f"ALTER TABLE {schema}.{table} ALTER COLUMN id SET DEFAULT nextval('public.{table}_id_seq')"
)

# Commit the transaction
cursor.execute('COMMIT')

except Exception as e:
logger.error(e)
Branch.objects.filter(pk=self.pk).update(status=BranchStatusChoices.FAILED)
Expand Down

0 comments on commit f971fb0

Please sign in to comment.