Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add media properties generation (#3620)

Olga Bulat5041280d482b
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index b64cfc4c5..9557c93e5 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -327,9 +327,10 @@ jobs:
run_id: ${{ github.run_id }}
setup_images: upstream_db catalog
- - name: Check DAG documentation
+ - name: Check generated documentation
run: |
- just catalog/generate-dag-docs true
+ just catalog/generate-docs dag true
+ just catalog/generate-docs media-props true
####################
# Ingestion server #
diff --git a/.prettierignore b/.prettierignore
index 12be1ee97..ed30bc228 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -2,6 +2,10 @@
.github/**/*.md
.github/CODEOWNERS
+# Documentation
+# This file is linted when created, but the hr elements are replaced for correct rendering.
+documentation/meta/media_properties/catalog.md
+
# Frontend
frontend/test/unit/coverage
frontend/test/tapes
diff --git a/catalog/justfile b/catalog/justfile
index 9eb7985b8..1f0f713d9 100644
--- a/catalog/justfile
+++ b/catalog/justfile
@@ -120,24 +120,51 @@ test *args:
# Utilities #
#############
-# Generate the DAG documentation
-generate-dag-docs fail_on_diff="false":
+# Generate the documentation (either "dag" or "media-props")
+generate-docs doc="dag" fail_on_diff="false":
#!/bin/bash
set -e
+ if [ "{{ doc }}" == "dag" ]; then
+ SCRIPT_PATH="catalog/utilities/dag_doc_gen/dag_doc_generation.py"
+ GENERATED_REL_PATH="utilities/dag_doc_gen/DAGs.md"
+ FINAL_FILE="documentation/catalog/reference/DAGs.md"
+ NAME="DAG"
+ elif [ "{{ doc }}" == "media-props" ]; then
+ SCRIPT_PATH="catalog/utilities/media_props_gen/generate_media_properties.py"
+ GENERATED_REL_PATH="utilities/media_props_gen/media_properties.md"
+ FINAL_FILE="documentation/meta/media_properties/catalog.md"
+ NAME="Media properties"
+ else
+ echo "Invalid documentation type specified, use \`dag\` or \`media-props\`. Exiting."
+ exit 1
+ fi
+ GENERATED_ABS_PATH="/opt/airflow/catalog/${GENERATED_REL_PATH}"
just ../run \
+ --volume {{ justfile_directory() }}/../docker:/opt/airflow/docker/ \
+ -e PYTHONPATH=/opt/airflow/catalog:/opt/airflow/catalog/dags \
{{ SERVICE }} \
- "bash -c 'python catalog/utilities/dag_doc_gen/dag_doc_generation.py && chmod 666 /opt/airflow/catalog/utilities/dag_doc_gen/DAGs.md'"
- # Move the file to the top level on the documentation folder, since that level is not mounted into the container
- mv utilities/dag_doc_gen/DAGs.md ../documentation/catalog/reference/DAGs.md
+ "bash -c 'python $SCRIPT_PATH && chmod 666 $GENERATED_ABS_PATH'"
+ TEMP="documentation/meta/temp"
+ mv ../catalog/$GENERATED_REL_PATH ../$TEMP.md
+ echo "Moved the generated file to ../$TEMP.md"
echo -n "Running linting..."
# Linting step afterwards is necessary since the generated output differs greatly from what prettier expects
- just ../lint prettier documentation/catalog/reference/DAGs.md &>/dev/null || true
- echo "Done!"
+ just ../lint prettier $TEMP.md &>/dev/null || true
+ echo "Linting done!"
+
+ if [ "{{ doc }}" == "media-props" ]; then
+ echo -n "Replacing linted md <hr> '---' with '----' required by sphinx..."
+ sed 's/^---$/----/' "../$TEMP.md" > "../$TEMP.tmp"
+ mv "../$TEMP.tmp" "../$TEMP.md"
+ echo "Replacements done!"
+ fi
+ mv ../$TEMP.md ../$FINAL_FILE
+ echo "Moved the generated file to ../$FINAL_FILE"
if {{ fail_on_diff }}; then
set +e
- git diff --exit-code -- ../documentation/catalog/reference/DAGs.md
+ git diff --exit-code -- ../$FINAL_FILE
if [ $? -ne 0 ]; then
- printf "\n\n\e[31m!! Changes found in DAG documentation, please run 'just generate-dag-docs' locally and commit difference !!\n\n"
+ printf "\n\n\e[31m!! Changes found in $NAME documentation, please run 'just catalog/generate-docs {{ doc }}' locally and commit difference !!\n\n"
exit 1
fi
fi
diff --git a/catalog/tests/utilities/media_props_gen/test_column_parser.py b/catalog/tests/utilities/media_props_gen/test_column_parser.py
new file mode 100644
index 000000000..754b10979
--- /dev/null
+++ b/catalog/tests/utilities/media_props_gen/test_column_parser.py
@@ -0,0 +1,69 @@
+import pytest
+
+from utilities.media_props_gen.helpers.column_parser import (
+ COLUMN_DEFINITIONS,
+ Column,
+)
+
+
+ "init_args,expected_nullable,expected_str",
+ [
+ pytest.param(
+ {"required": True, "python_type": "URLColumn"},
+ False,
+ f"{COLUMN_DEFINITIONS['URLColumn']} (`upsert_strategy=newest_non_null, nullable=False, required=True`)",
+ id="required=True sets nullable to False",
+ ),
+ pytest.param(
+ {"required": False, "python_type": "StringColumn"},
+ True,
+ f"{COLUMN_DEFINITIONS['StringColumn']} (`upsert_strategy=newest_non_null, nullable=True, required=False`)",
+ id="required=False sets nullable to True",
+ ),
+ pytest.param(
+ {"name": "id", "db_name": "user_id", "python_type": "IntegerColumn"},
+ True,
+ f'{COLUMN_DEFINITIONS["IntegerColumn"]} '
+ f'(`name="id", upsert_strategy=newest_non_null, nullable=True, required=False`)',
+ id="name and db_name are different",
+ ),
+ pytest.param(
+ {"name": "id", "python_type": "StringColumn"},
+ True,
+ f"{COLUMN_DEFINITIONS['StringColumn']} (`upsert_strategy=newest_non_null, nullable=True, required=False`)",
+ id="default upsert strategy",
+ ),
+ pytest.param(
+ {
+ "name": "genres",
+ "python_type": "ArrayColumn",
+ "required": False,
+ "base_column": "StringColumn",
+ },
+ True,
+ f"{COLUMN_DEFINITIONS['ArrayColumn']} "
+ f"(`upsert_strategy=merge_array, base_column=StringColumn, nullable=True, required=False`)",
+ id="base_column",
+ ),
+ pytest.param(
+ {
+ "name": "audio_set",
+ "required": False,
+ "python_type": "JSONColumn",
+ "upsert_strategy": "merge_jsonb_arrays",
+ },
+ True,
+ f"{COLUMN_DEFINITIONS['JSONColumn']} (`upsert_strategy=merge_jsonb_arrays, nullable=True, required=False`)",
+ id="JSONColumn",
+ ),
+ ],
+)
+def test_column(init_args, expected_nullable, expected_str):
+ column = Column(**init_args)
+ assert (
+ column.nullable == expected_nullable
+ ), "Nullable attribute did not match expected value"
+ assert (
+ str(column) == expected_str
+ ), "__str__ representation did not match expected value"
diff --git a/catalog/tests/utilities/media_props_gen/test_db.py b/catalog/tests/utilities/media_props_gen/test_db.py
new file mode 100644
index 000000000..fbf29a329
--- /dev/null
+++ b/catalog/tests/utilities/media_props_gen/test_db.py
@@ -0,0 +1,90 @@
+import pytest
+
+from utilities.media_props_gen.helpers.db import (
+ FieldSqlInfo,
+ get_table_description_matches,
+ parse_field,
+)
+
+
+ "field_input,expected_output",
+ [
+ pytest.param(
+ "id integer NOT NULL",
+ FieldSqlInfo(name="id", nullable=False, datatype="integer", constraint=""),
+ id="integer not null",
+ ),
+ pytest.param(
+ "active boolean",
+ FieldSqlInfo(
+ name="active", nullable=True, datatype="boolean", constraint=""
+ ),
+ id="boolean nullable",
+ ),
+ pytest.param(
+ "user_id uuid[]",
+ FieldSqlInfo(
+ name="user_id", nullable=True, datatype="array of uuid", constraint=""
+ ),
+ id="array of uuid",
+ ),
+ pytest.param(
+ "payload jsonb NOT NULL",
+ FieldSqlInfo(
+ name="payload", nullable=False, datatype="jsonb", constraint=""
+ ),
+ id="jsonb not null",
+ ),
+ pytest.param(
+ "created_at timestamp with time zone",
+ FieldSqlInfo(
+ name="created_at",
+ nullable=True,
+ datatype="timestamp with time zone",
+ constraint="",
+ ),
+ id="timestamp with time zone",
+ ),
+ pytest.param(
+ "name character varying(255) NOT NULL",
+ FieldSqlInfo(
+ name="name",
+ nullable=False,
+ datatype="character varying",
+ constraint="(255)",
+ ),
+ id="character varying with constraint",
+ ),
+ pytest.param("invalid_field not_a_type", None, id="invalid type"),
+ ],
+)
+def test_parse_field(field_input, expected_output):
+ assert parse_field(field_input) == expected_output
+
+
+# Example SQL statements for testing
+sql_for_image = "CREATE TABLE public.image (id SERIAL PRIMARY KEY, name VARCHAR(255));"
+sql_for_audio = "CREATE TABLE public.audio (id SERIAL PRIMARY KEY, title VARCHAR(255));"
+non_matching_sql = (
+ "CREATE TABLE public.video (id SERIAL PRIMARY KEY, description TEXT);"
+)
+no_table_sql = "This is not a SQL create table statement."
+
+
+ "media_type,sql_text,expected_table_name",
+ [
+ ("image", sql_for_image, "image"),
+ ("audio", sql_for_audio, "audio"),
+ ("image", non_matching_sql, None),
+ ("audio", no_table_sql, None),
+ ],
+)
+def test_get_table_description_matches(media_type, sql_text, expected_table_name):
+ result = get_table_description_matches(sql_text, media_type)
+ if expected_table_name:
+ assert result is not None
+ assert result.group(1) == expected_table_name
+ else:
+ assert result is None
diff --git a/catalog/tests/utilities/media_props_gen/test_generate_media_properties.py b/catalog/tests/utilities/media_props_gen/test_generate_media_properties.py
new file mode 100644
index 000000000..86eedbd5f
--- /dev/null
+++ b/catalog/tests/utilities/media_props_gen/test_generate_media_properties.py
@@ -0,0 +1,118 @@
+from unittest.mock import patch
+
+import pytest
+
+from utilities.media_props_gen.generate_media_properties import (
+ generate_db_props_string,
+ generate_markdown_doc,
+)
+from utilities.media_props_gen.helpers.db import FieldSqlInfo
+
+
+DIRECTORY = "utilities.media_props_gen"
+MODULE = f"{DIRECTORY}.generate_media_properties"
+
+# Sample mock data
+markdown_descriptions_mock = "Markdown Descriptions"
+tables_mock = {"image": "Image Table Markdown", "audio": "Audio Table Markdown"}
+long_form_doc_mock = "Long Form Documentation Mock"
+
+
+def props_source_mock():
+ with patch(
+ f"{MODULE}.parse_props_from_source",
+ return_value=(markdown_descriptions_mock, tables_mock, long_form_doc_mock),
+ ) as mock:
+ yield mock
+
+
+def test_generate_markdown_doc(props_source_mock):
+ preamble_mock = "Preamble Content"
+ postamble_mock = "Postamble Content"
+
+ with patch(f"{MODULE}.PREAMBLE", preamble_mock), patch(
+ f"{MODULE}.POSTAMBLE", postamble_mock
+ ):
+ result = generate_markdown_doc()
+
+ expected_result = f"""{preamble_mock}
+## Image Properties\n{tables_mock["image"]}
+## Audio Properties\n{tables_mock["audio"]}
+## Media Property Descriptions\n{long_form_doc_mock}\n
+----\n\n{postamble_mock}\n"""
+
+ assert result == expected_result
+
+
+ "field,expected_output",
+ [
+ pytest.param(
+ FieldSqlInfo(
+ name="identifier", nullable=False, datatype="uuid", constraint=""
+ ),
+ ("identifier", "uuid, non-nullable"),
+ id="uuid_non_nullable",
+ ),
+ pytest.param(
+ FieldSqlInfo(
+ name="created_on",
+ nullable=False,
+ datatype="timestamp with time zone",
+ constraint="",
+ ),
+ ("created_on", "timestamp with time zone, non-nullable"),
+ id="timestamp_non_nullable",
+ ),
+ pytest.param(
+ FieldSqlInfo(
+ name="ingestion_type",
+ nullable=True,
+ datatype="character varying",
+ constraint="(80)",
+ ),
+ ("ingestion_type", "character varying (80), nullable"),
+ id="varchar_nullable_with_constraint",
+ ),
+ pytest.param(
+ FieldSqlInfo(
+ name="url",
+ nullable=False,
+ datatype="character varying",
+ constraint="(3000)",
+ ),
+ ("url", "character varying (3000), non-nullable"),
+ id="varchar_non_nullable_with_constraint",
+ ),
+ pytest.param(
+ FieldSqlInfo(
+ name="meta_data", nullable=True, datatype="jsonb", constraint=""
+ ),
+ ("meta_data", "jsonb, nullable"),
+ id="jsonb_nullable",
+ ),
+ pytest.param(
+ FieldSqlInfo(
+ name="watermarked", nullable=True, datatype="boolean", constraint=""
+ ),
+ ("watermarked", "boolean, nullable"),
+ id="boolean_nullable",
+ ),
+ pytest.param(
+ FieldSqlInfo(
+ name="standardized_popularity",
+ nullable=True,
+ datatype="double precision",
+ constraint="",
+ ),
+ ("standardized_popularity", "double precision, nullable"),
+ id="double_precision_nullable",
+ ),
+ ],
+)
+def test_generate_db_props_string(field, expected_output):
+ expected_column, expected_props = expected_output
+ field_name, props_string = generate_db_props_string(field)
+ assert field_name == f"[`{expected_column}`](#{expected_column})"
+ assert props_string == expected_props
diff --git a/catalog/tests/utilities/media_props_gen/test_md.py b/catalog/tests/utilities/media_props_gen/test_md.py
new file mode 100644
index 000000000..2831a4426
--- /dev/null
+++ b/catalog/tests/utilities/media_props_gen/test_md.py
@@ -0,0 +1,40 @@
+import pytest
+
+from utilities.media_props_gen.helpers.md import Md
+
+
+ "input_text,expected_output",
+ [
+ pytest.param(
+ "# Title\n## Prop1\nContent1\n## Prop2\nContent2",
+ {"Title": {"Prop1": "Content1", "Prop2": "Content2"}},
+ id="Basic Functionality",
+ ),
+ pytest.param("", {}, id="Empty Input"),
+ pytest.param("Just some text without headers.", {}, id="No Headers"),
+ pytest.param("# Title", {}, id="Single Header Only"),
+ pytest.param(
+ "# Title\nJust some standalone content.\n# Title1\n## Prop1\nContent1",
+ {"Title1": {"Prop1": "Content1"}},
+ id="Missing Subheaders",
+ ),
+ pytest.param(
+ "# Title\n## Prop\nLine 1\nLine 2",
+ {"Title": {"Prop": "Line 1Line 2"}},
+ id="Multiple Lines per Property",
+ ),
+ pytest.param(
+ "# Title\n\n## Prop\nContent\n\n",
+ {"Title": {"Prop": "Content"}},
+ id="Whitespace Lines Are Ignored",
+ ),
+ pytest.param(
+ "# Title \n## Prop \nContent ",
+ {"Title": {"Prop": "Content"}},
+ id="Trailing Whitespace in lines",
+ ),
+ ],
+)
+def test_parse(input_text, expected_output):
+ assert Md.parse(input_text) == expected_output
diff --git a/catalog/utilities/media_props_gen/__init__.py b/catalog/utilities/media_props_gen/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/catalog/utilities/media_props_gen/docs/media_props.md b/catalog/utilities/media_props_gen/docs/media_props.md
new file mode 100644
index 000000000..9553720a4
--- /dev/null
+++ b/catalog/utilities/media_props_gen/docs/media_props.md
@@ -0,0 +1,425 @@
+# identifier
+
+## Description
+
+The unique UUID identifier for the media item.
+
+## Object Shape
+
+UUID
+
+## Selection Criteria
+
+Created when the item is inserted into the main table.
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# created_on
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# updated_on
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# ingestion_type
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# provider
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# source
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# foreign_identifier
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# foreign_landing_url
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# url
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# thumbnail
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# width
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# height
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# filesize
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# license
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# license_version
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# creator
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# creator_url
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# title
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# meta_data
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# tags
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# watermarked
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# last_synced_with_source
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# removed_from_source
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# filetype
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# category
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# standardized_popularity
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# duration
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# bit_rate
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# sample_rate
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# genres
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# alt_files
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# audio_set
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# audio_set_foreign_identifier
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# set_position
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
+
+# alt_files
+
+## Description
+
+## Object Shape
+
+## Selection Criteria
+
+## Normalization and Validation
+
+## Existing Data Inconsistencies
diff --git a/catalog/utilities/media_props_gen/docs/postamble.md b/catalog/utilities/media_props_gen/docs/postamble.md
new file mode 100644
index 000000000..e69de29bb
diff --git a/catalog/utilities/media_props_gen/docs/preamble.md b/catalog/utilities/media_props_gen/docs/preamble.md
new file mode 100644
index 000000000..3727f79ea
--- /dev/null
+++ b/catalog/utilities/media_props_gen/docs/preamble.md
@@ -0,0 +1,10 @@
+# Catalog Media Properties
+
+_This document is auto-generated from the source code in
+[/catalog/utilities/media_props_gen/generate_media_properties.py](https://github.com/WordPress/openverse/blob/main/catalog/utilities/media_props_gen/generate_media_properties.py)._
+
+This is a list of the media properties, with the descriptions of corresponding
+database columns and Python objects that are used to store and retrieve media
+data. The order of the properties corresponds to their order in the `image`
+table. Property names typically match those of the database columns, except when
+noted otherwise in the Python column's name property.
diff --git a/catalog/utilities/media_props_gen/generate_media_properties.py b/catalog/utilities/media_props_gen/generate_media_properties.py
new file mode 100644
index 000000000..29c6297aa
--- /dev/null
+++ b/catalog/utilities/media_props_gen/generate_media_properties.py
@@ -0,0 +1,147 @@
+"""Automatic media properties generation."""
+
+import logging
+from dataclasses import dataclass
+from pathlib import Path
+
+from common.constants import MEDIA_TYPES
+from utilities.media_props_gen.helpers.column_parser import parse_python_columns
+from utilities.media_props_gen.helpers.db import FieldSqlInfo, create_db_props_dict
+from utilities.media_props_gen.helpers.md import Md
+
+
+log = logging.getLogger(__name__)
+# Silence noisy modules
+logging.getLogger("common.storage.media").setLevel(logging.WARNING)
+
+# Constants
+DOCS = Path(__file__).parent / "docs"
+DOC_MD_PATH = Path(__file__).parent / "media_properties.md"
+SOURCE_MD_PATH = DOCS / "media_props.md"
+
+PREAMBLE = (DOCS / "preamble.md").read_text()
+POSTAMBLE = (DOCS / "postamble.md").read_text()
+
+
+@dataclass
+class FieldInfo:
+ name: str
+ nullable: bool
+ datatype: str
+ constraint: str
+ python_column: str = ""
+
+
+def generate_media_properties() -> dict:
+ """
+ Generate a dictionary documenting each property of the media items.
+ For each property, return the database field and the Python object shape.
+ """
+ media_props = {}
+ python_columns = parse_python_columns()
+
+ for media_type in MEDIA_TYPES:
+ media_props[media_type] = create_db_props_dict(media_type)
+
+ # Add the python column properties to the media properties dictionary
+ for prop in media_props[media_type].keys():
+ media_props[media_type][prop]["python_column"] = python_columns.get(
+ prop, ""
+ )
+
+ return media_props
+
+
+def generate_db_props_string(field: FieldSqlInfo) -> tuple[str, str]:
+ constraint = f"{' ' + field.constraint if field.constraint else ''}"
+ nullable = f"{'nullable' if field.nullable else 'non-nullable'}"
+ props_string = f"{field.datatype}{constraint}, {nullable}"
+
+ return f"[`{field.name}`](#{field.name})", props_string
+
+
+def generate_media_props_table(media_properties) -> str:
+ """Generate the markdown table with media properties."""
+
+ # Convert the list of FieldInfo objects to a md table
+ table = "| Name | DB Field | Python Column |\n"
+ table += "| --- | --- | --- |\n"
+ for field_name, field in media_properties.items():
+ name, db_properties = generate_db_props_string(field["sql"])
+
+ table += (
+ f"| {name} | {db_properties} | " f"{field.get('python_column', '')} |\n"
+ )
+ return table
+
+
+def generate_long_form_doc(markdown_descriptions: dict, media_properties: dict) -> str:
+ """
+ Generate the long-form markdown documentation for each media property.
+ Uses the markdown descriptions from the `media_props.md` source file.
+ Also uses `media_properties` dictionary to set which media types have
+ the specific properties.
+ """
+ prop_mds = []
+ for prop, description in markdown_descriptions.items():
+ prop_heading = f"{Md.heading(3, prop)}"
+
+ media_types = [
+ f"`{media_type}`"
+ for media_type, value in media_properties.items()
+ if prop in value.keys()
+ ]
+ prop_heading += f"_Media Types_: {', '.join(media_types)}\n\n"
+
+ prop_doc = "".join(
+ [f"{Md.heading(4, k)}{Md.line(v)}" for k, v in description.items() if v]
+ )
+ prop_mds += [prop_heading + prop_doc]
+ return Md.horizontal_line.join(prop_mds) + "\n"
+
+
+def parse_props_from_source() -> tuple[dict, dict, str]:
+ """Parse the media property descriptions from the source code and `media_props.md`"""
+ media_properties = generate_media_properties()
+ markdown_descriptions = Md.parse(SOURCE_MD_PATH.read_text())
+ tables = {}
+
+ for media_type in MEDIA_TYPES:
+ tables[media_type] = generate_media_props_table(media_properties[media_type])
+
+ long_form_doc = generate_long_form_doc(markdown_descriptions, media_properties)
+ return markdown_descriptions, tables, long_form_doc
+
+
+def generate_markdown_doc() -> str:
+ """
+ Parse the media property descriptions from the source code and `media_props.md`
+ Generate the tables with media properties database column and
+ Python objects characteristics, and a long-form documentation for each property.
+ """
+
+ markdown_descriptions, tables, long_form_doc = parse_props_from_source()
+
+ media_props_doc = (
+ f"""
+{PREAMBLE}
+{Md.heading(2, "Image Properties")}{tables["image"]}
+{Md.heading(2, "Audio Properties")}{tables["audio"]}
+{Md.heading(2, "Media Property Descriptions")}{long_form_doc}
+{Md.horizontal_line + POSTAMBLE if POSTAMBLE else ''}
+""".strip()
+ + "\n"
+ )
+
+ return media_props_doc
+
+
+def write_media_props_doc(path: Path = DOC_MD_PATH) -> None:
+ """Generate the DAG documentation and write it to a file."""
+ doc_text = generate_markdown_doc()
+ log.info(f"Writing doc to {path}")
+ path.write_text(doc_text)
+
+
+if __name__ == "__main__":
+ write_media_props_doc()
diff --git a/catalog/utilities/media_props_gen/helpers/__init__.py b/catalog/utilities/media_props_gen/helpers/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/catalog/utilities/media_props_gen/helpers/column_parser.py b/catalog/utilities/media_props_gen/helpers/column_parser.py
new file mode 100644
index 000000000..57e1c2521
--- /dev/null
+++ b/catalog/utilities/media_props_gen/helpers/column_parser.py
@@ -0,0 +1,130 @@
+import ast
+import dataclasses
+from dataclasses import dataclass
+from pathlib import Path
+
+
+COLUMNS_PATH = Path(__file__).parents[3] / "dags" / "common" / "storage" / "columns.py"
+
+COLUMNS_URL = "https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py" # noqa: E501
+
+CODE = ast.parse(COLUMNS_PATH.read_text())
+
+
+@dataclass
+class ColumnDefinition:
+ name: str
+ start_lineno: int
+ end_lineno: int
+
+ def __str__(self):
+ return f"[{self.name}]({COLUMNS_URL}#L{self.start_lineno}-L{self.end_lineno})"
+
+
+# Dictionary of all types of columns with their line numbers for hyperlinks
+COLUMN_DEFINITIONS = {
+ item.name: ColumnDefinition(
+ name=item.name, start_lineno=item.lineno, end_lineno=item.end_lineno
+ )
+ for item in ast.iter_child_nodes(CODE)
+ if isinstance(item, ast.ClassDef) and item.name.endswith("Column")
+}
+
+
+@dataclass
+class Column:
+ name: str | None = None
+ db_name: str | None = None
+ python_type: str | None = None
+ upsert_strategy: str | None = None
+ base_column: str | None = None
+ nullable: bool | None = None
+ required: bool = False
+
+ def __post_init__(self):
+ """
+ Set `nullable` value based on the value of `required`. If required is true,
+ then the media item is discarded if the column is null.
+ This mean that the column cannot have `None` as a value.
+ """
+ if self.nullable is None:
+ self.nullable = True if self.required is None else not self.required
+ if self.upsert_strategy is None:
+ if self.python_type == "JSONColumn":
+ self.upsert_strategy = "merge_jsonb_objects"
+ elif self.python_type == "ArrayColumn":
+ self.upsert_strategy = "merge_array"
+ else:
+ self.upsert_strategy = "newest_non_null"
+
+ def __str__(self):
+ name = (
+ f'name="{self.name}", '
+ if self.db_name and self.db_name != self.name
+ else ""
+ )
+ res = name + ", ".join(
+ [
+ f"{f}={v}"
+ for f in COLUMN_PROPS
+ if (v := getattr(self, f)) is not None
+ and f not in ["name", "db_name", "python_type"]
+ ]
+ )
+ return f"{COLUMN_DEFINITIONS[self.python_type]} (`{res}`)"
+
+
+COLUMN_PROPS = [field.name for field in dataclasses.fields(Column)]
+
+
+def parse_col_argument_value(item):
+ """
+ Return `attr` for Attribute value (upsert strategies), `func.id` for Call value (base_column),
+ and `value` for Constant values such as `true`.
+ We don't save the List type used for sql_args.
+ """
+ # Upsert strategy
+ if isinstance(item, ast.Attribute) and isinstance(item.value, ast.Name):
+ return item.attr
+ # Base column
+ elif isinstance(item, ast.Call) and isinstance(item.func, ast.Name):
+ return item.func.id
+ elif isinstance(item, ast.Constant):
+ return item.value
+ return item.value
+
+
+def parse_python_columns() -> dict[str, any]:
+ """
+ Parse columns.py to a dictionary with the column's `db_name` as a key,
+ and the string describing Python column as a value.
+ Example output:
+ "height": "[IntegerColumn](/link/to/column/type/definition/)" +
+ "(`name="height", nullable=True, required=False, upsert_strategy=newest_non_null`)"
+ """
+ # Extracts all the assignments of the form `column_name = <Type>Column(...)`
+ cols: list[tuple[str, ast.Call]] = [
+ (item.value.func.id, item.value)
+ for item in ast.iter_child_nodes(CODE)
+ if isinstance(item, ast.Assign)
+ and isinstance(item.value, ast.Call)
+ and isinstance(item.value.func, ast.Name)
+ and item.value.func.id.endswith("Column")
+ and item.value.func.id != "Column"
+ ]
+
+ columns = {}
+ for col_python_type, col in cols:
+ parsed_column = Column(
+ python_type=col_python_type,
+ **{
+ col.arg: parse_col_argument_value(col.value)
+ for col in col.keywords
+ if col.arg in COLUMN_PROPS
+ },
+ )
+
+ db_name = parsed_column.db_name or parsed_column.name
+ columns[db_name] = f"{parsed_column}"
+
+ return columns
diff --git a/catalog/utilities/media_props_gen/helpers/db.py b/catalog/utilities/media_props_gen/helpers/db.py
new file mode 100644
index 000000000..3d8cf01b5
--- /dev/null
+++ b/catalog/utilities/media_props_gen/helpers/db.py
@@ -0,0 +1,100 @@
+import logging
+import re
+from dataclasses import dataclass
+from pathlib import Path
+from typing import Any
+
+from common.constants import MediaType
+
+
+LOCAL_POSTGRES_FOLDER = Path(__file__).parents[4] / "docker" / "upstream_db"
+SQL_PATH = {
+ "image": LOCAL_POSTGRES_FOLDER / "0003_openledger_image_schema.sql",
+ "audio": LOCAL_POSTGRES_FOLDER / "0006_openledger_audio_schema.sql",
+}
+SQL_TYPES = [
+ "integer",
+ "boolean",
+ "uuid",
+ "double precision",
+ "jsonb",
+ "timestamp with time zone",
+ "character varying",
+]
+SQL_TYPE_REGEX = re.compile(f"({'|'.join(SQL_TYPES)})")
+CREATE_TABLE_REGEX = re.compile(r"CREATE\s+TABLE\s+\w+\.(\w+)\s+\(([\s\S]*?)\);")
+
+
+@dataclass
+class FieldSqlInfo:
+ name: str
+ nullable: bool
+ datatype: str
+ constraint: str
+
+
+def get_table_description_matches(
+ sql_file_contents: str, media_type: MediaType
+) -> re.Match[str] | None:
+ """
+ Return the table description matches for a given media type or None if
+ the table description could not be found or the table name is not `media_type`.
+ """
+ table_description_matches = CREATE_TABLE_REGEX.search(sql_file_contents)
+
+ if not table_description_matches:
+ logging.warning(f"Could not find table description for {media_type}")
+ return None
+ table_name = table_description_matches.group(1)
+ if table_name != media_type:
+ logging.warning(
+ f"Table name {table_name} does not match media type {media_type}"
+ )
+ return None
+ return table_description_matches
+
+
+def parse_field(field: str) -> FieldSqlInfo | None:
+ field_name = field.split(" ")[0]
+ field_constraint = ""
+ try:
+ field_type = SQL_TYPE_REGEX.search(field).group(1)
+ if field_type == "character varying":
+ char_limit = field.split("(")[1].split(")")[0]
+ field_constraint = f"({char_limit})"
+
+ if "[]" in field:
+ field_type = f"array of {field_type}"
+ except AttributeError:
+ logging.warning(f"Could not find type for field {field_name} in {field}")
+ return None
+
+ return FieldSqlInfo(
+ name=field_name,
+ nullable="NOT NULL" not in field,
+ datatype=field_type,
+ constraint=field_constraint,
+ )
+
+
+def create_db_props_dict(
+ media_type: MediaType,
+) -> dict[Any, Any] | dict[Any, dict[str, FieldSqlInfo]]:
+ """
+ Parse the DDL for a media type and returns a list of field
+ sql definitions.
+ """
+ sql_path = SQL_PATH[media_type]
+ logging.debug(f"Reading SQL file {sql_path}")
+
+ if not (matches := get_table_description_matches(sql_path.read_text(), media_type)):
+ return {}
+
+ field_descriptions = [
+ field.strip() for field in matches.group(2).split("\n") if field.strip()
+ ]
+ fields = {}
+ for field in field_descriptions:
+ if field_sql_info := parse_field(field):
+ fields[field_sql_info.name] = {"sql": field_sql_info}
+ return fields
diff --git a/catalog/utilities/media_props_gen/helpers/md.py b/catalog/utilities/media_props_gen/helpers/md.py
new file mode 100644
index 000000000..b542f5610
--- /dev/null
+++ b/catalog/utilities/media_props_gen/helpers/md.py
@@ -0,0 +1,44 @@
+class Md:
+ horizontal_line = "\n----\n\n"
+
+ @staticmethod
+ def heading(level: int, text: str) -> str:
+ """Add a heading to a markdown string."""
+ return f"{'#' * level} {text}\n"
+
+ @staticmethod
+ def line(text: str) -> str:
+ """Add a line to a markdown string."""
+ return f"{text}\n"
+
+ @staticmethod
+ def parse(text: str) -> dict[str, dict[str, str]]:
+ """
+ Parse the text content of the markdown documentation file and return a dictionary with the
+ field name as key and the description as value.
+ """
+ contents = [line for line in text.split("\n") if line.strip()]
+ current_field = ""
+ properties = {}
+ prop = ""
+ value = {}
+ for i, line in enumerate(contents):
+ if line.startswith("# "):
+ if current_field and value:
+ properties[current_field] = value
+ current_field = line.replace("# ", "").strip()
+ value = {}
+ elif line.startswith("## "):
+ if prop and prop in value:
+ value[prop] = value[prop].strip()
+ prop = line.replace("## ", "").strip()
+ value[prop] = ""
+ elif not prop:
+ continue
+ elif i == len(contents) - 1:
+ value[prop] = f"{value[prop]}{line}".strip()
+ properties[current_field] = value
+ else:
+ value[prop] += line
+
+ return properties
diff --git a/documentation/catalog/guides/quickstart.md b/documentation/catalog/guides/quickstart.md
index b30a089b0..6b0ac6319 100644
--- a/documentation/catalog/guides/quickstart.md
+++ b/documentation/catalog/guides/quickstart.md
@@ -186,7 +186,7 @@ just recreate
> **Note**: Any recipes or scripts which output files to the container's mounted
> volumes will need to be run as the root user. This can be done with the
> `DC_USER=root` environment variable for `just` recipes. For example, see the
-> [generate-dag-docs recipe](https://github.com/WordPress/openverse-catalog/blob/c9be67e483e49e9eda7cd21b52bcde8857cd3922/justfile#L126).
+> [generate-docs recipe](https://github.com/WordPress/openverse-catalog/blob/c9be67e483e49e9eda7cd21b52bcde8857cd3922/justfile#L124).
[justfile]: https://github.com/WordPress/openverse/blob/main/catalog/justfile
[dockercompose]:
diff --git a/documentation/meta/ci_cd/jobs/catalog.md b/documentation/meta/ci_cd/jobs/catalog.md
index 1617e87ca..ac5918e1e 100644
--- a/documentation/meta/ci_cd/jobs/catalog.md
+++ b/documentation/meta/ci_cd/jobs/catalog.md
@@ -17,7 +17,7 @@ for the catalog.
## `catalog-checks`
-Runs tests for the catalog using the `catalog/generate-dag-docs` recipe. The job
+Runs tests for the catalog using the `catalog/generate-docs` recipe. The job
runs inside a Docker container so Python does not need to be installed. However,
the job generates a new documentation page that must be linted, so
[`setup-env`](/meta/ci_cd/actions.md#setup-env) in invoked to set up Node.js and
diff --git a/documentation/meta/media_properties/catalog.md b/documentation/meta/media_properties/catalog.md
new file mode 100644
index 000000000..d136a6780
--- /dev/null
+++ b/documentation/meta/media_properties/catalog.md
@@ -0,0 +1,294 @@
+# Catalog Media Properties
+
+_This document is auto-generated from the source code in
+[/catalog/utilities/media_props_gen/generate_media_properties.py](https://github.com/WordPress/openverse/blob/main/catalog/utilities/media_props_gen/generate_media_properties.py)._
+
+This is a list of the media properties, with the descriptions of corresponding
+database columns and Python objects that are used to store and retrieve media
+data. The order of the properties corresponds to their order in the `image`
+table. Property names typically match those of the database columns, except when
+noted otherwise in the Python column's name property.
+
+## Image Properties
+
+| Name | DB Field | Python Column |
+| ----------------------------------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [`identifier`](#identifier) | uuid, nullable | [UUIDColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L500-L517) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`created_on`](#created_on) | timestamp with time zone, non-nullable | [TimestampColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L520-L547) (`upsert_strategy=no_change, nullable=False, required=True`) |
+| [`updated_on`](#updated_on) | timestamp with time zone, non-nullable | [TimestampColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L520-L547) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`ingestion_type`](#ingestion_type) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`provider`](#provider) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`source`](#source) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`foreign_identifier`](#foreign_identifier) | character varying (3000), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`foreign_landing_url`](#foreign_landing_url) | character varying (1000), nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`upsert_strategy=newest_non_null, nullable=True, required=True`) |
+| [`url`](#url) | character varying (3000), non-nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`thumbnail`](#thumbnail) | character varying (3000), nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`name="thumbnail_url", upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`width`](#width) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`height`](#height) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`filesize`](#filesize) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`license`](#license) | character varying (50), non-nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`name="license_", upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`license_version`](#license_version) | character varying (25), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`creator`](#creator) | character varying (2000), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`creator_url`](#creator_url) | character varying (2000), nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`title`](#title) | character varying (5000), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`meta_data`](#meta_data) | jsonb, nullable | [JSONColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L388-L454) (`upsert_strategy=merge_jsonb_objects, nullable=True, required=False`) |
+| [`tags`](#tags) | jsonb, nullable | [JSONColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L388-L454) (`upsert_strategy=merge_jsonb_arrays, nullable=True, required=False`) |
+| [`watermarked`](#watermarked) | boolean, nullable | [BooleanColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L340-L385) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`last_synced_with_source`](#last_synced_with_source) | timestamp with time zone, nullable | [TimestampColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L520-L547) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`removed_from_source`](#removed_from_source) | boolean, non-nullable | [BooleanColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L340-L385) (`upsert_strategy=false, nullable=False, required=True`) |
+| [`filetype`](#filetype) | character varying (5), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`category`](#category) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`standardized_popularity`](#standardized_popularity) | double precision, nullable | [CalculatedColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L259-L337) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+
+## Audio Properties
+
+| Name | DB Field | Python Column |
+| --------------------------------------------------------------- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [`identifier`](#identifier) | uuid, nullable | [UUIDColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L500-L517) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`created_on`](#created_on) | timestamp with time zone, non-nullable | [TimestampColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L520-L547) (`upsert_strategy=no_change, nullable=False, required=True`) |
+| [`updated_on`](#updated_on) | timestamp with time zone, non-nullable | [TimestampColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L520-L547) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`ingestion_type`](#ingestion_type) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`provider`](#provider) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`source`](#source) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`foreign_identifier`](#foreign_identifier) | character varying (3000), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`foreign_landing_url`](#foreign_landing_url) | character varying (1000), nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`upsert_strategy=newest_non_null, nullable=True, required=True`) |
+| [`url`](#url) | character varying (3000), non-nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`thumbnail`](#thumbnail) | character varying (3000), nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`name="thumbnail_url", upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`filetype`](#filetype) | character varying (5), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`duration`](#duration) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`bit_rate`](#bit_rate) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`sample_rate`](#sample_rate) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`category`](#category) | character varying (80), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`genres`](#genres) | array of character varying (80), nullable | [ArrayColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L599-L651) (`upsert_strategy=merge_array, base_column=StringColumn, nullable=True, required=False`) |
+| [`audio_set`](#audio_set) | jsonb, nullable | [JSONColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L388-L454) (`upsert_strategy=merge_jsonb_objects, nullable=True, required=False`) |
+| [`set_position`](#set_position) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`alt_files`](#alt_files) | jsonb, nullable | [JSONColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L388-L454) (`upsert_strategy=merge_jsonb_arrays, nullable=True, required=False`) |
+| [`filesize`](#filesize) | integer, nullable | [IntegerColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L216-L256) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`license`](#license) | character varying (50), non-nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`name="license_", upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`license_version`](#license_version) | character varying (25), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=False, required=True`) |
+| [`creator`](#creator) | character varying (2000), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`creator_url`](#creator_url) | character varying (2000), nullable | [URLColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L550-L596) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`title`](#title) | character varying (5000), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`meta_data`](#meta_data) | jsonb, nullable | [JSONColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L388-L454) (`upsert_strategy=merge_jsonb_objects, nullable=True, required=False`) |
+| [`tags`](#tags) | jsonb, nullable | [JSONColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L388-L454) (`upsert_strategy=merge_jsonb_arrays, nullable=True, required=False`) |
+| [`watermarked`](#watermarked) | boolean, nullable | [BooleanColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L340-L385) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`last_synced_with_source`](#last_synced_with_source) | timestamp with time zone, nullable | [TimestampColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L520-L547) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`removed_from_source`](#removed_from_source) | boolean, non-nullable | [BooleanColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L340-L385) (`upsert_strategy=false, nullable=False, required=True`) |
+| [`standardized_popularity`](#standardized_popularity) | double precision, nullable | [CalculatedColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L259-L337) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+| [`audio_set_foreign_identifier`](#audio_set_foreign_identifier) | character varying (1000), nullable | [StringColumn](https://github.com/WordPress/openverse/blob/main/catalog/dags/common/storage/columns.py#L457-L497) (`upsert_strategy=newest_non_null, nullable=True, required=False`) |
+
+## Media Property Descriptions
+
+### identifier
+
+_Media Types_: `audio`, `image`
+
+#### Description
+
+The unique UUID identifier for the media item.
+
+#### Object Shape
+
+UUID
+
+#### Selection Criteria
+
+Created when the item is inserted into the main table.
+
+----
+
+### created_on
+
+_Media Types_: `audio`, `image`
+
+----
+
+### updated_on
+
+_Media Types_: `audio`, `image`
+
+----
+
+### ingestion_type
+
+_Media Types_: `audio`, `image`
+
+----
+
+### provider
+
+_Media Types_: `audio`, `image`
+
+----
+
+### source
+
+_Media Types_: `audio`, `image`
+
+----
+
+### foreign_identifier
+
+_Media Types_: `audio`, `image`
+
+----
+
+### foreign_landing_url
+
+_Media Types_: `audio`, `image`
+
+----
+
+### url
+
+_Media Types_: `audio`, `image`
+
+----
+
+### thumbnail
+
+_Media Types_: `audio`, `image`
+
+----
+
+### width
+
+_Media Types_: `image`
+
+----
+
+### height
+
+_Media Types_: `image`
+
+----
+
+### filesize
+
+_Media Types_: `audio`, `image`
+
+----
+
+### license
+
+_Media Types_: `audio`, `image`
+
+----
+
+### license_version
+
+_Media Types_: `audio`, `image`
+
+----
+
+### creator
+
+_Media Types_: `audio`, `image`
+
+----
+
+### creator_url
+
+_Media Types_: `audio`, `image`
+
+----
+
+### title
+
+_Media Types_: `audio`, `image`
+
+----
+
+### meta_data
+
+_Media Types_: `audio`, `image`
+
+----
+
+### tags
+
+_Media Types_: `audio`, `image`
+
+----
+
+### watermarked
+
+_Media Types_: `audio`, `image`
+
+----
+
+### last_synced_with_source
+
+_Media Types_: `audio`, `image`
+
+----
+
+### removed_from_source
+
+_Media Types_: `audio`, `image`
+
+----
+
+### filetype
+
+_Media Types_: `audio`, `image`
+
+----
+
+### category
+
+_Media Types_: `audio`, `image`
+
+----
+
+### standardized_popularity
+
+_Media Types_: `audio`, `image`
+
+----
+
+### duration
+
+_Media Types_: `audio`
+
+----
+
+### bit_rate
+
+_Media Types_: `audio`
+
+----
+
+### sample_rate
+
+_Media Types_: `audio`
+
+----
+
+### genres
+
+_Media Types_: `audio`
+
+----
+
+### alt_files
+
+_Media Types_: `audio`
+
+----
+
+### audio_set
+
+_Media Types_: `audio`
+
+----
+
+### audio_set_foreign_identifier
+
+_Media Types_: `audio`
+
+----
+
+### set_position
+
+_Media Types_: `audio`
diff --git a/documentation/meta/media_properties/index.md b/documentation/meta/media_properties/index.md
index 220877201..8e346d228 100644
--- a/documentation/meta/media_properties/index.md
+++ b/documentation/meta/media_properties/index.md
@@ -6,6 +6,7 @@ Openverse stack.
```{toctree}
:titlesonly:
+catalog
api
frontend
```