-
Notifications
You must be signed in to change notification settings - Fork 961
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
Firestore and Database Emulator: Initialization of an instance with a dataset #1167
Comments
I agree that it would be great to load a database "snapshot" on initialization. I currently run the firestore and functions emulators locally for development, but when I seed the DB with testing data, a bunch of firestore function triggers are executed. This is pretty undesirable, so are there any plans for a feature to help with loading initial data or, even better, firestore data persistence to disk? |
Thanks for raising the point about wanting to seed data without functions
firing. As a stopgap measure we could definitely implement a way to "turn
off" functions triggers with a special call while you load data. That
could be useful for certain tests too. Would you use that?
But for the long term we need import/export.
…On Sat, Oct 12, 2019, 11:54 AM Wyatt Ades ***@***.***> wrote:
I agree that it would be great to load a database "snapshot" on
initialization. I currently run the firestore and functions emulators
locally for development, but when I seed the DB with testing data, a bunch
of firestore function triggers are executed. This is pretty undesirable, so
are there any plans for a feature to help with loading initial data or,
even better, firestore data persistence to disk?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1167?email_source=notifications&email_token=ACATB2VEE7BBI75HECFTE23QOIMOLA5CNFSM4G5NG5X2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCGBZA#issuecomment-541352164>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACATB2WHUTO43JISN54J4U3QOIMOLANCNFSM4G5NG5XQ>
.
|
Yes that would be a good solution for now, thanks! |
So there are no milestones set for this yet? but one thing I like now about this team here, it seems to be more active and responsive. |
can guys please add realtime db also in scope for this along with firestore db. |
@anantanandgupta no milestones yet, but yes we try to be really open about out progress! And I have added the Database emulator to be in scope as well. For Database the problem is easier (JSON format) but we still need to help you "pause" the Cloud Functions |
I know I am in good hands. But to tell you the criticality, I have designed this huge platform fully around firebase and everyone was against this a yesr back, but with my efforts i have proven till now that my decision to use firebase as the technology was not wrong. At this point it has become so big that to work on multiple features by multiple developers with a common database hosted on cloud has become impossible. So if each of us can work on a local copy of the database, it will be a lot easier and efficient. |
The ability to import data into the Firestore emulator (i.e., initialize it with "seed" data) should be going out with the next release. It will be a bit manual at first, we'll add better tooling in subsequent releases. Looking into what would be necessary for the Realtime Database emulator. |
@ryanpbrewster is there any documentation on how to setup "seed" data ? |
@SamyPesse this has been implemented inside the Emulator JAR itself (as @ryanpbrewster said) but we have not actually exposed an API through Would you mind sharing how you'd expect this to work? Would you prefer a flag on the |
Importing and exporting data is currently implemented, but we haven't quite figured out how to make it easy to use these features. So keep in mind that we know these instructions are rough, and we're open to ideas about how to improve this: Get an exportYou can generate an export from your production Firestore instance, or from the local emulator. Emulator exportBoot up the emulator and populate it with data however you'd like. Once you have your database in a state that you like, create an export:
which will dump the export onto your local filesystem in a directory like Production exportYou'll need a Google Cloud Storage bucket. I'll use my test project's default AppEngine bucket
and Firestore will dump a full copy of your production data into Google Cloud Storage. If you'd like, you can use the Once it's done you can copy it onto your local filesystem (note that this is going to go poorly if you have a huge database):
Import dataFor now, the only way to import data into the emulator is via a command line flag:
If all goes well, the emulator will start up and have all of your data in it. Note that the path it's expecting is the location of the |
I was able to emulate the firestore data from the export. Now If I try to start the firebase emulator suit. Firestore emulator is not working because the emulator is already running in the port. I tried even setting the FIRESTORE_EMULATOR_HOST variable its not recognizing. If the seed path can also be passed along the command while starting the emulator it will be much more helpful and reduce a lot of development time like |
+1 for @prgwar 's suggestion. How can I get the emulator suite to run using this startup firestore? Functions in the emulator use production because "⚠ functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production." |
@prgwar thanks for your suggestion, we are currently working on deciding the API for specifying import/export from the @srolfe26 your issue sounds like a different one, you're running the Cloud Functions emulator but not the Firestore emulator. Try running |
For any fellow WSL (1 or 2) users out there, you may have trouble connecting to the emulator from your browser. I added a
|
Would @prgwar 's suggestion of using --firestore_seed_from_export= be acceptable? If so, I'm willing to put up a PR. How else can I help get the ball rolling? I would also love if the same seed_from_export functionality could be implemented on the Realtime Database emulator. |
@spencerwhyte thanks for the offer! I am actively tackling this right now, working on something that will support Firestore and RTDB and also any future emulators. How would you feel about this general flow:
That's what I am currently working on, I think it's the most flexible thing but I am very open to feedback |
@samtstern That's great to hear! This design sounds perfect, just as long as the emulator export format / backup format is something that we can work with. If it's the same format as the backups on production, that'll do. We have a need to import a large amount of data for our integration tests without firing off our triggers. Currently we have been surviving by doing some checks that disable triggers when under test, however we'd love to avoid that complexity. This support for We use |
Thanks for the feedback! |
PR #1968 implements this feature (for Firestore only at the moment, Realtime Database coming soon) and will be included in the next CLI release (likely |
This feature was just released in |
Is this documented anywhere? Also, is there a way to export the production data without a Google Cloud Storage bucket (which I don't have)? |
@shaimo sorry we're a bit behind on docs but they should be out in the next few days! To export from production you do need a Cloud Storage bucket. This is because export is a "managed" operation which means it happens on a Google server somewhere. We can't run an operation like that against your local filesystem, we need a cloud destination. If you have a Firebase project you actually do have a default Cloud Storage bucket you can use and it includes some free quota. Just navigate over to the Storage section of the Firebase console to check it out. |
@samtstern As the documentation may take some time, can you please give a brief on how to import/export to emulator instance? |
We now have some documentation on the new flags here: But let me give you an example anyway. To use import/export you will need two terminal windows so let's call them Terminal 1 and Terminal 2 First start the emulators Terminal 1 $ firebase emulators:start
# ... After you have built up some data in them that you would like to save, run the export command in another terminal: Terminal 2 $ firebase emulators:export ./mydirectory
# ... Now you have an export in Terminal 1 $ firebase emulators:start --import=./mydirectory
# ... And that's it! |
@samtstern Can we import from a production export using the firebase emulators:start --import command? |
@landonj you can but it's a little tricky at the moment. The simplest thing to do is run |
Anything on seeding RTDB for emulator yet? |
This is much needed |
I'm trying to do the exact same thing as @landonj .. and I tried what @samtstern told ... but I'm receiving an error... What I'm doing wrong ? bdw.. the file exists!
Error: firestore: Firestore Emulator has exited with code: 1 |
Can you expand on this? Can I point directly to the gcloud bucket? Or must I first download the contents of the export locally? Which files do I need to modify? The following is what I have attempted:
As the above did not seem to work, I updated the
Below is the directory structure:
However I still have no data in the emulator UI. EditJust thought I'd add the final output from the emulator, it runs without error but without my data:
|
@gugahoi your post helped me come up with a solution: https://gist.github.com/bkuri/36cef71bcf30a5416b1c353cb81f38ed It's a small bash script that seeds your cloud storage emulator instance. All it needs is the project name and a destination path to save exported data to. ie: BTW, the above script depends on two very common tools ( Hope this helps someone. 👍 |
Anyway to avoid triggering of firestore functions on importing an existing database? |
@bkuri thanks for that script, I guess there is something odd going on with my setup/installation as I am still unable to get any data to show up in the firestore emulator console. |
Thanks to @gugahoi I was able to import a collection from production into the local emulator.
I wish these instructions were clear enough to be helpful. I hope this will help someone while we wait for a more robust solution from the Firebase folks. |
Just as a brief update: when I posted the instructions from the comment above, I was doing it in WSL2 and they didn't seem to work but the same steps in Ubuntu seem to be fine.I suspect there might be something in WSL2 interfering. |
I want to do this the other way around i want to import my emulator data into production, I need to add 7000 google sheet rows to my firestore and i was able to do that by editing a function however when trying to do it in production my memory limit gets exceeded also when something goes wrong inside the function i might end up with duplicate data. I noticed the export import and i noticed that i can make an export of my local emulator firestore data. But how about importing my local backup into production ? |
@nvanhoesel the import/export formats are the same in production and in the emulators. But yours is an uncommon use case so you'll need to do some work yourself to get the emulator export into Google Cloud Storage so that Firestore can import it properrly. |
Is there a way to reset it to initial imported data while it is running, like an endpoint that can be called from code ? How do people even run integration tests without this ? |
Is this still working? I'm getting errors exit code 1. |
It would be great to have the possibility to create an instance of the Firestore emulator with a dataset.
Currently, we're doing a batch write to initialize or reset an instance of an emulator. The issue is that it takes nearly 3s for an update of 120 operations (our testing dataset).
Would it be possible to create a Firestore emulator instance from a snapshot or to improve the performances of the emulator for large updates?
The text was updated successfully, but these errors were encountered: