def METHOD_NAME(
    repository: Repository,
    image_hash: str,
    current_state: Optional[SingerState],
    new_state: str,
):
    # Add a table to the new image with the new state
    repository.object_engine.create_table(
        schema=None,
        table=INGESTION_STATE_TABLE,
        schema_spec=INGESTION_STATE_SCHEMA,
        temporary=True,
    )
    # NB: new_state here is a JSON-serialized string, so we don't wrap it into psycopg2.Json()
    logging.info("Writing state: %s", new_state)
    repository.object_engine.run_sql(
        SQL("INSERT INTO pg_temp.{} (timestamp, state) VALUES(now(), %s)").format(
            Identifier(INGESTION_STATE_TABLE)
        ),
        (new_state,),
    )
    object_id = repository.objects.create_base_fragment(
        "pg_temp", INGESTION_STATE_TABLE, repository.namespace, table_schema=INGESTION_STATE_SCHEMA
    )
    # If the state exists already, overwrite it; otherwise, add new state table.
    if current_state:
        repository.objects.overwrite_table(
            repository,
            image_hash,
            INGESTION_STATE_TABLE,
            INGESTION_STATE_SCHEMA,
            [object_id],
        )
    else:
        repository.objects.register_tables(
            repository,
            [(image_hash, INGESTION_STATE_TABLE, INGESTION_STATE_SCHEMA, [object_id])],
        )