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

Document using strapi instance for migrations #2085

Merged
merged 3 commits into from
Apr 23, 2024
Merged

Document using strapi instance for migrations #2085

merged 3 commits into from
Apr 23, 2024

Conversation

nc1z
Copy link
Contributor

@nc1z nc1z commented Apr 17, 2024

What does it do?

Updated documentation for developers that decide to use strapi instead of knex to perform data migrations.

Why is it needed?

Often developers may want to use their custom strapi service methods to perform migrations.

Important

This serves as a caution for new Strapi developers who might overlook the lack of atomicity when using the strapi instance, unlike knex, which operates within a transaction state by default when received in the up() function.

Source: this happened to my team😄

Related issue(s)/PR(s)

N/A

@nc1z nc1z requested a review from pwizla as a code owner April 17, 2024 14:31
Copy link

vercel bot commented Apr 17, 2024

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

Name Status Preview Comments Updated (UTC)
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2024 5:19pm

@pwizla
Copy link
Collaborator

pwizla commented Apr 22, 2024

Thanks, @nc1z.
I did the technical writing review but also asking @derrickmehaffy for a technical review, as I'm not sure this is something we'd like to recommend 🤔

@pwizla pwizla self-assigned this Apr 22, 2024
@pwizla pwizla added the source: Dev Docs PRs/issues targeting the Developer Docs label Apr 22, 2024
@nc1z
Copy link
Contributor Author

nc1z commented Apr 22, 2024

Thanks, @nc1z.

I did the technical writing review but also asking @derrickmehaffy for a technical review, as I'm not sure this is something we'd like to recommend 🤔

All good @pwizla, appreciate the review 😃

From what I see, the docs don't advise against other approaches besides knex, so it might be good to either explicitly mention the pitfalls or explicitly recommend knex somehow.

But let's see what derrick says, just sharing my opinion here since our team used strapi services as a quick way to reuse logic in our migrations without needing to build tables from scratch (especially when they have complex relations).

@derrickmehaffy
Copy link
Member

This makes sense to me, the transaction thing won't be a problem afaik in Strapi 5 with the document service replacing the entity service and to my knowledge the docsrv will wrap everything in a transaction by default.

Typically you wouldn't use the migrations for normal CRUD operations just db schema modifications or something but it will work for both.

might result in data loss so the highest-level of callout is required

Co-authored-by: Pierre Wizla <pwizla@users.noreply.github.com>
Co-authored-by: Pierre Wizla <pwizla@users.noreply.github.com>
@nc1z
Copy link
Contributor Author

nc1z commented Apr 22, 2024

This makes sense to me, the transaction thing won't be a problem afaik in Strapi 5 with the document service replacing the entity service and to my knowledge the docsrv will wrap everything in a transaction by default.

Typically you wouldn't use the migrations for normal CRUD operations just db schema modifications or something but it will work for both.

Exciting stuff in Strapi 5 I see! 😄

Yeah in our case we had to create/migrate some tables, relations and sync content localizations for several environments including prod, so we figured using our service with create functionality would avoid all the additional work since its tested.

Cool, @pwizla I'll leave you to decide if we want to merge, I'd think it's useful for v4 since most existing systems will still be on there for awhile. I've cleaned up according to your comments. Cheers 👍

Copy link
Member

@derrickmehaffy derrickmehaffy left a comment

Choose a reason for hiding this comment

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

Overall looks good to me

@pwizla
Copy link
Collaborator

pwizla commented Apr 23, 2024

Thanks for the insightful discussion, @derrickmehaffy and @nc1z!
This is definitely helpful for v4 and indeed Strapi v4 will be maintained for 12-18 months so it's worth adding it to docs.

The PR is now approved, merged, should be live on docs.strapi.io in a few minutes, and will be mentioned in the next weekly snapshot release.

@pwizla pwizla merged commit 7da45e0 into strapi:main Apr 23, 2024
2 checks passed
@pwizla pwizla added this to the 4.23.2 milestone Apr 23, 2024
@pwizla pwizla added pr: updated content PRs updating existing documentation content temp: port to v5 Temporary label for PRs that need to be ported to v5 docs labels Apr 23, 2024
MbonuJennifer added a commit that referenced this pull request May 22, 2024
@MbonuJennifer MbonuJennifer removed the temp: port to v5 Temporary label for PRs that need to be ported to v5 docs label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: updated content PRs updating existing documentation content source: Dev Docs PRs/issues targeting the Developer Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants