EnsureDatabaseExists and bundles

95 views
Skip to first unread message

Robert Edin

unread,
Jun 18, 2013, 5:45:08 AM6/18/13
to rav...@googlegroups.com
Hi,
If I use documentStore.DatabaseCommands.EnsureDatabaseExists("anotherDb")
to create a new database, is there any way to configure what bundles that new db shall use
like when a db is created in the studio?

Robert

Oren Eini (Ayende Rahien)

unread,
Jun 18, 2013, 5:47:04 AM6/18/13
to ravendb
You need to do that using CreateDatabase, that way you can specify the bundles.




Robert

--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Robert Edin

unread,
Jun 18, 2013, 7:07:40 AM6/18/13
to rav...@googlegroups.com
Ok, .... I don't find how to use it here
or anywhere else on the site.
I don't find it by intellisense at store.DatabaseCommands.
I Google it and find no good usage.
Where can I find out how to use CreateDatabase()???

Fitzchak Yitzchaki

unread,
Jun 18, 2013, 7:37:16 AM6/18/13
to <ravendb@googlegroups.com>

Robert Edin

unread,
Jun 18, 2013, 8:58:05 AM6/18/13
to rav...@googlegroups.com
... and the F****** firewall I'm behind locks me out from github :=(

Matt Watson

unread,
Jun 18, 2013, 10:30:36 AM6/18/13
to rav...@googlegroups.com
Here is how I figured out how to add databases so we could enable replication. Will allow you to set bundles.

   public static void EnsureDatabaseExists(string dbname, string primaryUrl, string replicationUrl)
        {
            using (var store = new DocumentStore { Url = primaryUrl, DefaultDatabase = null })
            {
                store.Initialize();

                var serverClient = (ServerClient)store.DatabaseCommands.ForSystemDatabase();

                try
                {
                    //if exists, return
                    if (serverClient.Get("Raven/Databases/" + dbname) != null)
                    {
                        return;
                    }

                }
                catch (Exception ex)
                {
                    ex.SendToStackify();
                    return;
                }

                //We have to do this so we can specify the bundles we need to enable replication.
                //The built in EnsureDatabase method won't enable replication

                DatabaseDocument newDB = new DatabaseDocument()
                    {
                        Settings =
                            {
                                {"Raven/DataDir", Path.Combine("~", Path.Combine("Databases", dbname))},
                                {"Raven/ActiveBundles", "PeriodicBackup;Replication"}
                            }
                    };
                
                
                var docNew = RavenJObject.FromObject(newDB);
                docNew.Remove("Id");

                try
                {
                    var req = serverClient.CreateRequest("PUT", "/admin/databases/" + Uri.EscapeDataString(dbname));
                    req.Write(docNew.ToString(Formatting.Indented));
                    req.ExecuteRequest();
                }
                catch (Exception ex)
                {
                    ex.SendToStackify();
                }


                //Create the standard index

                try
                {
                    new RavenDocumentsByEntityName().Execute(serverClient.ForDatabase(dbname), new DocumentConvention());
                }
                catch (Exception ex)
                {
                    ex.SendToStackify();
                }


                if (replicationUrl != null)
                {
                    ReplicationDocument replicationDocument = new ReplicationDocument();
                    ReplicationDestination destination = new ReplicationDestination()
                        {
                            Url = replicationUrl,
                            Database = dbname,
                            TransitiveReplicationBehavior = TransitiveReplicationOptions.None,
                            IgnoredClient = false,
                            Disabled = false
                        };

                    replicationDocument.Destinations.Add(destination);


                    using (var session = store.OpenSession(dbname))
                    {
                        session.Store(replicationDocument, replicationDocument.Id);
                        session.SaveChanges();
                    }
                }
            }
        }

Robert Edin

unread,
Jun 19, 2013, 2:50:47 AM6/19/13
to rav...@googlegroups.com
Thanx Matt! This was more than I asked for, but it can be really useful to us :)
Reply all
Reply to author
Forward
0 new messages