Database Naming convention

mobile

#1

Is this name to long to be a database name 72d264ce-e739-48f0-8c06-98cf081e5e32-1460911677562, it seems to match the requirements laid down in the docs.

Caution:For compatibility reasons, database names cannot contain uppercase letters! The only legal characters are lowercase ASCII letters, digits, and the special characters _$()±/

Kind regards,

Jacko


#2

https://mothereff.in/byte-counter says its 50 bytes so you are good :thumbsup:

You can store a key size of 250 bytes max.


#3

Sorry, I should have said I get this error in Android Studio 2.0 when I try to initially load the app onto one of my test devices (Google Nexus tablet Android 5.1.1), so this fails when I first try to create the database, on allowing the App to crash I run the app again and it is fine, it can open the database with the naming convention as provided before:

Invalid database name: 72d264ce-e739-48f0-8c06-98cf081e5e32-1460911677562

Caused by: java.lang.IllegalArgumentException: Invalid database name: 72d264ce-e739-48f0-8c06-98cf081e5e32-1460911677562
at com.couchbase.lite.Manager.getDatabase(Manager.java:557)
at com.couchbase.lite.Manager.openDatabase(Manager.java:333)

I used the following code taken from the ForestDB Blog post

manager = new Manager(new AndroidContext(getApplicationContext()), Manager.DEFAULT_OPTIONS);
DatabaseOptions options = new DatabaseOptions();
options.setCreate(true);
options.setStorageType(Manager.FORESTDB_STORAGE);
Database database = manager.openDatabase(dbName, options);

Where dbName is a combination of UUID.randomUUID().toString and current time in milliseconds converted to string also.

String newUUID = UUID.randomUUID().toString();
Calendar calendar = GregorianCalendar.getInstance();
long currentTime = calendar.getTimeInMillis();
dbName = String.format(Locale.UK, "%s-%d", newUUID, currentTime).toLowerCase();

Changed the code slightly too

manager = new Manager(new AndroidContext(getApplicationContext()), Manager.DEFAULT_OPTIONS);
manager.setStorageType(Manager.FORESTDB_STORAGE);
Database database = manager.getDatabase(dbName);

Now it wont run at all!

Jacko


#5

There is one more requirement that is not clear from the documentation: the database name must start with a lower case letter (yours starts with a number). This is taken from the CouchDB requirements. It should be in our docs as well.


#6

Hi @borrrden,

Spot on, I forced lowercase letters at the start like

dbName = String.format(Locale.UK, "%s_%s_%d", "cbl", newUUID, currentTime).toLowerCase();

And it loaded and created the database first time, as expected. It did work sometimes yesterday but the UUID part must have started with a letter, which I missed.

With thanks,

Jacko


#7

@interneers For what it’s worth, I ran into this problem myself in one of my unit tests a month or two ago and it took me a bit to figure out (and I should know better since I am writing the .NET version ><). I thought it was odd that it was failing intermittently, then I realized it was the luck of the draw whether or not a UUID starts with a number or a letter.


#8

@interneers,

My comment above about 250 byte key that is a Couchbase Server requirement not CBL database names, sorry.

SIDE NOTE
You want to key your doc ID size to equal something less then then 250 … maybe 200 bytes b/c in Couchbase server when updating a doc it keeps around the of the older version as a new key with a TTL of 5min. The key looks Something like below.

_sync:: {your-doc-id}::{ABCD-rev-number MD5 hash of Doc}


#9

Understood, just learning about sync gateway now.

Maybe an inclusion in the documents including the above requirements would help others in the future.

With thanks,

Jacko