Database.ensure() should return True if the database was created, False if it already existed

Bug #833646 reported by Jason Gerard DeRose on 2011-08-25
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Microfiber
High
Akshat Jain

Bug Description

Database.ensure() tries to create the database, and handles the PreconditionFailed exception for you if the database already exists:

http://bazaar.launchpad.net/~microfiber/microfiber/trunk/view/76/microfiber.py#L693
(URL updated by Manish. Please use specific commit URL instead of HEAD since the line number for a method can change in HEAD).

However, it would be handy to know whether the database was created, so you know if say there is some initialization work you must do. Like this:

db = Database('novacut')
if db.ensure():
    # Must be first time running Novacut, lets initialize and so forth
    pass

This way Database.ensure() will match the semantics of the filestore.ensuredir() function:

http://bazaar.launchpad.net/~dmedia/filestore/trunk/view/186/filestore.py#L1044
(URL updated by Manish. Please use specific commit URL instead of HEAD since the line number for a method can change in HEAD).

This is a tiny change, and then you'll just have to update the Live unit test for Database.ensuredir():

http://bazaar.launchpad.net/~microfiber/microfiber/trunk/view/head:/test_microfiber.py#L715

The "live" tests aren't run by default, as they require CouchDB to be available. Run the live tests against system-wide CouchDB like this:

  ./setup.py test --live

Or run them against desktopcouch like this:

  ./setup.py --dc

But you need to have dmedia installed for the --dc option to work.

Related branches

lp:~akshatj/microfiber/ensure
Jason Gerard DeRose: Approve on 2011-09-12
description: updated
Akshat Jain (akshatj) on 2011-08-25
Changed in microfiber:
status: Triaged → In Progress
summary: - Database.ensure() should return True if the database was created, Fales
+ Database.ensure() should return True if the database was created, False
if it already existed
Akshat Jain (akshatj) on 2011-09-12
Changed in microfiber:
status: In Progress → Fix Committed
Changed in microfiber:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers