[ckan-changes] commit/ckan: kindly: [group] backport add member table
Bitbucket
commits-noreply at bitbucket.org
Thu Jun 23 16:49:22 UTC 2011
1 new changeset in ckan:
http://bitbucket.org/okfn/ckan/changeset/9c303fdfbf14/
changeset: 9c303fdfbf14
branch: feature-1198-publisher-hierarcy
user: kindly
date: 2011-06-23 18:26:36
summary: [group] backport add member table
affected #: 2 files (1.8 KB)
--- a/ckan/migration/versions/040_add_user_group_tables.py Wed Jun 22 23:06:19 2011 +0100
+++ b/ckan/migration/versions/040_add_user_group_tables.py Thu Jun 23 17:26:36 2011 +0100
@@ -1,67 +1,74 @@
from migrate import *
def upgrade(migrate_engine):
-
migrate_engine.execute('''
BEGIN;
-CREATE TABLE user_group (
- id text NOT NULL,
- name text NOT NULL,
- parent_id text
+CREATE TABLE "member" (
+ id text NOT NULL,
+ user_id text,
+ group_id text,
+ capacity text,
+ "state" text,
+ revision_id text
);
-CREATE TABLE user_group_extra (
- id text NOT NULL,
- user_group_id text NOT NULL,
- "key" text NOT NULL,
- "value" text NOT NULL
-);
+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
+);
+
-CREATE TABLE user_group_package (
- id text NOT NULL,
- user_group_id text NOT NULL,
- package_id text NOT NULL,
- capacity text
-);
+ALTER TABLE "group"
+ ADD COLUMN parent_id text;
-CREATE TABLE user_group_user (
- id text NOT NULL,
- user_group_id text NOT NULL,
- user_id text NOT NULL,
- capacity text
-);
+ALTER TABLE group_revision
+ ADD COLUMN parent_id text;
+ALTER TABLE package_group
+ ADD COLUMN capacity text,
+ ADD COLUMN type text;
-ALTER TABLE user_group
- ADD CONSTRAINT user_group_pkey PRIMARY KEY (id);
+ALTER TABLE package_group_revision
+ ADD COLUMN capacity text,
+ ADD COLUMN type text;
-ALTER TABLE user_group_extra
- ADD CONSTRAINT user_group_extra_pkey PRIMARY KEY (id);
+ALTER TABLE "member"
+ ADD CONSTRAINT member_pkey PRIMARY KEY (id);
-ALTER TABLE user_group_package
- ADD CONSTRAINT user_group_package_pkey PRIMARY KEY (id);
+ALTER TABLE "member"
+ ADD CONSTRAINT member_group_id_fkey FOREIGN KEY (group_id) REFERENCES "group"(id);
-ALTER TABLE user_group_user
- ADD CONSTRAINT user_group_user_pkey PRIMARY KEY (id);
+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 user_group_extra
- ADD CONSTRAINT user_group_extra_user_group_id_fkey FOREIGN KEY (user_group_id) REFERENCES user_group(id);
-
-ALTER TABLE user_group_package
- ADD CONSTRAINT user_group_package_package_id_fkey FOREIGN KEY (package_id) REFERENCES package(id);
-
-ALTER TABLE user_group_package
- ADD CONSTRAINT user_group_package_user_group_id_fkey FOREIGN KEY (user_group_id) REFERENCES user_group(id);
-
-ALTER TABLE user_group_user
- ADD CONSTRAINT user_group_user_user_group_id_fkey FOREIGN KEY (user_group_id) REFERENCES user_group(id);
-
-ALTER TABLE user_group_user
- ADD CONSTRAINT user_group_user_user_id_fkey FOREIGN KEY (user_id) REFERENCES "user"(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 Wed Jun 22 23:06:19 2011 +0100
+++ b/ckan/model/group.py Thu Jun 23 17:26:36 2011 +0100
@@ -1,8 +1,11 @@
+from datetime import datetime
+
from meta import *
from core import *
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
@@ -10,12 +13,25 @@
__all__ = ['group_table', 'Group', 'package_revision_table',
'PackageGroup', 'GroupRevision', 'PackageGroupRevision',
- 'package_group_revision_table']
+ 'package_group_revision_table', 'Member', 'member_table',
+ 'member_revision_table']
+
+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')),
Column('group_id', UnicodeText, ForeignKey('group.id')),
+ Column('capacity', UnicodeText),
+ Column('type', UnicodeText),
)
vdm.sqlalchemy.make_table_stateful(package_group_table)
@@ -27,6 +43,7 @@
Column('title', UnicodeText),
Column('description', UnicodeText),
Column('created', DateTime, default=datetime.now),
+ Column('parent_id', UnicodeText),
)
vdm.sqlalchemy.make_table_stateful(group_table)
@@ -38,6 +55,11 @@
DomainObject):
pass
+class Member(vdm.sqlalchemy.RevisionedObjectMixin,
+ vdm.sqlalchemy.StatefulObjectMixin,
+ DomainObject):
+ pass
+
class Group(vdm.sqlalchemy.RevisionedObjectMixin,
vdm.sqlalchemy.StatefulObjectMixin,
DomainObject):
@@ -138,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)
@@ -148,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