-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate schema to match Bioconductor's BiocFileCache. (#12)
- 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
1 parent
087837d
commit a91d033
Showing
11 changed files
with
100 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
* Jayaram Kancherla <[email protected]> | ||
* Max Hargreaves <[email protected]> | ||
* Oleksandr Khoroshevskyi <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SCHEMA_VERSION = "0.99.4" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |