Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: swap create to update_or_create when inserting plans/tiers #1120

Merged
merged 7 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions core/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

from django.apps import AppConfig
from django.core.management import call_command
from shared.helpers.cache import RedisBackend

from services.redis_configuration import get_redis_connection
Expand All @@ -17,24 +16,6 @@ class CoreConfig(AppConfig):
def ready(self):
import core.signals # noqa: F401

if RUN_ENV == "DEV":
try:
# Call your management command here
call_command(
"insert_data_to_db_from_csv",
"core/management/commands/codecovTiers-Jan25.csv",
"--model",
"tiers",
)
call_command(
"insert_data_to_db_from_csv",
"core/management/commands/codecovPlans-Jan25.csv",
"--model",
"plans",
)
except Exception as e:
logger.error(f"Failed to run startup command: {e}")

if RUN_ENV not in ["DEV", "TESTING"]:
cache_backend = RedisBackend(get_redis_connection())
cache.configure(cache_backend)
12 changes: 6 additions & 6 deletions core/management/commands/codecovPlans-Jan25.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
10,2025-01-16 04:40:55.162 -0800,2025-01-24 11:33:46.043 -0800,0,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories""}",,true,Developer,,,false,users-trial,6,
9,2025-01-16 04:39:59.759 -0800,2025-01-24 11:34:10.038 -0800,10,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",annually,true,Enterprise Cloud,,,true,users-enterprisey,4,price_1LmjzwGlVGuVgOrkIwlM46EU
8,2025-01-16 04:39:15.877 -0800,2025-01-24 11:34:31.904 -0800,12,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",monthly,true,Enterprise Cloud,,,true,users-enterprisem,4,price_1LmjypGlVGuVgOrkzKtNqhwW
7,2025-01-16 04:38:12.544 -0800,2025-01-24 11:34:53.935 -0800,4,"{""Up to 10 users"",""Unlimited repositories"",""2500 private repo uploads"",""Patch coverage analysis""}",annually,true,Team,10,2500,true,users-teamy,2,price_1NrlXiGlVGuVgOrkgMTw5yno
6,2025-01-16 04:37:08.918 -0800,2025-01-24 11:35:15.346 -0800,5,"{""Up to 10 users"",""Unlimited repositories"",""2500 private repo uploads"",""Patch coverage analysis""}",monthly,true,Team,10,2500,true,users-teamm,2,price_1NqPKdGlVGuVgOrkm9OFvtz8
5,2025-01-16 04:35:34.152 -0800,2025-01-24 11:35:42.724 -0800,10,"{""Includes 5 seats"",""$10 per additional seat"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",annually,true,Sentry Pro,5,,true,users-sentryy,5,price_1MlYAYGlVGuVgOrke9SdbBUn
4,2025-01-16 04:34:33.867 -0800,2025-01-24 11:35:48.218 -0800,12,"{""Includes 5 seats"",""$10 per additional seat"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",monthly,true,Sentry Pro,5,,true,users-sentrym,5,price_1MlY9yGlVGuVgOrkHluurBtJ
3,2025-01-16 04:32:44.655 -0800,2025-01-24 11:36:09.660 -0800,10,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",annually,true,Pro,,,true,users-pr-inappy,3,price_1Gv2COGlVGuVgOrkuOYVLIj7
2,2025-01-16 04:30:42.897 -0800,2025-01-24 11:36:14.651 -0800,12,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",monthly,true,Pro,,,true,users-pr-inappm,3,price_1Gv2B8GlVGuVgOrkFnLunCgc
7,2025-01-16 04:38:12.544 -0800,2025-01-24 11:34:53.935 -0800,4,"{""Up to 10 users"",""Unlimited repositories"",""2500 private repo uploads"",""Patch coverage analysis""}",annually,true,Team,10,2500,true,users-teamy,2,price_1OCM2cGlVGuVgOrkMWUFjPFz
6,2025-01-16 04:37:08.918 -0800,2025-01-24 11:35:15.346 -0800,5,"{""Up to 10 users"",""Unlimited repositories"",""2500 private repo uploads"",""Patch coverage analysis""}",monthly,true,Team,10,2500,true,users-teamm,2,price_1OCM0gGlVGuVgOrkWDYEBtSL
5,2025-01-16 04:35:34.152 -0800,2025-01-24 11:35:42.724 -0800,10,"{""Includes 5 seats"",""$10 per additional seat"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",annually,true,Sentry Pro,5,,true,users-sentryy,5,price_1Mj1mMGlVGuVgOrkC0ORc6iW
4,2025-01-16 04:34:33.867 -0800,2025-01-24 11:35:48.218 -0800,12,"{""Includes 5 seats"",""$10 per additional seat"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",monthly,true,Sentry Pro,5,,true,users-sentrym,5,price_1Mj1kYGlVGuVgOrk7jucaZAa
3,2025-01-16 04:32:44.655 -0800,2025-01-24 11:36:09.660 -0800,10,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",annually,true,Pro,,,true,users-pr-inappy,3,plan_H6P16wij3lUuxg
2,2025-01-16 04:30:42.897 -0800,2025-01-24 11:36:14.651 -0800,12,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories"",""Priority Support""}",monthly,true,Pro,,,true,users-pr-inappm,3,plan_H6P3KZXwmAbqPS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are junk values/non-prod right? can you change those last 2 to have price_ instead of plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah they're legit values 😅 We need them to actually checkout with stripe locally / on stage

