Artur Owczarek
Artur Owczarek

Reputation: 1167

Firebase realtime database erased

I use Firebase realtime database in my react native app. Most things is being done with REST API cloud functions. Few things in app use directly realtime database. Of late i noticed that for no apparent reason all data in my database was erased. Even parts of database which are no longer in use and are not referenced in source code of my app/cloud functions are gone.

The problem happens with two projects and their databases (production/test). I have to use backups to restore them but it happens again even if nobody uses application (eg. in test environment).

Does anybody have idea what might be the source of this problem? I have parts responsible for removal of some parts of the data but it's impossible that all of the run at once. How do I troubleshoot it? How is it possible to remove all the data at once?

My security rules are as follows:

{
  "rules": {
    "version": {
      ".read": true,
      ".write": false
    },
    "flatLocations": {
      ".read": false,
      ".write": false
    },
    "geoplaces": {
      ".read": false,
      ".write": false,
      ".indexOn": "g"
    },
    "locations": {
      ".read": true,
      ".write": false
    },
    "locationSubscriptions": {
      ".read": false,
      ".write": false
    },
    "profiles": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    },
    "subscriptionCodes": {
      ".indexOn": "vendingPointId",
      ".read": false,
      ".write": false
    },
    "usersRoles": {
      ".read": false,
      ".write": false
    },
    "usersSubscriptions": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": false
      }
    },
    "vendingPoints": {
      ".read": false,
      ".write": false,
      ".indexOn": "vendorId"
    },
    "customersBasicData": {
      ".read": false,
      ".write": false
    },
    "notificationTokens": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    },
    "scheduled": {
      ".read": false,
      ".write": false
    }
  }
}

Some data are only added. I have no code to delete them.

Upvotes: 0

Views: 1265

Answers (1)

Artur Owczarek
Artur Owczarek

Reputation: 1167

The problem was undefined used in reference. When you run admin.database().ref(somethingWhichIsUndefined).remove(), the whole database is ereased.

Upvotes: 1

Related Questions