tanx to google , firebase can deploy on localhost for testing. afer stoping simulation all of the states are going to reset and database is wiping out too.
I need to know how to avoid from losing this data and configs.
If you're using Cloud Firestore you can import data to and export data from the emulator suite. For other emulated products such functionality does not (yet) exist, so you will have to ensure you can re-initialize the data in your application code.
Related
Scenario:
I am working on a POC locally where I am using Firestore as my database. As it is my local setup I am using Firestore Emulator. Now my POC is successful and I want to move local database from emulator to actual Firestore.
Query:
Is it possible to achieve what I am trying to do?
So far I am not able to find any relevant content on internet around this. I did find couple of examples where there is demonstration of exporting data from Firestore and importing to local emulator but I was not able to find the vice-versa option!
Firebase does not provide any sort of tool or service to do this. Your easiest alternative will be to write a program to query the data out of the emulator and write it into your cloud hosted instance. You might find the Firebase Admin SDK helpful for writing to the cloud in a program that you run locally.
I recently set up the firebase emulators to run my cloud functions locally. After setup, the cloud functions triggered successfully but any write to the real-time database does not reflect in the corresponding local database emulator UI. e.g when I use
snapshot.after.ref.parent.child('busy').set(true)
So I tried exporting and importing the real-time data and I discovered that all database write from cloud functions was being saved in a default database with name localhost:4000/?ns=pick2-c468b-default-rtdb and not the database that is triggering the write event.
Is this the default behaviour of the emulator and how do I go about changing or fixing it?
Writes to snapshot.after.ref should go to the database that triggered the Function.
If that is not happening for you, I recommend reporting a bug with a minimal repro on the repo (which should include an entire Cloud Function, and not just the line that you think is going wrong.
Is there a way I can configure the firestore emulator to start off with the data in my production database. I have a lot of test information in there and want to transition it to the local emulator without having to copy each and every document/collection. My initial thought was that there must be a configuration in the firebase.json file but I'm sure what it would be.
There is no feature to configure the Firestore emulator to read its initial data from the production database.
What you can do is export the data from your production database (through its regular API(, and import it to the emulator (also through its regular API) and after that use the import and export commands to get the data in and out of the emulator.
I'm Planning To Use Firebase - Firestore Emulators For Handling Some Huge Amount Of Data That's Coming From A Websocket.
I just need to process the data locally in realtime.
Firestore Emulator Is A great choice since it has all the features I need. But the issue is it clears the database every time the Emulator is turned off. is there any config or settings that can change this behaviour?
if it is not possible. can somebody tell me any other Approach to use firestore locally? or any other alternative to firebase that I can use locally.
With the recent updates to Firebase Emulator, you use export the data when the emulator is running and import when it starts again.
To export the data
firebase emulators:export <export-directory>
To start and import the emulator
firebase emulators:start --import <export-directory>
I've managed this starting Firebase emulator with parameters to export data on exit and import existing one:
firebase emulators:start --import=exported-dev-data --export-on-exit=exported-dev-data
This way the emulator always export the data I've generated to folder exported-dev-data, and loads it back when starting again.
Currently you need to write code to populate the database during each run of the emulator.
If you would like to see different behavior, please file an issue on GitHub.
I want to test my Firebase data access layer with direct access to Firebase.
Is flutter drive the only way to run such tests, or are there other ways like running in emulator using flutter test?
What are the possible approaches and how can I set them up?
I'm not aware of a way to talk to a real database with flutter test currently, because there's no Firebase SDK to do the talking to the network. You probably wouldn't want this anyway, because it could make your tests nondeterministic or flaky if the data changes or the Firebase servers aren't accessible.
Some plugins, like shared_preferences, have an API for providing mock values. You could do something like that for the firebase_database plugin, either as a pull request to the first-party repo or by calling MethodChannel.setMockMethodCallHandler and BinaryMessages.handlePlatformMessage in your test code to simulate what the native side would be doing.