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(user): Migrate user module to DML #10389

Merged
merged 5 commits into from
Dec 2, 2024
Merged

feat(user): Migrate user module to DML #10389

merged 5 commits into from
Dec 2, 2024

Conversation

adrien2p
Copy link
Member

@adrien2p adrien2p commented Dec 2, 2024

RESOLVES FRMW-2817
What
Migrate user to DML

@adrien2p adrien2p marked this pull request as ready for review December 2, 2024 10:30
Copy link

changeset-bot bot commented Dec 2, 2024

🦋 Changeset detected

Latest commit: 6212ab3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 65 packages
Name Type
@medusajs/user Minor
integration-tests-http Patch
@medusajs/medusa Minor
@medusajs/test-utils Minor
@medusajs/api-key Minor
@medusajs/auth Minor
@medusajs/cache-inmemory Minor
@medusajs/cache-redis Minor
@medusajs/cart Minor
@medusajs/currency Minor
@medusajs/customer Minor
@medusajs/event-bus-local Minor
@medusajs/event-bus-redis Minor
@medusajs/file Minor
@medusajs/fulfillment Minor
@medusajs/index Minor
@medusajs/inventory Minor
@medusajs/link-modules Minor
@medusajs/locking Minor
@medusajs/notification Minor
@medusajs/order Minor
@medusajs/payment Minor
@medusajs/pricing Minor
@medusajs/product Minor
@medusajs/promotion Minor
@medusajs/region Minor
@medusajs/sales-channel Minor
@medusajs/stock-location Minor
@medusajs/store Minor
@medusajs/tax Minor
@medusajs/workflow-engine-inmemory Minor
@medusajs/workflow-engine-redis Minor
@medusajs/auth-emailpass Minor
@medusajs/auth-github Minor
@medusajs/auth-google Minor
@medusajs/file-local Minor
@medusajs/file-s3 Minor
@medusajs/fulfillment-manual Minor
@medusajs/locking-postgres Minor
@medusajs/locking-redis Minor
@medusajs/notification-local Minor
@medusajs/notification-sendgrid Minor
@medusajs/payment-stripe Minor
@medusajs/core-flows Minor
@medusajs/framework Minor
@medusajs/js-sdk Minor
@medusajs/modules-sdk Minor
@medusajs/orchestration Minor
@medusajs/types Minor
@medusajs/utils Minor
@medusajs/workflows-sdk Minor
@medusajs/cli Minor
@medusajs/medusa-oas-cli Minor
@medusajs/oas-github-ci Minor
@medusajs/telemetry Minor
@medusajs/admin-bundler Minor
@medusajs/admin-sdk Minor
@medusajs/admin-shared Minor
@medusajs/admin-vite-plugin Minor
@medusajs/dashboard Minor
@medusajs/icons Minor
@medusajs/toolbox Minor
@medusajs/ui-preset Minor
create-medusa-app Minor
medusa-dev-cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 11:19am
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 11:19am
5 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 11:19am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 11:19am
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 11:19am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 11:19am
resources-docs ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 11:19am

Comment on lines -11 to -26
const expireDate = new Date().setMilliseconds(
new Date().getMilliseconds() + 60 * 60 * 24
)

const defaultInviteData = [
{
id: "1",
email: "[email protected]",
token: "test",
expires_at: expireDate,
},
{
id: "2",
email: "[email protected]",
token: "test",
expires_at: expireDate,
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: The given value was overritten by the module so it was not doing anything

expires_at: new Date().setMilliseconds(
new Date().getMilliseconds() + this.config.expiresIn * 1000
),
expires_at: new Date(Date.now() + this.config.expiresIn * 1000),
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: this was giving a big int instead of a date, now it does the same thing but provide a date instead

Comment on lines +318 to 328
const id = generateEntityId((invite as { id?: string }).id, "invite")
return {
...invite,
expires_at: new Date(),
token: "placeholder",
id,
expires_at: new Date(Date.now() + this.config.expiresIn * 1000),
token: this.generateToken({ id, email: invite.email }),
}
})

const created = await this.inviteService_.create(toCreate, sharedContext)

const updates = created.map((invite) => {
return {
id: invite.id,
expires_at: new Date().setMilliseconds(
new Date().getMilliseconds() + this.config.expiresIn * 1000
),
token: this.generateToken({ id: invite.id, email: invite.email }),
}
})

return await this.inviteService_.update(updates, sharedContext)
return await this.inviteService_.create(toCreate, sharedContext)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: This is a simplification, instead of doing a create and then an update, we only perform a create but the result remain unchanged

Comment on lines +6 to +10
this.addSql('drop index if exists "IDX_invite_email";');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_invite_email_unique" ON "invite" (email) WHERE deleted_at IS NULL;');

this.addSql('drop index if exists "IDX_user_email";');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_user_email_unique" ON "user" (email) WHERE deleted_at IS NULL;');
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: this apply the right name based on convention

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

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

LGTM

packages/modules/user/src/models/user.ts Outdated Show resolved Hide resolved
hirotaka pushed a commit to hirotaka/medusa that referenced this pull request Dec 7, 2024
* feat(user): Migrate user module to DML

* Create rotten-tigers-worry.md

* update indexes names following conventions

* remove duplicate modifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants