Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ class Migration(migrations.Migration):
("database", "0169_alter_galleryview_card_cover_image_field"),
]

operations = [migrations.RunSQL(update_password_tsv_index)]
operations = [migrations.RunSQL(update_password_tsv_index, migrations.RunSQL.noop)]
12 changes: 9 additions & 3 deletions backend/src/baserow/core/pgvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ def try_enable_pgvector() -> bool:
:return: True if the extension is now enabled, False otherwise.
"""

if is_pgvector_enabled():
return True

try:
with connection.cursor() as cursor:
cursor.execute("CREATE EXTENSION IF NOT EXISTS vector;")
Expand Down Expand Up @@ -321,6 +318,15 @@ def try_migrate_vector_fields(sender, **kwargs):
previously disabled, so that the field and index can be created later.
"""

# Check if the ContentType for SchemaOperation exists. If not, it means the
# core migrations haven't fully run yet (e.g., in migration tests with a
# separate database), so we skip the vector field migration.
if not ContentType.objects.filter(
app_label="core", model="schemaoperation"
).exists():
print("skipped (SchemaOperation content type not ready).")
return

was_enabled = is_pgvector_enabled()
pgvector_enabled = try_enable_pgvector()

Expand Down
8 changes: 8 additions & 0 deletions backend/src/baserow/test_utils/pytest_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,14 @@ def second_separate_database_for_migrations(
_set_suffix_to_test_databases(suffix)

with django_db_blocker.unblock():
# Clear ContentType cache before setting up the second database.
# The cache may contain IDs from the first test database, which would
# cause foreign key violations when post_migrate signals try to create
# records referencing ContentTypes in the new database.
from django.contrib.contenttypes.models import ContentType

ContentType.objects.clear_cache()

db_cfg = setup_databases(
verbosity=request.config.option.verbose,
interactive=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(migrate_app_labels),
migrations.RunPython(migrate_app_labels, migrations.RunPython.noop),
]
Loading