strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable and developer-first.
https://strapi.io
Other
60.67k stars 7.58k forks source link

Developing locally pointing to production database dropped data #20177

Closed oldo closed 2 weeks ago

oldo commented 3 weeks ago

Bug report

Required System information

Describe the bug

We have a production instance of the project running in the cloud. Whilst developing, we had set local env var to the production database. Locally the codebase was checked out to an old commit that didn't include a number of new collection types that had been added. We ran the dev server locally and because the code didn't have the new collection types and db env vars were pointing to production, the corresponding tables related to the missing collection types were dropped. A lot of important data was lost and without any warning or notification.

Steps to reproduce the behavior

  1. run locally with local database
  2. check out old commit that doesn't include some recently added collection types
  3. run again locally and tables are dropped.

Expected behavior

I would expect that if data is going to be dropped that a notification is given something along the lines of "The following tables with data are going to be dropped: X, Y, Z. Do you want to continue Y/n".

I'm pretty shocked at how easy it was to lose data.

derrickmehaffy commented 2 weeks ago

This is intended and there are several warnings in the documentation.

We can't add interactive messages to the terminal or it would break ci/cd and this type of schema migration is exactly what it should be doing in production.

You should NEVER connect any application to a prod database like that. Take a snapshot or a backup, pull it locally and connect with a local dev database.

oldo commented 2 weeks ago

Thanks for the response. I disagree that no safeguards could be put in place because of CI/CD. Perhaps prompts could be added if running dev server or a check for the presence of an env var (e.g. IS_CICD) to determine whether it's appropriate to show warnings when data is going to be dropped from the database.

derrickmehaffy commented 2 weeks ago

It's something we have discussed at length internally and decided against. For more information as to why we decided this see #1114