[ckan-changes] commit/ckan: kindly: [group] add member table
Bitbucket
commits-noreply at bitbucket.org
Thu Jun 23 15:12:49 UTC 2011
1 new changeset in ckan:
http://bitbucket.org/okfn/ckan/changeset/db87fdf02610/
changeset: db87fdf02610
branch: feature-1094-authz
user: kindly
date: 2011-06-23 17:12:32
summary: [group] add member table
affected #: 2 files (2.2 KB)
--- a/ckan/migration/versions/040_add_user_group_tables.py Thu Jun 23 14:58:11 2011 +0100
+++ b/ckan/migration/versions/040_add_user_group_tables.py Thu Jun 23 16:12:32 2011 +0100
@@ -2,13 +2,33 @@
def upgrade(migrate_engine):
migrate_engine.execute('''
+
+BEGIN;
+
CREATE TABLE "member" (
id text NOT NULL,
user_id text,
group_id text,
- capacity text
+ capacity text,
+ "state" text,
+ revision_id text
);
+CREATE TABLE member_revision (
+ id text NOT NULL,
+ user_id text,
+ group_id text,
+ capacity text,
+ "state" text,
+ revision_id text NOT NULL,
+ continuity_id text,
+ expired_id text,
+ revision_timestamp timestamp without time zone,
+ expired_timestamp timestamp without time zone,
+ "current" boolean
+);
+
+
ALTER TABLE "group"
ADD COLUMN parent_id text;
@@ -31,4 +51,24 @@
ALTER TABLE "member"
ADD CONSTRAINT member_user_id_fkey FOREIGN KEY (user_id) REFERENCES "user"(id);
+
+ALTER TABLE "member"
+ ADD CONSTRAINT member_revision_id_fkey FOREIGN KEY (revision_id) REFERENCES revision(id);
+
+ALTER TABLE member_revision
+ ADD CONSTRAINT member_revision_pkey PRIMARY KEY (id, revision_id);
+
+ALTER TABLE member_revision
+ ADD CONSTRAINT member_revision_continuity_id_fkey FOREIGN KEY (continuity_id) REFERENCES member(id);
+
+ALTER TABLE member_revision
+ ADD CONSTRAINT member_revision_group_id_fkey FOREIGN KEY (group_id) REFERENCES "group"(id);
+
+ALTER TABLE member_revision
+ ADD CONSTRAINT member_revision_revision_id_fkey FOREIGN KEY (revision_id) REFERENCES revision(id);
+
+ALTER TABLE member_revision
+ ADD CONSTRAINT member_revision_user_id_fkey FOREIGN KEY (user_id) REFERENCES "user"(id);
+
+COMMIT;
''')
--- a/ckan/model/group.py Thu Jun 23 14:58:11 2011 +0100
+++ b/ckan/model/group.py Thu Jun 23 16:12:32 2011 +0100
@@ -5,6 +5,7 @@
from sqlalchemy.orm import eagerload_all
from domain_object import DomainObject
from package import *
+from user import *
from types import make_uuid
import vdm.sqlalchemy
from ckan.model import extension
@@ -12,15 +13,19 @@
__all__ = ['group_table', 'Group', 'package_revision_table',
'PackageGroup', 'GroupRevision', 'PackageGroupRevision',
- 'package_group_revision_table']
+ 'package_group_revision_table', 'Member', 'member_table',
+ 'member_revision_table']
-user_group_table = Table('member', metadata,
+member_table = Table('member', metadata,
Column('id', UnicodeText, primary_key=True, default=make_uuid),
Column('user_id', UnicodeText, ForeignKey('user.id')),
Column('group_id', UnicodeText, ForeignKey('group.id')),
Column('capacity', UnicodeText),
)
+vdm.sqlalchemy.make_table_stateful(member_table)
+member_revision_table = make_revisioned_table(member_table)
+
package_group_table = Table('package_group', metadata,
Column('id', UnicodeText, primary_key=True, default=make_uuid),
Column('package_id', UnicodeText, ForeignKey('package.id')),
@@ -50,6 +55,11 @@
DomainObject):
pass
+class Member(vdm.sqlalchemy.RevisionedObjectMixin,
+ vdm.sqlalchemy.StatefulObjectMixin,
+ DomainObject):
+ pass
+
class Group(vdm.sqlalchemy.RevisionedObjectMixin,
vdm.sqlalchemy.StatefulObjectMixin,
DomainObject):
@@ -150,6 +160,17 @@
extension=[vdm.sqlalchemy.Revisioner(package_group_revision_table),],
)
+mapper(Member, member_table, properties={
+ 'group': relation(Group,
+ backref=backref('member_all', cascade='all, delete-orphan'),
+ ),
+ 'user': relation(User,
+ backref=backref('member_all', cascade='all, delete-orphan'),
+ ),
+},
+ extension=[vdm.sqlalchemy.Revisioner(member_revision_table),],
+)
+
def _create_group(group):
return PackageGroup(group=group)
@@ -160,11 +181,26 @@
Group.packages = association_proxy('package_group_all', 'package', creator=_create_package)
+def _create_member_group(group):
+ return Member(group=group)
+
+def _create_user(user):
+ return Member(user=user)
+
+User.groups = association_proxy('member_all', 'group', creator=_create_member_group)
+Group.users = association_proxy('member_all', 'user', creator=_create_user)
+
+
vdm.sqlalchemy.modify_base_object_mapper(PackageGroup, Revision, State)
PackageGroupRevision = vdm.sqlalchemy.create_object_version(mapper, PackageGroup,
package_group_revision_table)
+vdm.sqlalchemy.modify_base_object_mapper(Member, Revision, State)
+MemberRevision = vdm.sqlalchemy.create_object_version(mapper, Member,
+ member_revision_table)
+
+
from vdm.sqlalchemy.base import add_stateful_versioned_m2m
#vdm.sqlalchemy.add_stateful_versioned_m2m(Package, PackageGroup, 'groups', 'group',
# 'package_group')
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list