Skip to content

Commit 4ed721d

Browse files
authored
dev: swap create to update_or_create when inserting plans/tiers (#1120)
1 parent b27a23b commit 4ed721d

File tree

6 files changed

+35
-42
lines changed

6 files changed

+35
-42
lines changed

core/apps.py

-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22

33
from django.apps import AppConfig
4-
from django.core.management import call_command
54
from shared.helpers.cache import RedisBackend
65

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

20-
if RUN_ENV == "DEV":
21-
try:
22-
# Call your management command here
23-
call_command(
24-
"insert_data_to_db_from_csv",
25-
"core/management/commands/codecovTiers-Jan25.csv",
26-
"--model",
27-
"tiers",
28-
)
29-
call_command(
30-
"insert_data_to_db_from_csv",
31-
"core/management/commands/codecovPlans-Jan25.csv",
32-
"--model",
33-
"plans",
34-
)
35-
except Exception as e:
36-
logger.error(f"Failed to run startup command: {e}")
37-
3819
if RUN_ENV not in ["DEV", "TESTING"]:
3920
cache_backend = RedisBackend(get_redis_connection())
4021
cache.configure(cache_backend)

core/management/commands/codecovPlans-Jan25.csv

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
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,
33
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
44
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
5-
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-
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
7-
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
8-
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
9-
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
10-
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
5+
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+
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
7+
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
8+
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
9+
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
10+
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
1111
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,
1212
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,
1313
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,

core/management/commands/insert_data_to_db_from_csv.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ def handle(self, *args, **kwargs):
5151
)
5252
continue
5353

54-
Model.objects.create(**model_data)
55-
self.stdout.write(self.style.SUCCESS(f"Inserted row: {row}"))
54+
try:
55+
Model.objects.update_or_create(
56+
defaults=model_data,
57+
id=row.get("id"),
58+
)
59+
self.stdout.write(self.style.SUCCESS(f"Inserted row: {row}"))
60+
except Exception as e:
61+
self.stdout.write(self.style.ERROR(f"Error inserting row: {e}"))
62+
continue
5663

5764
self.stdout.write(
5865
self.style.SUCCESS(

dev.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

77
_start_gunicorn() {
88
if [ -n "$PROMETHEUS_MULTIPROC_DIR" ]; then
@@ -19,6 +19,8 @@ _start_gunicorn() {
1919
python manage.py migrate
2020
python manage.py migrate --database "timeseries" timeseries
2121
python manage.py pgpartition --yes --skip-delete
22+
python manage.py insert_data_to_db_from_csv core/management/commands/codecovTiers-Jan25.csv --model tiers
23+
python manage.py insert_data_to_db_from_csv core/management/commands/codecovPlans-Jan25.csv --model plans
2224
fi
2325
if [[ "$DEBUGPY" ]]; then
2426
pip install debugpy

requirements.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ freezegun
2525
google-cloud-pubsub
2626
gunicorn>=22.0.0
2727
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
28-
https://github.com/codecov/shared/archive/9235672f89d2810fcf8c37905f0645f8ac77f4d4.tar.gz#egg=shared
28+
https://github.com/codecov/shared/archive/abf6180de5cee3ac99b7fbf909bd82c7325063fd.tar.gz#egg=shared
2929
https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz
3030
idna>=3.7
3131
minio

requirements.txt

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# This file was autogenerated by uv via the following command:
2-
# uv pip compile requirements.in -o requirements.txt
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.12
3+
# by the following command:
4+
#
5+
# pip-compile requirements.in
6+
#
37
aiodataloader==0.4.0
48
# via -r requirements.in
59
amplitude-analytics==1.1.4
@@ -84,11 +88,11 @@ click-repl==0.2.0
8488
# via celery
8589
codecov-ribs==0.1.18
8690
# via shared
87-
codecovopentelem @ https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
91+
codecovopentelem @ https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz
8892
# via -r requirements.in
8993
colour==0.1.5
9094
# via shared
91-
coverage==7.5.1
95+
coverage[toml]==7.5.1
9296
# via
9397
# codecovopentelem
9498
# pytest-cov
@@ -166,7 +170,7 @@ filelock==3.0.12
166170
# via virtualenv
167171
freezegun==1.1.0
168172
# via -r requirements.in
169-
google-api-core==2.23.0
173+
google-api-core[grpc]==2.23.0
170174
# via
171175
# google-cloud-core
172176
# google-cloud-pubsub
@@ -191,7 +195,7 @@ google-crc32c==1.0.0
191195
# google-resumable-media
192196
google-resumable-media==2.7.2
193197
# via google-cloud-storage
194-
googleapis-common-protos==1.59.1
198+
googleapis-common-protos[grpc]==1.59.1
195199
# via
196200
# google-api-core
197201
# grpc-google-iam-v1
@@ -400,23 +404,19 @@ requests==2.32.3
400404
# google-cloud-storage
401405
# shared
402406
# stripe
403-
rfc3986==1.4.0
407+
rfc3986[idna2008]==1.4.0
404408
# via httpx
405409
rsa==4.7.2
406410
# via google-auth
407411
s3transfer==0.5.0
408412
# via boto3
409-
sentry-sdk==2.13.0
413+
sentry-sdk[celery]==2.13.0
410414
# via
411415
# -r requirements.in
412416
# shared
413417
setproctitle==1.1.10
414418
# via -r requirements.in
415-
setuptools==75.8.0
416-
# via
417-
# ddtrace
418-
# opentelemetry-instrumentation
419-
shared @ https://github.com/codecov/shared/archive/9235672f89d2810fcf8c37905f0645f8ac77f4d4.tar.gz#egg=shared
419+
shared @ https://github.com/codecov/shared/archive/abf6180de5cee3ac99b7fbf909bd82c7325063fd.tar.gz
420420
# via -r requirements.in
421421
simplejson==3.17.2
422422
# via -r requirements.in
@@ -499,3 +499,6 @@ zipp==3.19.2
499499
# via importlib-metadata
500500
zstandard==0.23.0
501501
# via shared
502+
503+
# The following packages are considered to be unsafe in a requirements file:
504+
# setuptools

0 commit comments

Comments
 (0)