1

Currently I've been moving my firebase app from real time database to the cloud firestore. For that purpose I have two separate firebase projects:

  • my-project <- current project my app uses
  • my-project-firestore <- project I want to migrate to

I exported all the users from the current project and imported them back to the new one.

Currently my react-redux-firebase config looks like that

export const reduxFirebase = {
    userProfile: "users"
};

it makes the user profiles are being saved to the real time database under path /users Now I moved all of the documents under this path to the same path in the cloud firestore database by using such python script

def migrate_users(project_id, firebase_app, firestore_client):
    path = "/users"
    firestore_path = "users/{customer_id}"
    print(
        f"migrating from project: {project_id}, partner_id: {partner_id}, path: {path}"
    )
    ref = db.reference(path, firebase_app)
    document = ref.get() or {}
    items = document.items()
    size = len(items)
    for counter, item in enumerate(items):
        customer_id = item[0]
        notes = item[1]
        print(f"{counter+1}/{size} -- migrating customer_id: {customer_id}")
        current_document = firestore_client.document(
            firestore_path.format(
                customer_id=customer_id
            )
        )
        current_document.set(notes)

So now in theory I should have the same state of data regarding users and their profiles in both databases.

I added the redux-firestore dependency

    "react-redux-firebase": "2.5.1",
    "redux-firestore": "^0.13.0",

I changed some code in my react app

   export const reduxFirebase = {
       userProfile: "users",
       useFirestoreForProfile: true
   };
...
   firebase.initializeApp(firebaseConfig());
   firebase.firestore()
...
  const composedEnhancers = composeEnhancers(
        reactReduxFirebase(firebase, reduxConfig),
        reduxFirestore(firebase),
        applyMiddleware(...middleware),
        ...enhancers
    );

After I login into my app using my gmail account, which in firebase has some id let's say qWertYzAbcdEfhJijk, when I try to fetch all documents from the firestore under the path /users I can only fetch documents which were created when somebody logged into my app with new config. It doesn't see all the user data I migrated

    export default compose(
        withStyles(styles),
        firestoreConnect(props => [
            {
                collection: "users",
                storeAs: "users"
            },
        ]),
        connect(mapStateToProps, mapDispatchToProps)
    )(ActiveUsersPanel);
...
const mapStateToProps = (state, props) => {
    return {
        users: state.firestore.data.users
    };
};
...
function ActiveUsersPanel(props) {
    const {firebase, classes, users} = props;
    console.log(users);
...

the result contains only one item

{"qWertYzAbcdEfhJijk":{"id":"qWertYzAbcdEfhJijk","avatarUrl":"https://lh6.go...","displayName":"My name","email":"my@email.com","providerData":[{"email":"my@email.com","phoneNumber":null,"photoURL":"https://lh6.googl...","providerId":"google.com","uid":"115418232581098xxxxxx"}]}}

And doesn't contain all of the documents I migrated from the old database even though they look the same

Why is it happening and how to solve it ?

EDIT: maybe this picture can help to better understand what my issue is

enter image description here

EDIT: I noticed that when I change the react-redux-firebase config to point to other path

export const reduxFirebase = {
           userProfile: "storeUsers",
           useFirestoreForProfile: true
       };

suddenly it's able to read the /users correctly in my component

Clyde Barrow
  • 1,924
  • 8
  • 30
  • 60
  • In your python migration script, are you defining the credentials of your new project to initialize firestore_client ? – Jan Hernandez Sep 03 '20 at 13:40
  • in my migration script I use a separate admin sdk credentials to put the data into the database – Clyde Barrow Sep 03 '20 at 14:39
  • based on the last edit of the question you can read your users? – Jan Hernandez Sep 03 '20 at 16:06
  • when I change in the config the `userProfile` variable to `storedUsers` I AM able to read all the users I migrated however the new users are saved under this new path so it doesn't solve my issue - it only implies that the problem is with the way the library reads the user profile path – Clyde Barrow Sep 03 '20 at 18:57

0 Answers0