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

Allow emulators to export on exit #2224

Closed
samtstern opened this issue May 8, 2020 · 19 comments · Fixed by #2415
Closed

Allow emulators to export on exit #2224

samtstern opened this issue May 8, 2020 · 19 comments · Fixed by #2415

Comments

@samtstern
Copy link
Contributor

Originally requested through FIrebase support, there is some demand for a flag like this:

firebase emulators:start --import=./seed --export-on-exit

This would import from a location but save any mutations made on exit.

@michi88
Copy link
Contributor

michi88 commented Jun 14, 2020

I've requested this indeed! Great that it is actually picked up here :). I could try to make a PR if that is appreciated. Let me know.

@samtstern
Copy link
Contributor Author

@michi88 if you're interested in sending a PR for this I'd be happy to accept it. But we have to follow a bit of a process:

  1. First you and I should work out the full API change here
  2. Then I'll "sponsor" your internal API proposal, we have a group of Firebasers that reviews any API change to our SDKs or the CLI.
  3. Once it's approved we can merge and release your PR, along with any edits suggested by the API review process (2).

Sound like something you're up for? I know it sounds slow and bureaucratic but I'll be handling the bad parts mostly.

@michi88
Copy link
Contributor

michi88 commented Jun 16, 2020

Great, I’m up for giving that a try! So let’s settle on the API. What do you think about the —export-on-exit flag? Should it just be a flag or accept a path where to export the data to? Should it require the —import flag and take that folder to export to by default?

My general use case here is with :exec in the ‘default’ npm serve command that would start emulators but the data is not gone when you stop / reload. Of course you can do an export first and all but that is too much explaining for new developers coming to a project and expect things to just work with a single npm serve command.

What might make sense though is that the —import dir contains seed data (that you store in a repo) for new setups but that you can use a different dir as your local data dir where we would export and import to on subsequent runs. So maybe we would add another —seed flag that is only imported when the —import dir is empty.

Not sure what would be best here. Let me know what you think.

@samtstern
Copy link
Contributor Author

@michi88 thanks for asking all the right questions. My personal take:

  • I like the name --export-on-exit

  • I think it should take an optional path --export-on-exit=./some-path. When unspecified it would use the same path as --import. If you do a bare --export-on-exit with no --import=something flag that's an error. So:

    • ✅ VALID: emulators:start --import=./foo --export-on-exit
    • ✅ VALID: emulators:start --import=./foo --export-on-exit=./bar
    • ✅ VALID: emulators:start --export-on-exit=./bar
    • ❌ NOT VALID: emulators:start --export-on-exit

If that sounds good to you I'll propose it to the API people.

@michi88
Copy link
Contributor

michi88 commented Jun 16, 2020

I'm leaning towards that indeed as we have this --import flag already to work with.

On the other hand something like a --data-dir would maybe also make sense where we import from and export to. It feels a bit cumbersome that we need to set 2 flags in order to get this behavior (importing and exporting).

I'd say the --import flag is super useful for seeding data for tests and the --data-dir is what you want during development.

The downside of this is that we're actually not really using it as a persistent data dir but only export on exit (which is not guaranteed to succeed). Unless we can change that and use it like that (in the future) but that is doubtful.

I'm ok with --export-on-exit as well though :).

@samtstern
Copy link
Contributor Author

@michi88 totally makes sense, although right now we do want import and export to feel explicit and separate for the reason you said: they're one-time expensive operations. Something like --data-dir implies that these emulators have a persistence layer, which they do not.

I'll go ahead and kick this off.

@samtstern
Copy link
Contributor Author

Alright I sent out the API proposal so we'll see how it goes.

For googlers: https://go/firebase-emulators-export-on-exit

@samtstern
Copy link
Contributor Author

@michi88 thanks for your patience, the API proposal was approved today! I think this is all stated above but here's a succinct version of the proposal you can use for your implementation guide:

# VALID: This would export to the same directory as import (./data)
$ firebase emulators:start --import=./data --export-on-exit

# VALID: This would export to a brand new directory
$ firebase emulators:start --import=./data --export-on-exit=./new-data

# VALID: No import is required to export
$ firebase emulators:start --export-on-exit=./new-data

# INVALID: In this case we don't have an --import flag to infer the directory
$ firebase emulators:start --export-on-exit

Of course if your circumstances have changed and you no longer want to implement this just let me know and I will happily do the PR myself.

@michi88
Copy link
Contributor

michi88 commented Jun 30, 2020

I’ll have a look right now, keep you posted.

@quantuminformation
Copy link

Waiting with anticipation. I didn't realise that data was not saved automatically after restarting and was wondering what was wrong with my app until I checked the db, I'm glad I'm not crazy.

@quantuminformation
Copy link

Nice one, works a treat

image

@salaryazdjerdi
Copy link

So when we want to export the data from the emulator do we just exit (control c on mac) and it will be pulled to the same path we used in $ firebase emulators:start --import=./data --export-on-exit ?

@samtstern
Copy link
Contributor Author

@salaryazdjerdi yes exactly!

@quantuminformation
Copy link

If I delete all my data in the UI by clicking x on the root node, then restart then I still see the old data

using --import=./seed --export-on-exit

@samtstern
Copy link
Contributor Author

@quantuminformation we really appreciate all of your feedback but please don't comment on old closed issues with new bug reports. If you have an issue to report, start a new issue and follow the template (or find an existing open issue that is a duplicate and add a comment)

@quantuminformation
Copy link

quantuminformation commented Sep 21, 2020

Ok, sometimes I am reluctant because I don't want to create a new issue in case it's already a known one or its a feature by design. Will create a new one .

new issue https://github.com/firebase/firebase-tools-ui/issues/366

@steveoh
Copy link
Contributor

steveoh commented Jun 2, 2022

Should this export auth accounts as well?

@yuchenshi
Copy link
Member

@steveoh Yes it does by default if the Auth emulator is started.

@steveoh
Copy link
Contributor

steveoh commented Jun 17, 2022

What are the exit methods that trigger export?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants