Skip to content

Commit

Permalink
Migrate schema to match Bioconductor's BiocFileCache. (#12)
Browse files Browse the repository at this point in the history
- Mostly changing some of the fields from varchar to text (#11)
- Update contributor list
- Update Changelog

Co-authored-by: Khoroshevskyi <[email protected]>
  • Loading branch information
jkanche and khoroshevskyi committed May 23, 2024
1 parent 087837d commit a91d033
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 88 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

* Jayaram Kancherla <[email protected]>
* Max Hargreaves <[email protected]>
* Oleksandr Khoroshevskyi <[email protected]>
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.1 (development)
## Version 0.4 (development)

- Initial release
- Migrate the schema to match R/Bioconductor's BiocFileCache (Check out [this issue](https://github.com/BiocPy/pyBiocFileCache/issues/11)). Thanks to [@khoroshevskyi ](https://github.com/khoroshevskyi) for the PR.

## Version 0.1

- Initial release of the package, Setting up all the actions.
11 changes: 3 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ def setup(app):
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"sidebar_width": "300px",
"page_width": "1200px"
}
html_theme_options = {"sidebar_width": "300px", "page_width": "1200px"}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down Expand Up @@ -266,9 +263,7 @@ def setup(app):

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "user_guide.tex", "pyBiocFileCache Documentation", "jkanche", "manual")
]
latex_documents = [("index", "user_guide.tex", "pyBiocFileCache Documentation", "jkanche", "manual")]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
Expand Down Expand Up @@ -304,4 +299,4 @@ def setup(app):
"pyscaffold": ("https://pyscaffold.org/en/stable", None),
}

print(f"loading configurations for {project} {version} ...", file=sys.stderr)
print(f"loading configurations for {project} {version} ...", file=sys.stderr)
3 changes: 1 addition & 2 deletions src/pybiocfilecache/BiocFileCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from sqlalchemy.orm import Session

from ._exceptions import NoFpathError, RnameExistsError, RpathTimeoutError
from .db import create_schema
from .db.schema import Resource
from .db.db_config import create_schema, Resource
from .utils import copy_or_move, create_tmp_dir, generate_id

__author__ = "Jayaram Kancherla"
Expand Down
4 changes: 2 additions & 2 deletions src/pybiocfilecache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

from .BiocFileCache import BiocFileCache as BiocFileCache

from .db.schema import Metadata as Metadata
from .db.schema import Resource as Resource
from .db.db_config import Metadata as Metadata
from .db.db_config import Resource as Resource

from ._exceptions import NoFpathError as NoFpathError
from ._exceptions import RnameExistsError as RnameExistsError
Expand Down
1 change: 1 addition & 0 deletions src/pybiocfilecache/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SCHEMA_VERSION = "0.99.4"
36 changes: 0 additions & 36 deletions src/pybiocfilecache/db/Base.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/pybiocfilecache/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
__copyright__ = "jkanche"
__license__ = "MIT"

from .Base import create_schema
from .db_config import create_schema
84 changes: 84 additions & 0 deletions src/pybiocfilecache/db/db_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from typing import Tuple

from sqlalchemy import create_engine, select, Column, Integer, Text, DateTime, func
from sqlalchemy.engine import Engine
from sqlalchemy.orm.session import Session

from sqlalchemy.orm import declarative_base, sessionmaker

from ..const import SCHEMA_VERSION

__author__ = "jkanche"
__copyright__ = "jkanche"
__license__ = "MIT"

Base = declarative_base()


class Metadata(Base):
__tablename__ = "metadata"
key = Column(Text(), primary_key=True, index=True)
value = Column(Text())

def __repr__(self):
return "<Metadata(key='%s', valye='%s')>" % (self.key, self.value)


class Resource(Base):
__tablename__ = "resource"
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
rid = Column(Text())
rname = Column(Text())
create_time = Column(DateTime, server_default=func.now())
access_time = Column(DateTime, server_default=func.now())
rpath = Column(Text())
rtype = Column(Text())
fpath = Column(Text())
last_modified_time = Column(DateTime, onupdate=func.now())
etag = Column(Text())
expires = Column(DateTime)

def __repr__(self):
return "<Resource(id='%s', rname='%s')>" % (self.id, self.rname)


def add_metadata(key: str, value: str, engine: Engine) -> None:
"""Add metadata to the database.
Args:
key:
Key of the metadata.
value:
Value of the metadata.
engine:
Engine
"""
with Session(engine) as session:
if session.scalar(select(Metadata).where(Metadata.key == key)):
pass
else:
new_metadata = Metadata(key=key, value=value)
session.add(new_metadata)
session.commit()


def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
"""Create the schema in the sqlite database.
Args:
cache_dir:
Location where the cache directory.
Returns:
A tuple of sqlalchemy engine and session maker.
"""
engine = create_engine(
f"sqlite:///{cache_dir}", connect_args={"check_same_thread": False}
)

Base.metadata.create_all(bind=engine, checkfirst=True)
sessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

add_metadata("schema_version", SCHEMA_VERSION, engine)

return (engine, sessionLocal)
35 changes: 0 additions & 35 deletions src/pybiocfilecache/db/schema.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Dummy conftest.py for pybiocfilecache.
If you don't know what this is for, just leave it empty.
Read more about conftest.py under:
- https://docs.pytest.org/en/stable/fixture.html
- https://docs.pytest.org/en/stable/writing_plugins.html
"""

# import pytest
# import pytest

0 comments on commit a91d033

Please sign in to comment.