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

Feat/terminate orga add orga id credit notes #3121

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ancorcruz
Copy link
Contributor

Context

This change makes it easier and more feasible to implement a mechanism for terminating an organization and deleting all its data. By explicitly associating CreditNote records with Organization, we improve data consistency and simplify tenant-scoped deletions.

Beyond the primary goal, this change also benefits the multi-tenant application in several ways:

  • Improves data integrity by making the organization-tenant relationship explicit.
  • Enables more efficient queries and filtering at the organization level.
  • Aligns CreditNote with other models that are already explicitly tied to Organization.

Description

  • Added an organization_id column to credit_notes, with an index and foreign key constraint.
  • Updated CreditNotes::CreateService to set organization_id when creating a CreditNote.
  • Refactored event tracking to reference credit_note.organization_id directly.
  • Updated specs to assert the presence of organization_id.

Impact

  • Existing CreditNote records will need backfilling (handled separately if needed).
  • Queries can now leverage organization_id for better performance.
  • Future work on organization deletion is now more straightforward.

Next up:

  • backfilling
  • marking the column not_null

@ancorcruz ancorcruz self-assigned this Jan 30, 2025
def change
add_reference :credit_notes, :organization, type: :uuid, index: {algorithm: :concurrently}

add_foreign_key :credit_notes, :organizations, validate: false
Copy link
Contributor

Choose a reason for hiding this comment

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

I think every statement needs to be its own migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, not sure about this, strong migrations has not complained so far.... why it needs to be in various migrations?

Copy link
Contributor

Choose a reason for hiding this comment

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

the reason would be to limit the amount of statements that are executed without transaction. I don't think it matters a lot, but I believe it's good practice to split the migration into multiple files :)

@ancorcruz ancorcruz marked this pull request as draft February 5, 2025 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants