Initial commit

This commit is contained in:
2024-08-27 20:33:44 +02:00
commit 1f1832267d
14794 changed files with 1599592 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailcore", "0002_initial_data"),
]
operations = [
migrations.CreateModel(
name="EditorsPick",
fields=[
(
"id",
models.AutoField(
serialize=False,
auto_created=True,
verbose_name="ID",
primary_key=True,
),
),
(
"sort_order",
models.IntegerField(blank=True, null=True, editable=False),
),
("description", models.TextField(blank=True)),
(
"page",
models.ForeignKey(on_delete=models.CASCADE, to="wagtailcore.Page"),
),
],
options={
"ordering": ("sort_order",),
},
bases=(models.Model,),
),
migrations.CreateModel(
name="Query",
fields=[
(
"id",
models.AutoField(
serialize=False,
auto_created=True,
verbose_name="ID",
primary_key=True,
),
),
("query_string", models.CharField(unique=True, max_length=255)),
],
options={},
bases=(models.Model,),
),
migrations.CreateModel(
name="QueryDailyHits",
fields=[
(
"id",
models.AutoField(
serialize=False,
auto_created=True,
verbose_name="ID",
primary_key=True,
),
),
("date", models.DateField()),
("hits", models.IntegerField(default=0)),
(
"query",
models.ForeignKey(
on_delete=models.CASCADE,
to="wagtailsearch.Query",
related_name="daily_hits",
),
),
],
options={},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name="querydailyhits",
unique_together={("query", "date")},
),
migrations.AddField(
model_name="editorspick",
name="query",
field=models.ForeignKey(
on_delete=models.CASCADE,
to="wagtailsearch.Query",
related_name="editors_picks",
),
preserve_default=True,
),
]

View File

@@ -0,0 +1,31 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailsearch", "0001_initial"),
]
operations = [
migrations.AlterModelOptions(
name="editorspick",
options={"ordering": ("sort_order",), "verbose_name": "Editor's Pick"},
),
migrations.AlterModelOptions(
name="querydailyhits",
options={"verbose_name": "Query Daily Hits"},
),
migrations.AlterField(
model_name="editorspick",
name="description",
field=models.TextField(verbose_name="Description", blank=True),
),
migrations.AlterField(
model_name="editorspick",
name="page",
field=models.ForeignKey(
on_delete=models.CASCADE, verbose_name="Page", to="wagtailcore.Page"
),
),
]

View File

@@ -0,0 +1,16 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("wagtailsearch", "0002_add_verbose_names"),
]
operations = [
# Do nothing. Previously this migration dropped the EditorsPick model from the application
# state but kept the database intact so that the wagtail.contrib.search_promotions app
# could subsequently adopt it by renaming the table. wagtail.contrib.search_promotions
# now creates its own table, so we don't want to keep the table from wagtailsearch around;
# we will delete it properly in wagtailsearch migration 0007.
# See https://github.com/wagtail/wagtail/issues/1824#issuecomment-1271840741
]

View File

@@ -0,0 +1,20 @@
# Generated by Django 2.2.dev20181026000358 on 2018-10-27 09:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("wagtailsearch", "0003_remove_editors_pick"),
]
operations = [
migrations.AlterModelOptions(
name="querydailyhits",
options={
"verbose_name": "Query Daily Hits",
"verbose_name_plural": "Query Daily Hits",
},
),
]

View File

@@ -0,0 +1,49 @@
# Generated by Django 3.2.4 on 2021-06-28 14:12
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("contenttypes", "0002_remove_content_type_name"),
("wagtailsearch", "0004_querydailyhits_verbose_name_plural"),
]
operations = [
migrations.CreateModel(
name="IndexEntry",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("object_id", models.CharField(max_length=50)),
("title_norm", models.FloatField(default=1.0)),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="contenttypes.contenttype",
),
),
],
options={
"verbose_name": "index entry",
"verbose_name_plural": "index entries",
"abstract": False,
},
),
migrations.AlterUniqueTogether(
name="indexentry",
unique_together={("content_type", "object_id")},
),
]

View File

