Skip to content

Commit

Permalink
Only create trac tables if they do not already exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahboyce committed Nov 15, 2024
1 parent 1729f82 commit a0c4bf3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tracdb/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def _create_db_table_for_model(model, schema_editor):
"""
Use the schema editor API to create the db table for the given (unmanaged) model.
"""
with connections["trac"].cursor() as cursor:
tables = schema_editor.connection.introspection.table_names(cursor)

if model._meta.db_table in tables:
# Table already created.
return

schema_editor.create_model(model)
if model._meta.model_name in _MODELS_WITH_FAKE_COMPOSITE_PK:
_replace_primary_key_field_with_autofield(model, schema_editor)
Expand Down

0 comments on commit a0c4bf3

Please sign in to comment.