13,2025-01-23 14:25:04.793 -0800,2025-01-23 14:25:04.793 -0800,12,"{""Configurable # of users"",""Unlimited public repositories"",""Unlimited private repositories""}",,true,Github Marketplace,,,false,users,3,
12,2025-01-16 04:44:51.064 -0800,2025-01-24 11:33:14.405 -0800,0,"{""Up to 1 user"",""Unlimited public repositories"",""Unlimited private repositories""}",,true,Developer,1,250,false,users-developer,2,
11,2025-01-16 04:44:01.249 -0800,2025-01-24 11:33:28.532 -0800,0,"{""Up to 1 user"",""Unlimited public repositories"",""Unlimited private repositories""}",,true,Developer,1,250,false,users-basic,1,
Expand Down
11 changes: 9 additions & 2 deletions core/management/commands/insert_data_to_db_from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@
)
continue

Model.objects.create(**model_data)
self.stdout.write(self.style.SUCCESS(f"Inserted row: {row}"))
try:
Model.objects.update_or_create(
defaults=model_data,
id=row.get("id"),
)
self.stdout.write(self.style.SUCCESS(f"Inserted row: {row}"))
except Exception as e:
self.stdout.write(self.style.ERROR(f"Error inserting row: {e}"))
continue

Check warning on line 62 in core/management/commands/insert_data_to_db_from_csv.py

View check run for this annotation

Codecov Notifications / codecov/patch

core/management/commands/insert_data_to_db_from_csv.py#L60-L62

Added lines #L60 - L62 were not covered by tests

self.stdout.write(
self.style.SUCCESS(
Expand Down
4 changes: 3 additions & 1 deletion dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# starts the development server using gunicorn
# NEVER run production with the --reload option command
echo "Starting gunicorn in dev mode"
echo "API: Starting gunicorn in dev mode"

_start_gunicorn() {
if [ -n "$PROMETHEUS_MULTIPROC_DIR" ]; then
Expand All @@ -19,6 +19,8 @@ _start_gunicorn() {
python manage.py migrate
python manage.py migrate --database "timeseries" timeseries
python manage.py pgpartition --yes --skip-delete
python manage.py insert_data_to_db_from_csv core/management/commands/codecovTiers-Jan25.csv --model tiers
python manage.py insert_data_to_db_from_csv core/management/commands/codecovPlans-Jan25.csv --model plans
fi
if [[ "$DEBUGPY" ]]; then
pip install debugpy
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ freezegun
google-cloud-pubsub
gunicorn>=22.0.0
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
https://github.com/codecov/shared/archive/9235672f89d2810fcf8c37905f0645f8ac77f4d4.tar.gz#egg=shared
https://github.com/codecov/shared/archive/abf6180de5cee3ac99b7fbf909bd82c7325063fd.tar.gz#egg=shared
https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz
idna>=3.7
minio
Expand Down
29 changes: 16 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in -o requirements.txt
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements.in
#
aiodataloader==0.4.0
# via -r requirements.in
amplitude-analytics==1.1.4
Expand Down Expand Up @@ -84,11 +88,11 @@ click-repl==0.2.0
# via celery
codecov-ribs==0.1.18
# via shared
codecovopentelem @ https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
codecovopentelem @ https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz
# via -r requirements.in
colour==0.1.5
# via shared
coverage==7.5.1
coverage[toml]==7.5.1
# via
# codecovopentelem
# pytest-cov
Expand Down Expand Up @@ -166,7 +170,7 @@ filelock==3.0.12
# via virtualenv
freezegun==1.1.0
# via -r requirements.in
google-api-core==2.23.0
google-api-core[grpc]==2.23.0
# via
# google-cloud-core
# google-cloud-pubsub
Expand All @@ -191,7 +195,7 @@ google-crc32c==1.0.0
# google-resumable-media
google-resumable-media==2.7.2
# via google-cloud-storage
googleapis-common-protos==1.59.1
googleapis-common-protos[grpc]==1.59.1
# via
# google-api-core
# grpc-google-iam-v1
Expand Down Expand Up @@ -400,23 +404,19 @@ requests==2.32.3
# google-cloud-storage
# shared
# stripe
rfc3986==1.4.0
rfc3986[idna2008]==1.4.0
# via httpx
rsa==4.7.2
# via google-auth
s3transfer==0.5.0
# via boto3
sentry-sdk==2.13.0
sentry-sdk[celery]==2.13.0
# via
# -r requirements.in
# shared
setproctitle==1.1.10
# via -r requirements.in
setuptools==75.8.0
# via
# ddtrace
# opentelemetry-instrumentation
shared @ https://github.com/codecov/shared/archive/9235672f89d2810fcf8c37905f0645f8ac77f4d4.tar.gz#egg=shared
shared @ https://github.com/codecov/shared/archive/abf6180de5cee3ac99b7fbf909bd82c7325063fd.tar.gz
# via -r requirements.in
simplejson==3.17.2
# via -r requirements.in
Expand Down Expand Up @@ -499,3 +499,6 @@ zipp==3.19.2
# via importlib-metadata
zstandard==0.23.0
# via shared

# The following packages are considered to be unsafe in a requirements file:
# setuptools
Loading