0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 21:49:51 +01:00
posthog/bin/build-schema-python.sh
Michael Matloka 3ffa9acd75
fix(insights): HogQL calculation of saved legacy insights v3 (#21720)
* Revert "revert(insights): HogQL calculation of saved legacy insights v2 (#21718)"

This reverts commit 2f019a39ec.

* Fix `CACHE_ONLY` in place of `CALCULATION_ONLY_IF_STALE`

* Make `ExecutionMode` naming unmistakable

* Reset UI snapshots

* Account for #21707's `apply_dashboard_filters` change

* Make `QueryRunner` generic
2024-04-23 16:50:56 +02:00

29 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -e
# Generate schema.py from schema.json
datamodel-codegen \
--class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp \
--use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum \
--input frontend/src/queries/schema.json --input-file-type jsonschema \
--output posthog/schema.py --output-model-type pydantic_v2.BaseModel
# Format schema.py
ruff format posthog/schema.py
# Check schema.py and autofix
ruff check --fix posthog/schema.py
# HACK: Datamodel-codegen output for enum-type fields with a default is invalid the default value is a plain string,
# and not the expected enum member. We fix this using sed, which is pretty hacky, but does the job.
# Specifically, we need to replace `Optional[PropertyOperator] = "exact"`
# with `Optional[PropertyOperator] = PropertyOperator("exact")` to make the default value valid.
# Remove this when https://github.com/koxudaxi/datamodel-code-generator/issues/1929 is resolved.
if [[ "$OSTYPE" == "darwin"* ]]; then
# sed needs `-i` to be followed by `''` on macOS
sed -i '' -e 's/Optional\[PropertyOperator\] = \("[A-Za-z_]*"\)/Optional[PropertyOperator] = PropertyOperator(\1)/g' posthog/schema.py
else
sed -i -e 's/Optional\[PropertyOperator\] = \("[A-Za-z_]*"\)/Optional[PropertyOperator] = PropertyOperator(\1)/g' posthog/schema.py
fi