Skip to content

Commit 8947f0f

Browse files
authored
fix: migration test (baserow#4574)
1 parent be28faa commit 8947f0f

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

backend/src/baserow/contrib/database/migrations/0170_update_password_tsv_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ class Migration(migrations.Migration):
3232
("database", "0169_alter_galleryview_card_cover_image_field"),
3333
]
3434

35-
operations = [migrations.RunSQL(update_password_tsv_index)]
35+
operations = [migrations.RunSQL(update_password_tsv_index, migrations.RunSQL.noop)]

backend/src/baserow/core/pgvector.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ def try_enable_pgvector() -> bool:
4545
:return: True if the extension is now enabled, False otherwise.
4646
"""
4747

48-
if is_pgvector_enabled():
49-
return True
50-
5148
try:
5249
with connection.cursor() as cursor:
5350
cursor.execute("CREATE EXTENSION IF NOT EXISTS vector;")
@@ -321,6 +318,15 @@ def try_migrate_vector_fields(sender, **kwargs):
321318
previously disabled, so that the field and index can be created later.
322319
"""
323320

321+
# Check if the ContentType for SchemaOperation exists. If not, it means the
322+
# core migrations haven't fully run yet (e.g., in migration tests with a
323+
# separate database), so we skip the vector field migration.
324+
if not ContentType.objects.filter(
325+
app_label="core", model="schemaoperation"
326+
).exists():
327+
print("skipped (SchemaOperation content type not ready).")
328+
return
329+
324330
was_enabled = is_pgvector_enabled()
325331
pgvector_enabled = try_enable_pgvector()
326332

backend/src/baserow/test_utils/pytest_conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,14 @@ def second_separate_database_for_migrations(
828828
_set_suffix_to_test_databases(suffix)
829829

830830
with django_db_blocker.unblock():
831+
# Clear ContentType cache before setting up the second database.
832+
# The cache may contain IDs from the first test database, which would
833+
# cause foreign key violations when post_migrate signals try to create
834+
# records referencing ContentTypes in the new database.
835+
from django.contrib.contenttypes.models import ContentType
836+
837+
ContentType.objects.clear_cache()
838+
831839
db_cfg = setup_databases(
832840
verbosity=request.config.option.verbose,
833841
interactive=False,

enterprise/backend/src/baserow_enterprise/migrations/0044_migrate_app_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ class Migration(migrations.Migration):
2929
]
3030

3131
operations = [
32-
migrations.RunPython(migrate_app_labels),
32+
migrations.RunPython(migrate_app_labels, migrations.RunPython.noop),
3333
]

0 commit comments

Comments
 (0)