add a site/authority x user/person relationship in registry model for
[sfa.git] / sfa / storage / migrations / versions / 002_authority_pis.py
diff --git a/sfa/storage/migrations/versions/002_authority_pis.py b/sfa/storage/migrations/versions/002_authority_pis.py
new file mode 100644 (file)
index 0000000..e234a2f
--- /dev/null
@@ -0,0 +1,28 @@
+# this move is about adding a authority x user many to many relation ship for modelling PIs
+# that is to say users who can vouch for other users in the authority, and can create slices
+
+from sqlalchemy import Table, MetaData, Column, ForeignKey
+from sqlalchemy import Integer, String
+
+metadata=MetaData()
+
+# this is needed my migrate so it can locate 'records.record_id'
+records = \
+    Table ( 'records', metadata,
+            Column ('record_id', Integer, primary_key=True),
+            )
+
+# authority x user (PIs) association
+authority_pi_table = \
+    Table ( 'authority_pi', metadata,
+            Column ('authority_id', Integer, ForeignKey ('records.record_id'), primary_key=True),
+            Column ('pi_id', Integer, ForeignKey ('records.record_id'), primary_key=True),
+            )
+
+def upgrade(migrate_engine):
+    metadata.bind = migrate_engine
+    authority_pi_table.create()
+
+def downgrade(migrate_engine):
+    metadata.bind = migrate_engine
+    authority_pi_table.drop()