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 4 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
127 changes: 127 additions & 0 deletions python/sdssdb/sqlalchemy/archive/sas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# !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'

class Tree(Base):
__tablename__ = 'tree'

class Env(Base):
__tablename__ = 'env'

class Directory(Base):
__tablename__ = 'directory'

class File(Base):
__tablename__ = 'file'

class Symlink_file(Base):
__tablename__ = 'symlink_file'

class Symlink_directory(Base):
__tablename__ = 'symlink_directory'

class Checksumfile(Base):
__tablename__ = 'checksumfile'

class Checksum(Base):
__tablename__ = 'checksum'

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

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

#class Checksum
#tree_id = db.Column(db.Integer, db.ForeignKey('%s.tree.id' % schema))
#checksumfile_id = db.Column(db.Integer, db.ForeignKey('%s.checksumfile.id' % schema), nullable=False)
#file_id = db.Column(db.Integer, db.ForeignKey('%s.file.id' % schema))
#directory_id = db.Column(db.Integer, db.ForeignKey('%s.directory.id' % schema), nullable=False)
Checksum.tree = relationship(Tree, backref='checksum')
Checksum.checksumfile = relationship(Checksumfile, backref='checksum')
Checksum.file = relationship(File, backref='checksum')
Checksum.directory = relationship(Directory, backref='checksum')

#class Checksumfile
#tree_id = db.Column(db.Integer, db.ForeignKey('%s.tree.id' % schema))
#env_id = db.Column(db.Integer, db.ForeignKey('%s.env.id' % schema))
#directory_id = db.Column(db.Integer, db.ForeignKey('%s.directory.id' % schema), nullable=False)
#file_id = db.Column(db.Integer, db.ForeignKey('%s.file.id' % schema), nullable=False)
Checksumfile.tree = relationship(Tree, backref='checksumfile')
Checksumfile.env = relationship(Env, backref='checksumfile')
Checksumfile.directory = relationship(Directory, backref='checksumfile')
Checksumfile.file = relationship(File, backref='checksumfile')

#class Directory
#root_id = db.Column(db.Integer, db.ForeignKey('%s.root.id' % schema), nullable = False)
#tree_id = db.Column(db.Integer, db.ForeignKey('%s.tree.id' % schema))
#env_id = db.Column(db.Integer, db.ForeignKey('%s.env.id' % schema))
Directory.root = relationship(Root, backref='directory')
Directory.tree = relationship(Tree, backref='directory')
Directory.env = relationship(Env, backref='directory')

#class Env
#tree_id = db.Column(db.Integer, db.ForeignKey('%s.tree.id' % schema))
#real_env_id = db.Column(db.Integer, db.ForeignKey('%s.env.id' % schema))
Env.tree = relationship(Tree, backref='env')
Env.real_env = relationship(Env)

#class File
#root_id = db.Column(db.Integer, db.ForeignKey('%s.root.id' % schema), nullable = False)
#tree_id = db.Column(db.Integer, db.ForeignKey('%s.tree.id' % schema))
#env_id = db.Column(db.Integer, db.ForeignKey('%s.env.id' % schema))
File.root = relationship(Root, backref='file')
File.tree = relationship(Tree, backref='file')
File.env = relationship(Env, backref='file')

#class Symlink_directory
#root_id = db.Column(db.Integer, db.ForeignKey('%s.root.id' % schema), nullable = False)
#tree_id = db.Column(db.Integer, db.ForeignKey('%s.tree.id' % schema))
#env_id = db.Column(db.Integer, db.ForeignKey('%s.env.id' % schema))
Symlink_directory.root = relationship(Root, backref='symlink_directory')
Symlink_directory.tree = relationship(Tree, backref='symlink_directory')
Symlink_directory.env = relationship(Env, backref='symlink_directory')

#class Symlink_file
#root_id = db.Column(db.Integer, db.ForeignKey('%s.root.id' % schema), nullable = False)
#tree_id = db.Column(db.Integer, db.ForeignKey('%s.tree.id' % schema))
#env_id = db.Column(db.Integer, db.ForeignKey('%s.env.id' % schema))
Symlink_file.root = relationship(Root, backref='symlink_file')
Symlink_file.tree = relationship(Tree, backref='symlink_file')
Symlink_file.env = relationship(Env, backref='symlink_file')

# prepare the base
database.add_base(Base)