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

adds access to archive database to sdssdb #11

Merged
merged 30 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c0d3fca
archive
Aug 10, 2019
de16086
archive_20190507
Aug 10, 2019
783eb6a
Update sas.py
joelbrownstein Aug 11, 2019
dbfb0c8
Updated define_relations() method in sas module
nbmurphy Sep 4, 2019
b92db30
linting archive sas.py file
havok2063 Sep 18, 2019
d1c9c80
updating relationships
havok2063 Sep 18, 2019
45ab952
updating relationships
havok2063 Sep 18, 2019
51d7dd9
updating relationships
havok2063 Sep 18, 2019
4a5f7f5
updating relationships to fix symlinks and symdirs
havok2063 Sep 18, 2019
aa0f038
cleaning up relationships
havok2063 Sep 18, 2019
a13c28d
updating print_fields
havok2063 Sep 18, 2019
632a3e0
add archive
Sep 18, 2019
4475031
updating backrefs
havok2063 Sep 19, 2019
71daf80
Merge branch 'archive' of https://github.com/sdss/sdssdb into archive
havok2063 Sep 19, 2019
7120537
adding archive db to docs
havok2063 Sep 19, 2019
3130548
updating changelog
havok2063 Sep 19, 2019
8e47785
adding files-dir relationship and name property to file
havok2063 Sep 19, 2019
807faf2
bugfix in relationship name
havok2063 Sep 19, 2019
64bfe1f
Added archive db ER diagram and made associated changes to intro.rst
nbmurphy Sep 20, 2019
3a6b978
fixing link to sas archive pdf schema
havok2063 Sep 23, 2019
2e6c259
merging master
havok2063 Sep 23, 2019
9dbc24b
fixing imports and linting issues
havok2063 Sep 23, 2019
a3dfcf0
fixing linting issues
havok2063 Sep 23, 2019
ba7c843
adding travis status badge
havok2063 Sep 23, 2019
d6ffc9a
removing requirements.txt from travis file
havok2063 Sep 23, 2019
f2cd3bc
adding a skipdb test for travis until db tests can be fixed
havok2063 Sep 23, 2019
4b3d9c6
removing tests for nonexistent code
havok2063 Sep 23, 2019
a6910b6
allowing py2.7 to fail
havok2063 Sep 23, 2019
6b66450
allowing py3.5 to fail since we use fstrings
havok2063 Sep 23, 2019
7c490a1
removing explicit localhost from local profile
havok2063 Sep 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions python/sdssdb/sqlalchemy/archive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# !usr/bin/env python
# -*- coding: utf-8 -*-
#
# Licensed under a 3-clause BSD license.
#
# @Author: Brian Cherinka
# @Date: 2018-09-23 16:06:18
# @Last modified by: José Sánchez-Gallego ([email protected])
# @Last Modified time: 2018-10-10 11:25:13

from __future__ import print_function, division, absolute_import

from sdssdb.connection import SQLADatabaseConnection
from sqlalchemy.ext.declarative import declarative_base, DeferredReflection
from sdssdb.sqlalchemy import BaseModel

# we need a shared common Base when joining across multiple schema
ArchiveBase = declarative_base(cls=(DeferredReflection, BaseModel,))

class ArchiveDatabaseConnection(SQLADatabaseConnection):
havok2063 marked this conversation as resolved.
Show resolved Hide resolved
dbname = 'archive_20190507'
base = ArchiveBase

database = ArchiveDatabaseConnection(autoconnect=True)
havok2063 marked this conversation as resolved.
Show resolved Hide resolved
135 changes: 135 additions & 0 deletions python/sdssdb/sqlalchemy/archive/sas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# !usr/bin/env python
# -*- coding: utf-8 -*-
#
# Licensed under a 3-clause BSD license.
#
# @Author: Joel Brownstein
# @Date: 2019-08-01 06:54:15
# @Last modified by: N Benjamin Murphy ([email protected])
# @Date: 2019-09-04 16:31:00

from __future__ import absolute_import, division, print_function

from sdssdb.sqlalchemy.archive import database, ArchiveBase, sas
havok2063 marked this conversation as resolved.
Show resolved Hide resolved
from sqlalchemy import Column, Float, and_, case, cast, select
from sqlalchemy.engine import reflection
from sqlalchemy.ext.declarative import AbstractConcreteBase, declared_attr
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship
from sqlalchemy.types import Integer

SCHEMA = 'sas'


class Base(AbstractConcreteBase, ArchiveBase):
__abstract__ = True
_schema = SCHEMA
_relations = 'define_relations'

