Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Conversation

@ajay-sentry
Copy link
Contributor

@ajay-sentry ajay-sentry commented Jan 28, 2025

Purpose/Motivation

This PR aims to make it dead simple to integrate the new plans into the Codecov local development environment, and provide a bridge for self-hosted folks as well.

This is done through a new django command which can currently be run with a "tier" or "plan" flag in the form of

python manage.py insert_data_to_db_from_csv nameOfCSV --model plans (or tiers)

You can use the provided csvs that are in the same directory or your own CSV if you so choose. The CSVs that are in the codebase are the "current" plan and tier information for codecov. I was originally thinking we should obfuscate this stuff... but for now it doesn't really make sense to do that because it's all public information anyway lol

Anyway, on app start, both the tier and plan version of this command are run if you're on the dev environment. Assuming umbrella-hat is the default way for folks to run the app I figure this is probably going to provide an experience where no "breaking changes" are felt though they are present.

Links to relevant tickets

Epic: codecov/engineering-team#2778

Closes codecov/engineering-team#3286

What does this PR do?

Include a brief description of the changes in this PR. Bullet points are your friend.

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-staging
Copy link

codecov-staging bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 85.10638% with 7 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../management/commands/insert_data_to_db_from_csv.py 84.21% 6 Missing ⚠️
core/apps.py 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Contributor

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@codecov-public-qa
Copy link

codecov-public-qa bot commented Jan 28, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2713 1 2712 6
View the top 1 failed tests by shortest run time
core/tests/test_management_commands.py::::test_insert_data_to_db_from_csv_for_plans
Stack Traces | 0.013s run time
@pytest.mark.django_db
    def test_insert_data_to_db_from_csv_for_plans():
        # Create a temporary CSV file
        with tempfile.NamedTemporaryFile(mode="w", delete=False, newline="") as temp_csv:
            writer = csv.writer(temp_csv)
            writer.writerow(
                ["name", "marketing_name", "base_unit_price", "tier_id", "is_active"]
            )
            writer.writerow(["Plan A", "Marketing A", "100", "1", "true"])
            writer.writerow(["Plan B", "Marketing B", "200", "2", "false"])
            csv_path = temp_csv.name
    
        Tier.objects.create(tier_name="Tier 1")
        Tier.objects.create(tier_name="Tier 2")
    
        out = StringIO()
        call_command("insert_data_to_db_from_csv", csv_path, "--model", "plans", stdout=out)
    
        # Check the output
        assert "Successfully inserted all data into plans from CSV" in out.getvalue()
    
        print(Plan.objects.all())
        print(Tier.objects.all())
        print(Plan.objects.filter(name="Plan A").exists())
        print(Plan.objects.filter(name="Plan B").exists())
    
        # Verify the data was inserted correctly
>       assert Plan.objects.filter(name="Plan A").exists()
E       AssertionError: assert False
E        +  where False = <bound method QuerySet.exists of <QuerySet []>>()
E        +    where <bound method QuerySet.exists of <QuerySet []>> = <QuerySet []>.exists
E        +      where <QuerySet []> = <bound method QuerySet.filter of <django.db.models.manager.Manager object at 0x7f68b84b4980>>(name='Plan A')
E        +        where <bound method QuerySet.filter of <django.db.models.manager.Manager object at 0x7f68b84b4980>> = <django.db.models.manager.Manager object at 0x7f68b84b4980>.filter
E        +          where <django.db.models.manager.Manager object at 0x7f68b84b4980> = Plan.objects

core/tests/test_management_commands.py:157: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 85.10638% with 7 lines in your changes missing coverage. Please review.

Project coverage is 96.00%. Comparing base (e06c5d8) to head (97a3b39).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

@ajay-sentry ajay-sentry changed the title WIP - Django Command run on startup to add plans / tiers Feat: Django Command run on startup to add plans / tiers Jan 28, 2025
@@ -0,0 +1,14 @@
"id","created_at","updated_at","base_unit_price","benefits","billing_rate","is_active","marketing_name","max_seats","monthly_uploads_limit","paid_plan","name","tier_id","stripe_id"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jan 25 corresponds to January 2025

# Check the output
assert "Successfully inserted all data into plans from CSV" in out.getvalue()

print(Plan.objects.all())
Copy link
Contributor

Choose a reason for hiding this comment

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

🖨️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was debugging the failing test 😅, fixed!

def ready(self):
import core.signals # noqa: F401

if RUN_ENV == "DEV":
Copy link
Contributor

Choose a reason for hiding this comment

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

Remind me, what's the plan to seed prod then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

already seeded via Django Admin, and will be kept up to date there as well

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
Copy link
Contributor

Choose a reason for hiding this comment

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

sentryy unit price should be 10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might be missing something, I believe that's the case already :O

But I think you're right about pro plan being off users-pr-inappy having the incorrect price

@ajay-sentry ajay-sentry added this pull request to the merge queue Jan 29, 2025
Merged via the queue into main with commit ae83c2f Jan 29, 2025
14 of 17 checks passed
@ajay-sentry ajay-sentry deleted the Ajay/add-db-command-for-adding-plans-and-tiers branch January 29, 2025 20:24
@sentry
Copy link

sentry bot commented Feb 5, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ IntegrityError: duplicate key value violates unique constraint "codecov_auth_tier_pkey" core.management.commands.insert_data_to_db_from... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django Command for integrating new plans / tiers into local dev env

4 participants