Skip to content

Commit

Permalink
Merge pull request #11 from sdss/archive
Browse files Browse the repository at this point in the history
adds access to archive database to sdssdb
  • Loading branch information
havok2063 authored Sep 24, 2019
2 parents 9a25253 + 7c490a1 commit 3b5f6ad
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ python:
- '2.7'
- '3.5'
- '3.6'
- '3.7'

os:
- linux

matrix:
fast_finish: true
allow_failures:
- python: '2.7'
- python: '3.5'

notifications:
email: false
Expand All @@ -27,7 +31,6 @@ branches:
install:
- pip install -U pip wheel --quiet
- pip install --upgrade setuptools --quiet
- pip install -r requirements.txt --quiet
- pip install pytest
- pip install pytest-coverage
- pip install coveralls
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Changelog
=========

This document records the main changes to the ``sdssdb`` code.

* Added ``archive`` database with ``sas`` schema.

* :release:`0.3.0 <2019-09-23>`
* Removed ``TIC v6``.
* Added ``TIC v8``.
Expand Down
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sdssdb
======

|python| |docs|
|python| |docs| |travis|

`SDSS <https://sdss.org>`__ product for database management.

Expand Down Expand Up @@ -30,3 +30,6 @@ How to use
:alt: Documentation Status
:scale: 100%
:target: https://sdssdb.readthedocs.io/en/latest/?badge=latest

.. |travis| image:: https://travis-ci.org/sdss/sdssdb.svg?branch=master
:target: https://travis-ci.org/sdss/sdssdb
9 changes: 9 additions & 0 deletions docs/sphinx/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Currently, we support the following databases and schemas:
* **sdss5db**: the SDSS-V development database.
* *catalogdb*: schema for source catalogues used for target selection.
* *targetdb*: schema with the results of the target selection and positioner information.
* **archive**: the SDSS science archive database.
* *sas*: schema for SAS.

Note that the level of readiness is not necessarily identical in both Peewee and SQLAlchemy. This table summarises what schemas are available for each library. Green indicates fully supported, yellow partial support, and red means that there are currently not model classes available for that schema. You can download the graph visualisation of the schema, showing the tables, columns, and relations between tables.

Expand Down Expand Up @@ -119,6 +121,13 @@ Note that the level of readiness is not necessarily identical in both Peewee and
<td class="warning"></td>
<td align="center"><a class="glyphicon glyphicon-download-alt" href="_static/schema_graphs/auto/sdss5db.targetdb.pdf"></a></td>
</tr>
<tr>
<td class="active">archive</td>
<td class="active">sas</td>
<td class="danger"></td>
<td class="success"></td>
<td align="center"><a class="glyphicon glyphicon-download-alt" href="../../../../schema/archive/archive_sas.pdf"></a></td>
</tr>
</tbody>
</table>

Expand Down
2 changes: 0 additions & 2 deletions python/sdssdb/etc/sdssdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ lco:
domain: lco.cl

local:
host: localhost
port: 5432
domain: null

lore:
Expand Down
26 changes: 26 additions & 0 deletions python/sdssdb/sqlalchemy/archive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# !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):
dbname = 'archive_20190507'
base = ArchiveBase


database = ArchiveDatabaseConnection(autoconnect=True)
143 changes: 143 additions & 0 deletions python/sdssdb/sqlalchemy/archive/sas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# !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
from sqlalchemy.ext.declarative import AbstractConcreteBase, declared_attr
from sqlalchemy.orm import relationship

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 = ['name']

@property
def name(self):
return self.location.rsplit('/', 1)[-1]


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')
File.directory = relationship(Directory, backref='files')

# class Symlink_directory
SymlinkDirectory.env = relationship(Env, backref='symlink_directories')
SymlinkDirectory.root = relationship(Root, backref='symlink_directories')
# 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='symlink_directories', foreign_keys='SymlinkDirectory.directory_id')
SymlinkDirectory.real_directory = relationship(Directory, backref='linked_symlink_directories',
primaryjoin=('and_(SymlinkDirectory.'
'real_directory_id==Directory.id)'))

SymlinkDirectory.tree = relationship(Tree, backref='symlink_directories',
foreign_keys='SymlinkDirectory.tree_id',
primaryjoin='and_(SymlinkDirectory.tree_id==Tree.id)')
SymlinkDirectory.real_tree = relationship(
Tree, backref='linked_symlink_directories',
primaryjoin='and_(SymlinkDirectory.real_tree_id==Tree.id)')

# class Symlink_file
SymlinkFile.directory = relationship(Directory, backref='symlink_files')
SymlinkFile.env = relationship(Env, backref='symlink_files')
SymlinkFile.real_file = relationship(File, backref='symlink_files')
SymlinkFile.root = relationship(Root, backref='symlink_files',
foreign_keys='SymlinkFile.root_id')

SymlinkFile.tree = relationship(Tree, backref='symlink_files',
foreign_keys='SymlinkFile.tree_id',
primaryjoin='and_(SymlinkFile.tree_id==Tree.id)')
SymlinkFile.real_tree = relationship(
Tree, backref='linked_symlink_files', primaryjoin='and_(SymlinkFile.real_tree_id==Tree.id)')


# prepare the base
database.add_base(Base)
23 changes: 0 additions & 23 deletions python/sdssdb/tests/test_main.py

This file was deleted.

7 changes: 7 additions & 0 deletions python/sdssdb/tests/test_peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
from __future__ import unicode_literals

import sdssdb.peewee.sdss5db.targetdb as targetdb
import pytest


@pytest.fixture(scope='session', autouse=True)
def skipdb():
if targetdb.database.connected is False:
pytest.skip('no targetdb found')


class TestPeewee(object):
Expand Down
Binary file added schema/archive/archive_sas.pdf
Binary file not shown.

0 comments on commit 3b5f6ad

Please sign in to comment.