Firebase FAQ - devuxd/SeeCodeRun GitHub Wiki
Firebase FAQ
1) I want to test some code I just wrote. Are there separate production and staging servers for SeeCodeRun? Or should I set up my own firebase just for my branch?
With Firebase, it is possible to set up multiple environments that may be used as production and staging servers. With the locations/URLs of the different servers and proper permissions, you can change your deployment to the appropriate server (i.e. a staging one if it is for testing) See the following articles for more information:
https://www.firebase.com/blog/2015-10-29-managing-development-environments.html
https://www.firebase.com/blog/2014-11-17-firebase-hosting-tips-and-tricks.html
2) I've made a change, had it reviewed, and pushed it into master. How do I deploy the new master branch to the production Firebase server?
These instructions assume that Node.js and npm are already installed and updated. See hosting setup for more information.
Initializing an Application
firebase init
- Run this command in your project directory to initialize it for Firebase Hosting. Initializing a project will create a firebase.json
file containing the configuration information needed for Hosting.
Deploying
firebase deploy
- Deploys the current project (both assets and Security Rules) to Firebase Hosting and creates your subdomain on firebaseapp.com
if it doesn't already exist.
Specifying the optional command line parameter -m
or --message
will allow you to include an optional version message, for example firebase deploy -m 'initial upload'
.
For extra granularity you can specify firebase deploy:hosting
to deploy only your site's static assets or firebase deploy:rule
s to deploy only Security Rules.
NOTE!! Security and Firebase rules in the new .json file will overwrite existing rules!
3) Can I do queries on Firebase?
Yes!
With Firebase database queries, we can selectively retrieve data based on various factors. To construct a query in your database, you start by specifying how you want your data to be ordered using one of the ordering functions: orderByChild()
, orderByKey()
, orderByValue()
, ororderByPriority()
. You can then combine these with five other methods to conduct complex queries:limitToFirst()
, limitToLast()
, startAt()
, endAt()
, and equalTo()
.
For more information you can visit the following pages:
Ordered Data Section_Web Quick Start Guide_Retrieving Data
Queries Section_Web Quick Start Guide_Retrieving Data
Some Important Notes:
-
Any node which does not have the child key we're querying on will be sorted with a value of null, meaning it will come first in the ordering. (See Ordered Data Section)
-
Queries can also be ordered by deeply nested children, rather than only children one level down by using the full path to the object rather than a single key
-
Queries can only order by one key at a time. Calling
orderByChild()
multiple times on the same query throws an error -
Keys (when ordering by key) can only be strings
-
See the Ordering Data link for a description of how Firebase will order null, Boolean and object values
-
You can improve performance for common ad-hoc queries by indexing data in the Security and Firebase Rules, which will index and save the keys on the Firebase servers to improve performance
4) Can I use security rules to prevent just anyone from seeing all of the content on Firebase? I don't want anyone that doesn't have the URL and ID of a pastebin to be able to see its content.
“Firebase provides a flexible, expression-based rules language with JavaScript-like syntax to easily define how your data should be structured and when your data can be read from and written to. The rules live on the Firebase servers and are automatically enforced at all times.”
Firebase includes extensive Security and Firebase Rules documentation, which includes user authentication. Read access can be customized using declarative rules statements, provided the information needed to customize the rule is available.
Firebase supports the following libraries to assist developers with correctly writing authorization rules for their applications:
Bolt Compiler
“The Bolt compiler simplifies building Security and Firebase Rules. Bolt provides types to specify schemas at specific paths and functions for code reuse.”
Blaze Compiler “The blaze compiler simplifies building Security and Firebase Rules. It drastically reduces the amount of copy and pasting involved. Blaze compiler Security and Firebase Rules are shorter, and the syntax is less fussy”
5) Could someone run a command that accidentally deletes all the data on Firebase? Should I be worried about data loss?
Firebase includes a remove() function that will remove all data at that location, including data at the child locations. Although not verified by the Firebase website, other sites have stated that this function cannot be called on the root, but must start with a child. Regardless, this function can be protected from deleting an entire database by writing security rules that could check for and prevent such actions or limiting write access by user. It is important to note that “The child rules can only grant additional privileges to what parent nodes have already declared. They cannot revoke a read or write privilege.”
In the event of a catastrophic loss of data, Firebase includes the following options to backup and restore your data:
-
Daily automated backups are included with the standard Firebase service. The backups are stored for 60 days, do not affect bandwidth usage and can be made available to developers on a case-by-base purpose for disaster recovery.
-
Private backups to Google Cloud Storage (GCS) bucket or an Amazon Simple Storage Solution (S3) bucket are available for updated service plans. Private backups do not affect bandwidth usage or application performance.
-
Can create manual backups with the REST API, but this will impact bandwidth usage and may impact performance.
6) I understand that there may already be data stored in Firebase. What changes can I make to what data I store or load from Firebase without worrying about backwards compatibility?
Firebase does not directly address backwards compatibility. As with any software program, a migration to a new version should continue to work with the older version, and as in the case of this question, an updated version of the software should not alter existing data. Caution should be taken when developing a new version of a program to ensure that the changes do not delete or override an existing function that may create issues for backwards compatibility. The following link is one source that addresses testing for backward compatibility. http://www.tutorialspoint.com/software_testing_dictionary/backward_compatibility_testing.htm
7) Where can I learn more about Firebase?
Start by visiting the main page! https://www.firebase.com/
Other Useful Links:
-
Web Platform Documents (includes code snippets and examples, including FirePad)
8) How much data will Firebase store?
Firebase provides 6 levels of service. The “free” (lowest) service provides 1 GB each of real time database and hosting storage. For more information on the pricing and service levels see Firebase Pricing and Plans. To help you manage your storage, the Firebase dashboard provides an analytics tab that will display the details of your storage in addition to other information that may be useful in understanding how your application is being used (such as tracking peak times).