Adding gitignore. Fixing the SQLAlchemy models to load, interconnect as expected.

This commit is contained in:
Aurynn Shaw 2013-08-06 14:19:43 +12:00
parent 28da06ebf9
commit 4c07898182
5 changed files with 18 additions and 12 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

View File

@ -1,11 +1,13 @@
from . import Base
from sqlalchemy import Column, types
from sqlalchemy import Column, String, types, schema, ForeignKey
from sqlalchemy.orm import relationship, backref
from .tenants import Tenant
class Resource(Base):
__tablename__ = "resources"
id = Column(String, primary_key=True)
type_ = Column(String, primary_key=True)
type_ = Column(String)
tenant_id = Column(String, ForeignKey("tenants.id"))
tenant = relationship("Tenant", backref=backref("tenants", order_by="id"))
tenant = relationship("Tenant", backref=backref("tenants", order_by=Tenant.id))

View File

@ -1,10 +1,10 @@
from . import Base
from sqlalchemy import Column, types
from sqlalchemy.schema import CheckConstraint
from sqlalchemy import Column, types, String
class Tenant(Base):
__tablename__ = 'tenants'
# ID is a uuid
id = Column(String, primary_key=True, nullable=False)
other_id = Column(String)
# Some reference data to something else?

View File

@ -1,6 +1,6 @@
from . import Base
from .resource import Resource
from sqlalchemy import Column, types
from .resources import Resource
from sqlalchemy import Column, types, ForeignKey, CheckConstraint, String
from sqlalchemy.orm import relationship, backref
# from sqlalchemy.schema import CheckConstraint
import datetime
@ -12,22 +12,23 @@ class Usage(Base):
__tablename__ = 'usage'
resource_id = Column(String, ForeignKey("resources.id"))
resource = relationship("Resource", backref=backref("resources", order_by="created"))
resource_id = Column(String, ForeignKey("resources.id"), primary_key=True)
# tenant = Column(String, nullable=False)
tenant_id = Column(String, ForeignKey("tenants.id"))
tenant = relationship("Tenant", backref=backref("usage", order_by="created"))
tenant_id = Column(String, ForeignKey("tenants.id"), primary_key=True)
volume = Column(String, nullable=False)
time = Column(TSRANGE, nullable=False)
created = Column(types.DateTime, nullable=False)
resource = relationship("Resource", backref=backref("resources", order_by=created))
tenant = relationship("Tenant", backref=backref("usage", order_by=created))
__table_args__ = (
ExcludeConstraint(
('tenant_id', '='),
('resource_id', '='),
('time', '&&')
),
CheckConstraint("start > end"),
)
def __init__(self, resource, tenant, value, start, end):

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
sqlalchemy>=0.8
psycopg2>=2.5.1