@declared_attr
def __table_args__(cls):
return {'schema': cls._schema}


class Root(Base):
__tablename__ = 'root'
print_fields = ['identifier']


class Tree(Base):
__tablename__ = 'tree'
print_fields = ['version']


class Env(Base):
__tablename__ = 'env'


class Directory(Base):
__tablename__ = 'directory'
print_fields = ['location']


class File(Base):
__tablename__ = 'file'
print_fields = ['location']


class SymlinkFile(Base):
__tablename__ = 'symlink_file'
print_fields = ['location']


class SymlinkDirectory(Base):
__tablename__ = 'symlink_directory'
print_fields = ['location']


class ChecksumFile(Base):
__tablename__ = 'checksumfile'
print_fields = ['filename']


class Checksum(Base):
__tablename__ = 'checksum'


def define_relations():
"""Setup relationships after preparation."""

# model relationships
Root.directories = relationship(Directory, backref='root')
Tree.envs = relationship(Env, backref='tree')

# class Checksum
Checksum.tree = relationship(Tree, backref='checksums')
Checksum.checksumfile = relationship(ChecksumFile, backref='checksums')
Checksum.file = relationship(File, backref='checksums')
Checksum.directory = relationship(Directory, backref='checksums')

# class Checksumfile
ChecksumFile.tree = relationship(Tree, backref='checksumfiles')
ChecksumFile.env = relationship(Env, backref='checksumfile')
ChecksumFile.directory = relationship(Directory, backref='checksumfile')
ChecksumFile.file = relationship(File, backref='checksumfile')

# class Directory
Directory.tree = relationship(Tree, backref='directories')
Directory.env = relationship(Env, backref='directories')

# class Env
# need to specify remote_side when foreign key points to itself
Env.real_env = relationship(Env, remote_side='Env.id', backref='env')

# class File
File.root = relationship(Root, backref='files')
File.tree = relationship(Tree, backref='files')
File.env = relationship(Env, backref='files')

# class Symlink_directory
SymlinkDirectory.env = relationship(Env, backref='symdirs')
SymlinkDirectory.root = relationship(Root, backref='symdirs')
# need to specify foreign_keys when multiple columns points to same key
# need to specify primaryjoin when there are multiple ways to join the tables
SymlinkDirectory.directory = relationship(
Directory, backref='symdir', foreign_keys='SymlinkDirectory.directory_id')
SymlinkDirectory.real_dir = relationship(Directory, backref='realsymdir',
primaryjoin='and_(SymlinkDirectory.real_directory_id==Directory.id)')
SymlinkDirectory.tree = relationship(Tree, backref='symdirs', foreign_keys='SymlinkDirectory.tree_id',
primaryjoin='and_(SymlinkDirectory.tree_id==Tree.id)')
SymlinkDirectory.real_tree = relationship(
Tree, backref='realsymdir', primaryjoin='and_(SymlinkDirectory.real_tree_id==Tree.id)')

# class Symlink_file
SymlinkFile.directory = relationship(Directory, backref='symlinks')
SymlinkFile.env = relationship(Env, backref='symlinks')
SymlinkFile.real_file = relationship(File, backref='symlinks')
SymlinkFile.root = relationship(Root, backref='symlinks', foreign_keys='SymlinkFile.root_id')
SymlinkFile.tree = relationship(Tree, backref='symlinks', foreign_keys='SymlinkFile.tree_id',
primaryjoin='and_(SymlinkFile.tree_id==Tree.id)')
SymlinkFile.real_tree = relationship(
Tree, backref='realsymlinks', primaryjoin='and_(SymlinkFile.real_tree_id==Tree.id)')


# prepare the base
database.add_base(Base)
14 changes: 7 additions & 7 deletions python/sdssdb/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

from pytest import mark

from sdssdb.main import math
# from sdssdb.main import math


class TestMath(object):
"""Tests for the ``math`` function in main.py."""
# class TestMath(object):
# """Tests for the ``math`` function in main.py."""

@mark.parametrize(('arg1', 'arg2', 'operator', 'result'),
[(1, 2, '+', 3), (2, 2, '-', 0), (3, 5, '*', 15), (10, 2, '/', 5)])
def test_math(self, arg1, arg2, operator, result):
# @mark.parametrize(('arg1', 'arg2', 'operator', 'result'),
# [(1, 2, '+', 3), (2, 2, '-', 0), (3, 5, '*', 15), (10, 2, '/', 5)])
# def test_math(self, arg1, arg2, operator, result):

assert math(arg1, arg2, arith_operator=operator) == result
# assert math(arg1, arg2, arith_operator=operator) == result