Skip to content

Commit

Permalink
Merge pull request #35 from LSSTDESC/u/jrbogart/beta_default
Browse files Browse the repository at this point in the history
U/jrbogart/beta default
  • Loading branch information
JoanneBogart authored Jul 5, 2023
2 parents 0d5307c + 370b27d commit 39cfd5f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
4 changes: 2 additions & 2 deletions scripts/create_registry_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Boolean, Index, Float
from sqlalchemy import ForeignKey, UniqueConstraint, Enum
from dataregistry.db_basic import create_db_engine, TableCreator, ownertypeenum, dataorgenum, add_table_row
from dataregistry.db_basic import create_db_engine, TableCreator, ownertypeenum, dataorgenum, add_table_row, SCHEMA_VERSION
from dataregistry.git_util import get_git_info
from dataregistry import __version__

Expand All @@ -17,7 +17,7 @@

parser = argparse.ArgumentParser(description='''
Creates dataregistry tables in specified schema and connection information (config)''', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--schema', help="name of schema to contain tables. Will be created if it doesn't already exist", default="registry_dev")
parser.add_argument('--schema', help="name of schema to contain tables. Will be created if it doesn't already exist", default=f"{SCHEMA_VERSION}")
parser.add_argument('--config', default="", help="path to config file used to establish connection")

args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion src/dataregistry/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.1"
__version__ = "0.2.2"
2 changes: 1 addition & 1 deletion src/dataregistry/db_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'''
Low-level utility routines and classes for accessing the registry
'''
SCHEMA_VERSION = 'registry_dev'
SCHEMA_VERSION = 'registry_beta'

__all__ = ['create_db_engine', 'add_table_row', 'TableCreator',
'TableMetadata', 'SCHEMA_VERSION', 'ownertypeenum', 'dataorgenum']
Expand Down
14 changes: 14 additions & 0 deletions src/dataregistry/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ class Query:
"""

def __init__(self, db_engine, dialect, schema_version=SCHEMA_VERSION):
'''
Create a new Query object. Note this call should be preceded
by a call to create_db_engine, which will return values for
db_engine and dialect
Parameters
----------
db_engine : sqlalchemy engine object
dialect : str
identifies target db type (e.g. 'postgresql')
schema_version : str
Which database schema to connect to.
Current default is 'registry_beta'
'''
self._engine = db_engine
self._dialect = dialect
if dialect == "sqlite":
Expand Down
36 changes: 31 additions & 5 deletions src/dataregistry/registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,36 @@
if os.getenv("DREGS_ROOT_DIR"):
_DEFAULT_ROOT_DIR = os.getenv("DREGS_ROOT_DIR")
else:
_DEFAULT_ROOT_DIR = '/global/cfs/cdirs/desc-co/jrbogart/dregs_root' #temporary
_DEFAULT_ROOT_DIR = "/global/cfs/cdirs/desc-co/registry-beta" #temporary

class Registrar():
'''
Register new datasets, executions ("runs") or alias names
'''
def __init__(self, db_engine, dialect, owner_type, owner=None,
schema_version=SCHEMA_VERSION):
'''
Create a new Registrar object. Note this call should be preceded
by a call to create_db_engine, which will return values for
db_engine and dialect.
Parameters
----------
db_engine : sqlalchemy engine object
dialect : str
identifies target db type (e.g. "postgresql")
owner_type : owenertypeenum
which of the allowed categories will be destination for
new dataset entries
owner : str
Forms part of relative path of dataset location.
Always "production" for production databases.
Otherwise defaults to "."
schema_version : str
Which database schema to connect to.
Current default is 'registry_beta'
'''
self._engine = db_engine
self._dialect = dialect
self._owner_type = owner_type.value
Expand Down Expand Up @@ -77,7 +99,7 @@ def _handle_data(self, relative_path, old_location, verbose):
"""
Find characteristics of dataset (i.e., is it a file or directory, how
many files and total disk space of the dataset).
If old_location is not None, copy the dataset into the data registry.
Parameters
Expand All @@ -99,7 +121,7 @@ def _handle_data(self, relative_path, old_location, verbose):
total_size : float
Total disk space of dataset in bytes
"""

# Get destination directory in data registry.
dest = _form_dataset_path(self._owner_type, self._owner,
relative_path, self._root_dir)
Expand Down Expand Up @@ -219,6 +241,10 @@ def register_dataset(self, relative_path, version,
relative_path : str
Destination for the dataset within the data registry. Path is
relative to ``<registry root>/<owner_type>/<owner>``.
If the environment variable DREGS_ROOT is defined, this
value is used for ``<registry root>``.
Otherwise currently ``<registry root>`` defaults to
/global/cfs/cdirs/desc-co/registry-beta
version : str
Semantic version string of the format MAJOR.MINOR.PATCH *or*
a special flag "patch", "minor" or "major".
Expand Down Expand Up @@ -248,13 +274,13 @@ def register_dataset(self, relative_path, version,
old_location : str, optional
Absolute location of dataset to copy.
If None dataset should already be at correct relative_path.
If None dataset should already be at correct relative_path.
copy : bool, optional
If true copy data from ``old_location`` to the database.
If False create a symlink (defaults to True).
is_dummy : bool
True for "dummy" datasets (no data is copied, for testing purposes
only)
only)
verbose : bool
Provide some additional output information
Expand Down

0 comments on commit 39cfd5f

Please sign in to comment.