# Generated by Django 3.2.25 on 2024-03-20 15:15

import django.contrib.postgres.indexes
from django.db import migrations
import pgtrigger.compiler
import pgtrigger.migrations


class Migration(migrations.Migration):

    dependencies = [
        ("bookwyrm", "0196_merge_pr3134_into_main"),
    ]

    operations = [
        migrations.AddIndex(
            model_name="author",
            index=django.contrib.postgres.indexes.GinIndex(
                fields=["search_vector"], name="bookwyrm_au_search__b050a8_gin"
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="author",
            trigger=pgtrigger.compiler.Trigger(
                name="update_search_vector_on_author_edit",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func="new.search_vector := setweight(to_tsvector('simple', new.name), 'A') || setweight(to_tsvector('simple', coalesce(array_to_string(new.aliases, ' '), '')), 'B');RETURN NEW;",
                    hash="b97919016236d74d0ade51a0769a173ea269da64",
                    operation='INSERT OR UPDATE OF "name", "aliases", "search_vector"',
                    pgid="pgtrigger_update_search_vector_on_author_edit_c61cb",
                    table="bookwyrm_author",
                    when="BEFORE",
                ),
            ),
        ),
        migrations.RunSQL(
            # Calculate search vector for all Authors.
            sql="UPDATE bookwyrm_author SET search_vector = NULL;",
            reverse_sql="UPDATE bookwyrm_author SET search_vector = NULL;",
        ),
    ]
