-
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.
Merge pull request #11 from sdss/archive
adds access to archive database to sdssdb
- Loading branch information
Showing
10 changed files
with
197 additions
and
27 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
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 |
---|---|---|
|
@@ -14,8 +14,6 @@ lco: | |
domain: lco.cl | ||
|
||
local: | ||
host: localhost | ||
port: 5432 | ||
domain: null | ||
|
||
lore: | ||
|
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,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) |
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,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) |
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
Binary file not shown.