@@ -0,0 +1,238 @@
# Generated by Django 3.2.4 on 2021-07-12 22:49
from django.db import connection, migrations, models
from wagtail.search.models import IndexEntry
# This migration takes on the base model defined in 0005_create_indexentry and adds certain fields that are specific to each database system
class Migration(migrations.Migration):
dependencies = [
("wagtailsearch", "0005_create_indexentry"),
]
if connection.vendor == "postgresql":
import django.contrib.postgres.indexes
import django.contrib.postgres.search
operations = [
migrations.AddField(
model_name="indexentry",
name="autocomplete",
field=django.contrib.postgres.search.SearchVectorField(),
),
migrations.AddField(
model_name="indexentry",
name="title",
field=django.contrib.postgres.search.SearchVectorField(),
),
migrations.AddField(
model_name="indexentry",
name="body",
field=django.contrib.postgres.search.SearchVectorField(),
),
migrations.AddIndex(
model_name="indexentry",
index=django.contrib.postgres.indexes.GinIndex(
fields=["autocomplete"], name="wagtailsear_autocom_476c89_gin"
),
),
migrations.AddIndex(
model_name="indexentry",
index=django.contrib.postgres.indexes.GinIndex(
fields=["title"], name="wagtailsear_title_9caae0_gin"
),
),
migrations.AddIndex(
model_name="indexentry",
index=django.contrib.postgres.indexes.GinIndex(
fields=["body"], name="wagtailsear_body_90c85d_gin"
),
),
]
elif connection.vendor == "sqlite":
from wagtail.search.backends.database.sqlite.utils import fts5_available
operations = [
migrations.AddField(
model_name="indexentry",
name="autocomplete",
field=models.TextField(null=True),
),
migrations.AddField(
model_name="indexentry",
name="body",
field=models.TextField(null=True),
),
migrations.AddField(
model_name="indexentry",
name="title",
field=models.TextField(),
),
]
if fts5_available():
operations.append(
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.CreateModel(
name="sqliteftsindexentry",
fields=[
(
"index_entry",
models.OneToOneField(
primary_key=True,
serialize=False,
to="wagtailsearch.indexentry",
on_delete=models.CASCADE,
db_column="rowid",
),
),
("title", models.TextField()),
("body", models.TextField(null=True)),
("autocomplete", models.TextField(null=True)),
],
options={"db_table": "%s_fts" % IndexEntry._meta.db_table},
),
],
database_operations=[
migrations.RunSQL(
sql=(
"CREATE VIRTUAL TABLE %s_fts USING fts5(autocomplete, body, title)"
% IndexEntry._meta.db_table
),
reverse_sql=(
"DROP TABLE IF EXISTS %s_fts"
% IndexEntry._meta.db_table
),
),
migrations.RunSQL(
sql=(
"CREATE TRIGGER insert_wagtailsearch_indexentry_fts AFTER INSERT ON %s BEGIN INSERT INTO %s_fts(title, body, autocomplete, rowid) VALUES (NEW.title, NEW.body, NEW.autocomplete, NEW.id); END"
% (IndexEntry._meta.db_table, IndexEntry._meta.db_table)
),
reverse_sql=(
"DROP TRIGGER IF EXISTS insert_wagtailsearch_indexentry_fts"
),
),
migrations.RunSQL(
sql=(
"CREATE TRIGGER update_wagtailsearch_indexentry_fts AFTER UPDATE ON %s BEGIN UPDATE %s_fts SET title=NEW.title, body=NEW.body, autocomplete=NEW.autocomplete WHERE rowid=NEW.id; END"
% (IndexEntry._meta.db_table, IndexEntry._meta.db_table)
),
reverse_sql=(
"DROP TRIGGER IF EXISTS update_wagtailsearch_indexentry_fts"
),
),
migrations.RunSQL(
sql=(
"CREATE TRIGGER delete_wagtailsearch_indexentry_fts AFTER DELETE ON %s BEGIN DELETE FROM %s_fts WHERE rowid=OLD.id; END"
% (IndexEntry._meta.db_table, IndexEntry._meta.db_table)
),
reverse_sql=(
"DROP TRIGGER IF EXISTS delete_wagtailsearch_indexentry_fts"
),
),
],
)
)
elif connection.vendor == "mysql":
operations = [
migrations.AddField(
model_name="indexentry",
name="autocomplete",
field=models.TextField(null=True),
),
migrations.AddField(
model_name="indexentry",
name="body",
field=models.TextField(null=True),
),
migrations.AddField(
model_name="indexentry",
name="title",
field=models.TextField(default=""),
preserve_default=False,
),
]
# Create FULLTEXT indexes
# We need to add these indexes manually because Django imposes an artificial limitation
# that forces to specify the max length of the TextFields that get referenced by the
# FULLTEXT index. If we do it manually, it works, because Django can't check that we are
# defining a new index.
operations.append(
migrations.RunSQL(
sql="""
ALTER TABLE wagtailsearch_indexentry
ADD FULLTEXT INDEX `fulltext_body` (`body`)
""",
reverse_sql="""
ALTER TABLE wagtailsearch_indexentry
DROP INDEX `fulltext_body`
""",
)
)
# We create two separate FULLTEXT indexes for the 'body' and 'title' columns, so that we are able to handle them separately afterwards.
# We handle them separately, for example, when we do scoring: there, we multiply the 'title' score by the value of the 'title_norm' column. This can't be done if we index 'title' and 'body' in the same index, because MySQL doesn't allow to search on subparts of a defined index (we need to search all the columns of the index at the same time).
operations.append(
migrations.RunSQL(
sql="""
ALTER TABLE wagtailsearch_indexentry
ADD FULLTEXT INDEX `fulltext_title` (`title`)
""",
reverse_sql="""
ALTER TABLE wagtailsearch_indexentry
DROP INDEX `fulltext_title`
""",
)
)
# We also need to create a joint index on 'title' and 'body', to be able to query both at the same time. If we don't have this, some queries may return wrong results. For example, if we match 'A AND (NOT B)' against 'A, B', it returns false, but if we do (match 'A AND (NOT B)' against 'A') or (match 'A AND (NOT B)' against 'B'), the first one would return True, and the whole expression would be True (wrong result). That's the same as saying that testing subsets does not necessarily produce the same result as testing the whole set.
operations.append(
migrations.RunSQL(
sql="""
ALTER TABLE wagtailsearch_indexentry
ADD FULLTEXT INDEX `fulltext_title_body` (`title`, `body`)
""",
reverse_sql="""
ALTER TABLE wagtailsearch_indexentry
DROP INDEX `fulltext_title_body`
""",
)
)
# We use an ngram parser for autocomplete, so that it matches partial search queries.
# The index on body and title doesn't match partial queries by default.
# Note that this is not supported on MariaDB. See https://jira.mariadb.org/browse/MDEV-10267
if connection.mysql_is_mariadb:
operations.append(
migrations.RunSQL(
sql="""
ALTER TABLE wagtailsearch_indexentry
ADD FULLTEXT INDEX `fulltext_autocomplete` (`autocomplete`)
""",
reverse_sql="""
ALTER TABLE wagtailsearch_indexentry
DROP INDEX `fulltext_autocomplete`
""",
)
)
else:
operations.append(
migrations.RunSQL(
sql="""
ALTER TABLE wagtailsearch_indexentry
ADD FULLTEXT INDEX `fulltext_autocomplete` (`autocomplete`)
WITH PARSER ngram
""",
reverse_sql="""
ALTER TABLE wagtailsearch_indexentry
DROP INDEX `fulltext_autocomplete`
""",
)
)

View File

@@ -0,0 +1,24 @@
# Generated by Django 4.0.7 on 2022-10-10 17:53
from django.db import migrations
class DeleteModelIfExists(migrations.DeleteModel):
def database_forwards(self, app_label, schema_editor, from_state, to_state):
model = from_state.apps.get_model(app_label, self.name)
table_name = model._meta.db_table
if table_name in schema_editor.connection.introspection.table_names():
super().database_forwards(app_label, schema_editor, from_state, to_state)
class Migration(migrations.Migration):
dependencies = [
("wagtailsearch", "0006_customise_indexentry"),
]
operations = [
DeleteModelIfExists(
name="EditorsPick",
),
]

View File

@@ -0,0 +1,27 @@
# Generated by Django 4.2.6 on 2023-10-27 18:03
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("wagtailsearch", "0007_delete_editorspick"),
]
operations = [
migrations.AlterUniqueTogether(
name="querydailyhits",
unique_together=None,
),
migrations.RemoveField(
model_name="querydailyhits",
name="query",
),
migrations.DeleteModel(
name="Query",
),
migrations.DeleteModel(
name="QueryDailyHits",
),
]