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 all 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
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):
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
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.