Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Documentation - Migration to Cloud Example #426

Open
duncangroenewald opened this issue Jul 18, 2019 · 5 comments
Open

Documentation - Migration to Cloud Example #426

duncangroenewald opened this issue Jul 18, 2019 · 5 comments
Assignees

Comments

@duncangroenewald
Copy link

duncangroenewald commented Jul 18, 2019

Goals

Migrate local realm to cloud

Expected Results

Sample code should compile

Actual Results

It seems the sample code is using outdated API's

#import "AppDelegate.h"

@import Realm;
@import Realm.Dynamic;
@import Realm.Private;

@interface AppDelegate ()

@EnD

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSString *sourceFilePath = [[NSBundle mainBundle] pathForResource:@"fieldFlow" ofType:@"realm"];

    RLMRealmConfiguration *configuration = [[RLMRealmConfiguration alloc] init];
    configuration.fileURL = [NSURL URLWithString:sourceFilePath];
    configuration.dynamic = true;
    configuration.readOnly = YES;

    RLMRealm *localRealm = [RLMRealm realmWithConfiguration:configuration error:nil];

    RLMSyncCredentials *creds = [RLMSyncCredentials credentialsWithUsername:@"admin@realm.io" password:@"password" register:NO];
    [RLMSyncUser logInWithCredentials:creds authServerURL:[NSURL URLWithString:@"http://localhost:9080"] onCompletion:^(RLMSyncUser *syncUser, NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^{
    [self copyToSyncRealmWithRealm: localRealm user:syncUser];
    });
    }];

    return YES;
    }

  • (void)copyToSyncRealmWithRealm:(RLMRealm *)realm user:(RLMSyncUser *)user
    {
    RLMRealmConfiguration *syncConfig = [[RLMRealmConfiguration alloc] init];
    syncConfig.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:[NSURL URLWithString:@"realm://localhost:9080/~/fieldRow"]];
    syncConfig.customSchema = [realm.schema copy];

    RLMRealm *syncRealm = [RLMRealm realmWithConfiguration:syncConfig error:nil];
    syncRealm.schema = syncConfig.customSchema;

    [syncRealm transactionWithBlock:^{
    NSArray *objectSchema = syncConfig.customSchema.objectSchema;
    for (RLMObjectSchema *schema in objectSchema) {
    RLMResults *allObjects = [realm allObjects:schema.className];
    for (RLMObject *object in allObjects) {
    RLMCreateObjectInRealmWithValue(syncRealm, schema.className, object, true);
    }
    }
    }];
    }

@EnD

Would someone mind updating the documentation to reflect the current APIs.

@gta-kkalchev
Copy link

I Cannot even access the realmserver documentation at https://docs.realm.io/server/
Now redirects to https://app.gitbook.com/@realm/s/server/ which says the following:

This space is private
You are not a member of the Realm organization, or you don't have permissions to access this space.

Please assist as we want to migrate and start using Realm Cloud as soon as possible.

@bmunkholm
Copy link
Contributor

bmunkholm commented Oct 23, 2019

@gta-kkalchev Where did you see the link to https://docs.realm.io/server/?
The Server docs are only for self-hosting. You should be able to use Cloud without any information from there. Are you missing something specific?

@gta-kkalchev
Copy link

@bmunkholm Thanks for your response, I was looking for documentation on how to migrate from selfhosted server to cloud platform. I don't have any experience with realm server, and couldn't find detailed docs on how to achieve my task. Any pointers are appreciated

@bmunkholm bmunkholm added the T-Doc label Nov 1, 2019
@bmunkholm
Copy link
Contributor

@gta-kkalchev If you are self-hosted I would reach out to your account manager and ask for guidance.

cc @terakilobyte @cbush

@duncangroenewald
Copy link
Author

@gta-kkalchev - is there any reason you can't just do a local backup from a client connected to your self hosted server and then use the javascript migration code to load the backup database file to the cloud server ? I have used the script to migrate from a local database to a cloud based development instance and then used the above procedure to backup the development instance and migrate that to production during the initial go-live. Initially we were worried about references not being retained but the migration script seemed to work perfectly well. Just make sure you allow enough time for the migration script to run and for the local realm service to complete syncing with the cloud server because the script just creates a local database and realm handles the syncing to the server.

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

No branches or pull requests

5 participants