summaryrefslogtreecommitdiffstats
path: root/proxy/schema
diff options
context:
space:
mode:
authorMike McCune <mmccune@gibson.pdx.redhat.com>2009-06-25 11:18:32 -0700
committerMike McCune <mmccune@gibson.pdx.redhat.com>2009-06-25 11:18:54 -0700
commit58173c3af215c429f17cf3b39cec6ecf37f6fd50 (patch)
treeb09ebe99130844f379d26eb10c1bb00f135badb7 /proxy/schema
parente8ca5b8312020635e352ff6d0f6c18742a9ba3b0 (diff)
downloadcandlepin-58173c3af215c429f17cf3b39cec6ecf37f6fd50.tar.gz
candlepin-58173c3af215c429f17cf3b39cec6ecf37f6fd50.tar.xz
candlepin-58173c3af215c429f17cf3b39cec6ecf37f6fd50.zip
model generation in sqlalchemy
Diffstat (limited to 'proxy/schema')
-rw-r--r--proxy/schema/README.txt1
-rw-r--r--proxy/schema/model/model.py59
2 files changed, 60 insertions, 0 deletions
diff --git a/proxy/schema/README.txt b/proxy/schema/README.txt
new file mode 100644
index 0000000..be06734
--- /dev/null
+++ b/proxy/schema/README.txt
@@ -0,0 +1 @@
+Files in this directory define the datamodel for the Entitlement Proxy.
diff --git a/proxy/schema/model/model.py b/proxy/schema/model/model.py
new file mode 100644
index 0000000..5a4dc92
--- /dev/null
+++ b/proxy/schema/model/model.py
@@ -0,0 +1,59 @@
+import sqlalchemy
+from sqlalchemy import create_engine
+from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
+from sqlalchemy.orm import mapper
+from sqlalchemy.orm import sessionmaker
+
+# engine = create_engine('sqlite:///:memory:', echo=True)
+engine = create_engine('postgres://mmccune:mmccune@127.0.0.1:5432/candlepin')
+
+metadata = MetaData()
+
+org_table = Table('org', metadata,
+ Column('uuid', String, primary_key=True),
+ Column('name', String))
+
+entitlement_table = Table('entitlement', metadata,
+ Column('uuid', String, primary_key=True),
+ Column('name', String),
+ Column('org', String, ForeignKey('org.uuid')),
+ Column('parent', String, ForeignKey('entitlement.uuid')))
+
+consumer_table = Table('consumer', metadata,
+ Column('uuid', String, primary_key=True),
+ Column('name', String),
+ Column('type', String),
+ Column('org', String, ForeignKey('org.uuid')),
+ Column('parent', String, ForeignKey('consumer.uuid')))
+
+product_definition_table = Table('product_definition', metadata,
+ Column('uuid', String, primary_key=True),
+ Column('name', String))
+
+entitlement_pool_table = Table('entitlement_pool', metadata,
+ Column('uuid', String, primary_key=True),
+ Column('name', String),
+ Column('org', String, ForeignKey('org.uuid')),
+ Column('product_definition', String, ForeignKey('product_definition.uuid')))
+
+metadata.create_all(engine)
+
+
+class Org(object):
+ def __init__(self, uuid, name):
+ self.uuid = uuid
+ self.name = name
+
+ def __repr__(self):
+ return "<Org('%s','%s')>" % (self.uuid, self.name)
+
+mapper(Org, org_table)
+
+Session = sessionmaker(bind=engine)
+session = Session()
+
+org1 = Org('289489090234', 'test org')
+session.add(org1)
+
+lookedup = session.query(Org).filter_by(name='test org').first()
+print lookedup.uuid