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

Developing locally pointing to production database dropped data #20177

Closed
oldo opened this issue Apr 22, 2024 · 3 comments
Closed

Developing locally pointing to production database dropped data #20177

oldo opened this issue Apr 22, 2024 · 3 comments
Labels
status: will not fix Won't fix as it's either intended or for some other reason

Comments

@oldo
Copy link

oldo commented Apr 22, 2024

Bug report

Required System information

  • Node.js version: 20.11.0
  • NPM version: 10.2.4
  • Strapi version: 4.11.4
  • Database: Postgres
  • Operating system: MacOS
  • Is your project Javascript or Typescript: Typescript

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
Copy link
Member

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.

@derrickmehaffy derrickmehaffy added the status: will not fix Won't fix as it's either intended or for some other reason label Apr 24, 2024
@derrickmehaffy derrickmehaffy closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
@oldo
Copy link
Author

oldo commented Apr 25, 2024

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: will not fix Won't fix as it's either intended or for some other reason
Projects
Status: Done
Development

No branches or pull requests

2 participants