Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database name, admin, and type #1692

Merged
merged 15 commits into from
Apr 21, 2022
Merged

Database name, admin, and type #1692

merged 15 commits into from
Apr 21, 2022

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Apr 21, 2022

This PR adds some useful utilities for configuring database access.

Database name

A new database_name config setting is added that allows for users to customize their MongoDB database name:

import fiftyone as fo

print(fo.list_datasets())  # [...]
print(fo.config.database_name)  # fiftyone
export FIFTYONE_DATABASE_NAME=fiftytwo
import fiftyone as fo
import fiftyone.core.odm as foo

print(fo.list_datasets())  # []
print(fo.config.database_name)  # fiftytwo

foo.drop_database()  # cleanup
unset FIFTYONE_DATABASE_NAME

Database/client types

Notions of database type and client type are added, and now database connections are refused if a Python client's type does not match the database's type.

The client type is hard-coded in fiftyone.constants.CLIENT_TYPE, and the database's type is stored in a new type field of the config collection.

This is an internal mechanism that exists to prevent OSS Python clients from connecting to non-OSS databases.

Database admin

A new database_admin config setting is added. This parameter defaults to True, but clients can set it to False, in which case database migrations are not allowed (other than lazily migrating a dataset to the current database version, which is normal usage):

fiftyone migrate -v 0.15.0.1
export FIFTYONE_DATABASE_ADMIN=false
import fiftyone as fo  # ERROR: only admins can migrate
unset FIFTYONE_DATABASE_ADMIN
import fiftyone as fo
# Migrating database to v0.15.1

The documentation explains how this feature may be useful for OSS users leveraging database_uri to work on a shared database:

Screen Shot 2022-04-21 at 1 26 33 PM

@brimoor brimoor added the feature Work on a feature request label Apr 21, 2022
@brimoor brimoor requested a review from a team April 21, 2022 17:33
@brimoor brimoor self-assigned this Apr 21, 2022
@j053y
Copy link
Contributor

j053y commented Apr 21, 2022

LGTM

@brimoor brimoor merged commit cf0a75d into develop Apr 21, 2022
@brimoor brimoor deleted the safe-db branch April 21, 2022 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants