-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add Default Organization Creation on API Startup #3232
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
Add Default Organization Creation on API Startup #3232
Conversation
WalkthroughThis pull request updates the organization-related functionality in two areas. In the organizations table schema, an optional Changes
Sequence Diagram(s)sequenceDiagram
participant SeedScript
participant Database
participant Logger
participant AdminQuery
SeedScript->>Database: Query organization with valid address
alt Organization Exists
Database-->>SeedScript: Return organization record
SeedScript->>Logger: Log "Creation skipped"
else No Organization Found
Database-->>SeedScript: Return no record
SeedScript->>AdminQuery: Query for administrator user
AdminQuery-->>SeedScript: Return admin user ID
SeedScript->>Database: Begin transaction: Insert default organization ("Unity Foundation USA")
Database-->>SeedScript: Organization inserted
SeedScript->>Database: Insert organization membership for admin user
Database-->>SeedScript: Membership record inserted
SeedScript->>Logger: Log success or encountered errors
end
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (8)
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #3232 +/- ##
====================================================
- Coverage 45.48% 45.44% -0.04%
====================================================
Files 455 455
Lines 33935 34008 +73
Branches 757 759 +2
====================================================
+ Hits 15435 15456 +21
- Misses 18496 18548 +52
Partials 4 4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
.devcontainer/devcontainer.json
(1 hunks)src/drizzle/tables/organizations.ts
(1 hunks)src/plugins/seedInitialData.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run tests for talawa api
- GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (2)
src/drizzle/tables/organizations.ts (1)
214-214
: Change looks good.
Making theid
an optional field aligns with the UUID default generation in the table definition and allows more flexibility when inserting records..devcontainer/devcontainer.json (1)
70-70
: Confirmwsl
usage for cross-platform compatibility.
Usingwsl cp
may not work in non-WSL environments. If you intend to support developers on other platforms, consider a more generic approach or confirm this command is strictly for WSL-based workflows.
await fastify.drizzleClient.transaction(async (tx) => { | ||
const organizationId = uuidv7(); | ||
|
||
const defaultOrganization = organizationsTableInsertSchema.parse({ | ||
id: organizationId, | ||
name: "Unity Foundation USA", | ||
description: "Service to the Community", | ||
addressLine1: "1268 Finwood Road", | ||
addressLine2: "Suite 200", | ||
city: "Dodge City", | ||
postalCode: "67801", | ||
state: "Kansas", | ||
avatarName: null, | ||
countryCode: "us", | ||
createdAt: new Date(), | ||
creatorId: adminUser.id, | ||
}); | ||
|
||
await tx.insert(organizationsTable).values(defaultOrganization); | ||
|
||
await tx.insert(organizationMembershipsTable).values({ | ||
memberId: adminUser.id, | ||
organizationId, | ||
role: "administrator", | ||
creatorId: adminUser.id, | ||
createdAt: new Date(), | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Address potential concurrency.
The check and insertion logic runs outside a strict upsert pattern. If multiple instances of the seeding logic run simultaneously, it can lead to multiple default organizations. Consider adding more robust constraints or an upsert-like transaction to ensure only one default is created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please make coderabbit.ai approves your work.
- Make sure all tests pass and are valid.
- Ensure the test code coverage for your patch reaches as close to 100% as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
Got it sir! I'll make sure coderabbit.ai approves the work, and I'll ensure all tests pass with near 100% coverage. |
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
Should I create a new file to write test cases? |
Yes we need tests. We can't afford to have this feature fail |
|
This pull request did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please verify it has no conflicts with the develop branch and rebase if needed. Mention it now if you need help or give permission to other people to finish your work. |
What kind of change does this PR introduce?
Added a check on API startup to create a default organization if none exists.
Issue Number:
#3168
Snapshots/Videos:


Does this PR introduce a breaking change?
No
Summary by CodeRabbit