

COMMENT ON TABLE grouper_ddl IS 'holds a record for each database object name, and db version, and java version';

COMMENT ON COLUMN grouper_ddl.id IS 'uuid of this ddl record';

COMMENT ON COLUMN grouper_ddl.object_name IS 'Corresponds to an enum in grouper.ddl package (with Ddl on end), represents one module, so grouper itself is one object';

COMMENT ON COLUMN grouper_ddl.db_version IS 'Version of this object as far as DB knows about';

COMMENT ON COLUMN grouper_ddl.last_updated IS 'last update timestamp, string so it can easily be used from update statement';

COMMENT ON COLUMN grouper_ddl.history IS 'history of this object name, with most recent first (truncated after 4k)';

COMMENT ON TABLE grouper_attributes IS 'attributes for groups, including name, extension, etc';

COMMENT ON COLUMN grouper_attributes.id IS 'db id of this attribute record';

COMMENT ON COLUMN grouper_attributes.group_id IS 'group_uuid foreign key';

COMMENT ON COLUMN grouper_attributes.field_id IS 'foreign key to field by id';

COMMENT ON COLUMN grouper_attributes.value IS 'value this attribute record';

COMMENT ON COLUMN grouper_attributes.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_composites IS 'records the composite group, and its factors';

COMMENT ON COLUMN grouper_composites.id IS 'db id of this composite record';

COMMENT ON COLUMN grouper_composites.owner IS 'group uuid of the composite group';

COMMENT ON COLUMN grouper_composites.left_factor IS 'left factor of the composite group';

COMMENT ON COLUMN grouper_composites.right_factor IS 'right factor of the composite group';

COMMENT ON COLUMN grouper_composites.type IS 'e.g. union, complement, intersection';

COMMENT ON COLUMN grouper_composites.creator_id IS 'member uuid of who created this';

COMMENT ON COLUMN grouper_composites.create_time IS 'number of millis since 1970 until when created';

COMMENT ON COLUMN grouper_composites.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_fields IS 'describes fields related to types';

COMMENT ON COLUMN grouper_fields.id IS 'db id of this field record';

COMMENT ON COLUMN grouper_fields.grouptype_uuid IS 'foreign key to group type';

COMMENT ON COLUMN grouper_fields.is_nullable IS 'if this is nullable';

COMMENT ON COLUMN grouper_fields.name IS 'name of the field';

COMMENT ON COLUMN grouper_fields.read_privilege IS 'which privilege is required to read this field';

COMMENT ON COLUMN grouper_fields.type IS 'type of field (e.g. attribute, list, access, naming)';

COMMENT ON COLUMN grouper_fields.write_privilege IS 'which privilege is required to write this attribute';

COMMENT ON TABLE grouper_groups IS 'holds the groups in the grouper system';

COMMENT ON COLUMN grouper_groups.id IS 'db id of this group record';

COMMENT ON COLUMN grouper_groups.parent_stem IS 'uuid of the stem that this group refers to';

COMMENT ON COLUMN grouper_groups.creator_id IS 'member uuid of the creator of this group';

COMMENT ON COLUMN grouper_groups.create_time IS 'number of millis since 1970 that this group was created';

COMMENT ON COLUMN grouper_groups.modifier_id IS 'member uuid of the last modifier of this group';

COMMENT ON COLUMN grouper_groups.modify_time IS 'number of millis since 1970 that this group was modified';

COMMENT ON COLUMN grouper_groups.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_groups_types IS 'holds the association between group and type';

COMMENT ON COLUMN grouper_groups_types.id IS 'id of this group/type record';

COMMENT ON COLUMN grouper_groups_types.group_uuid IS 'group uuid foreign key';

COMMENT ON COLUMN grouper_groups_types.type_uuid IS 'type uuid foreign key';

COMMENT ON COLUMN grouper_groups_types.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_members IS 'keeps track of subjects used in grouper.  Records are never deleted from this table';

COMMENT ON COLUMN grouper_members.id IS 'db id of this row';

COMMENT ON COLUMN grouper_members.subject_id IS 'subject id is the id from the subject source';

COMMENT ON COLUMN grouper_members.subject_source IS 'id of the source from sources.xml';

COMMENT ON COLUMN grouper_members.subject_type IS 'type of subject, e.g. person';

COMMENT ON COLUMN grouper_members.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_memberships IS 'keeps track of memberships and permissions';

COMMENT ON COLUMN grouper_memberships.id IS 'db id of this row';

COMMENT ON COLUMN grouper_memberships.owner_id IS 'group of the membership';

COMMENT ON COLUMN grouper_memberships.member_id IS 'member of the memership';

COMMENT ON COLUMN grouper_memberships.field_id IS 'foreign key to field by id';

COMMENT ON COLUMN grouper_memberships.mship_type IS 'type of membership, one of the three: immediate, effective, composite';

COMMENT ON COLUMN grouper_memberships.via_id IS 'if effective, this is the group above the member in the chain, for composite, this is the composite uuid';

COMMENT ON COLUMN grouper_memberships.depth IS 'for effective membership, the number of hops (excluding composites) along the membership graph';

COMMENT ON COLUMN grouper_memberships.parent_membership IS 'for effective membership, uuid of membership record from the group in question to the parent group of the member';

COMMENT ON COLUMN grouper_memberships.creator_id IS 'member uuid of the creator of this record';

COMMENT ON COLUMN grouper_memberships.create_time IS 'number of millis since 1970 that this record was created';

COMMENT ON COLUMN grouper_memberships.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_stems IS 'entries for stems and their attributes';

COMMENT ON COLUMN grouper_stems.id IS 'db id of this row';

COMMENT ON COLUMN grouper_stems.parent_stem IS 'stem uuid of parent stem or empty if under root';

COMMENT ON COLUMN grouper_stems.name IS 'full name (id) path of stem';

COMMENT ON COLUMN grouper_stems.display_name IS 'full dislpay name path of stem';

COMMENT ON COLUMN grouper_stems.creator_id IS 'member_id of who created this stem';

COMMENT ON COLUMN grouper_stems.create_time IS 'number of millis since 1970 since this was created';

COMMENT ON COLUMN grouper_stems.modifier_id IS 'member_id of modifier who last edited';

COMMENT ON COLUMN grouper_stems.modify_time IS 'number of millis since 1970 since this was edited';

COMMENT ON COLUMN grouper_stems.display_extension IS 'display extension (not full path) of stem';

COMMENT ON COLUMN grouper_stems.extension IS 'extension (id) (not full path) of this stem';

COMMENT ON COLUMN grouper_stems.description IS 'description of stem';

COMMENT ON COLUMN grouper_stems.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_types IS 'the various types which can be assigned to groups';

COMMENT ON COLUMN grouper_types.id IS 'db id of this row';

COMMENT ON COLUMN grouper_types.name IS 'name of this type';

COMMENT ON COLUMN grouper_types.creator_uuid IS 'member_id of the creator';

COMMENT ON COLUMN grouper_types.create_time IS 'number of millis since 1970 since this was created';

COMMENT ON COLUMN grouper_types.is_assignable IS 'if this type is assignable (not internal)';

COMMENT ON COLUMN grouper_types.is_internal IS 'if this type if internal (not assignable)';

COMMENT ON COLUMN grouper_types.hibernate_version_number IS 'hibernate uses this to version rows';

COMMENT ON TABLE grouper_loader_log IS 'log table with a row for each grouper loader job run';

COMMENT ON COLUMN grouper_loader_log.id IS 'uuid of this log record';

COMMENT ON COLUMN grouper_loader_log.job_name IS 'Could be group name (friendly) or just config name';

COMMENT ON COLUMN grouper_loader_log.status IS 'STARTED, RUNNING, SUCCESS, ERROR, WARNING, CONFIG_ERROR';

COMMENT ON COLUMN grouper_loader_log.started_time IS 'When the job was started';

COMMENT ON COLUMN grouper_loader_log.ended_time IS 'When the job ended (might be blank if daemon died)';

COMMENT ON COLUMN grouper_loader_log.millis IS 'Milliseconds this process took';

COMMENT ON COLUMN grouper_loader_log.millis_get_data IS 'Milliseconds this process took to get the data from the source';

COMMENT ON COLUMN grouper_loader_log.millis_load_data IS 'Milliseconds this process took to load the data to grouper';

COMMENT ON COLUMN grouper_loader_log.job_type IS 'GrouperLoaderJobType enum value';

COMMENT ON COLUMN grouper_loader_log.job_schedule_type IS 'GrouperLoaderJobscheduleType enum value';

COMMENT ON COLUMN grouper_loader_log.job_description IS 'More information about the job';

COMMENT ON COLUMN grouper_loader_log.job_message IS 'Could be a status or error message or stack';

COMMENT ON COLUMN grouper_loader_log.host IS 'Host that this job ran on';

COMMENT ON COLUMN grouper_loader_log.group_uuid IS 'If this job involves one group, this is uuid';

COMMENT ON COLUMN grouper_loader_log.job_schedule_quartz_cron IS 'Quartz cron string for this col';

COMMENT ON COLUMN grouper_loader_log.job_schedule_interval_seconds IS 'How many seconds this is supposed to wait between runs';

COMMENT ON COLUMN grouper_loader_log.last_updated IS 'When this record was last updated';

COMMENT ON COLUMN grouper_loader_log.unresolvable_subject_count IS 'The number of records which were not subject resolvable';

COMMENT ON COLUMN grouper_loader_log.insert_count IS 'The number of records inserted';

COMMENT ON COLUMN grouper_loader_log.update_count IS 'The number of records updated';

COMMENT ON COLUMN grouper_loader_log.delete_count IS 'The number of records deleted';

COMMENT ON COLUMN grouper_loader_log.total_count IS 'The total number of records (e.g. total number of members)';

COMMENT ON COLUMN grouper_loader_log.parent_job_name IS 'If this job is a subjob of another job, then put the parent job name here';

COMMENT ON COLUMN grouper_loader_log.parent_job_id IS 'If this job is a subjob of another job, then put the parent job id here';

COMMENT ON COLUMN grouper_loader_log.and_group_names IS 'If this group query is anded with another group or groups, they are listed here comma separated';

COMMENT ON COLUMN grouper_loader_log.job_schedule_priority IS 'Priority of this job (5 is unprioritized, higher the better)';

CREATE OR REPLACE VIEW grouper_attributes_v (GROUP_NAME, ATTRIBUTE_NAME, ATTRIBUTE_VALUE, GROUP_TYPE_NAME, FIELD_ID, ATTRIBUTE_ID, GROUP_ID, GROUPTYPE_UUID) AS select  (select ga2.value from grouper_attributes ga2 , grouper_fields gf where ga2.group_id = gg.id and gf.name = 'name' and gf.id = ga2.field_id) as group_name, gf.NAME as attribute_name, ga.VALUE as attribute_value, gt.NAME as group_type_name, ga.FIELD_ID, ga.ID as attribute_id, gg.ID as group_id, gf.grouptype_uuid from grouper_attributes ga, grouper_groups gg, grouper_fields gf, grouper_types gt where ga.FIELD_ID = gf.ID and ga.GROUP_ID = gg.ID and gf.GROUPTYPE_UUID = gt.ID ;

COMMENT ON VIEW grouper_attributes_v IS 'Join of groups and attributes with friendly names.  Attributes are name/value pairs for groups.  Each group type is related to a set of 0 to many attributes, each attribute is related to one group type.grouper_fields holds each attribute name under the field type of ^attribute^';

COMMENT ON COLUMN grouper_attributes_v.GROUP_NAME IS 'Group name is full ip path, e.g. school:stem1:groupId';

COMMENT ON COLUMN grouper_attributes_v.ATTRIBUTE_NAME IS 'Attribute name is the name of the name/value pair';

COMMENT ON COLUMN grouper_attributes_v.ATTRIBUTE_VALUE IS 'Attribute value is the value of the name/value pair';

COMMENT ON COLUMN grouper_attributes_v.GROUP_TYPE_NAME IS 'Group_type_name is the name of the group type this attribute is related to';

COMMENT ON COLUMN grouper_attributes_v.FIELD_ID IS 'Field_id is the uuid that uniquely identifies a the field';

COMMENT ON COLUMN grouper_attributes_v.ATTRIBUTE_ID IS 'Attribute_id is the uuid that uniquely identifies the pairing of group and attribute';

COMMENT ON COLUMN grouper_attributes_v.GROUP_ID IS 'Group_id is the uuid that uniquely identifies a group';

COMMENT ON COLUMN grouper_attributes_v.GROUPTYPE_UUID IS 'GroupType_uuid is the uuid that uniquely identifies a group type';

CREATE OR REPLACE VIEW grouper_composites_v (OWNER_GROUP_NAME, COMPOSITE_TYPE, LEFT_FACTOR_GROUP_NAME, RIGHT_FACTOR_GROUP_NAME, OWNER_GROUP_DISPLAYNAME, LEFT_FACTOR_GROUP_DISPLAYNAME, RIGHT_FACTOR_GROUP_DISPLAYNAME, OWNER_GROUP_ID, LEFT_FACTOR_GROUP_ID, RIGHT_FACTOR_GROUP_ID, COMPOSITE_ID, CREATE_TIME, CREATOR_ID, HIBERNATE_VERSION_NUMBER) AS select (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gc.owner and gf.name = 'name' and gf.id = ga.field_id) as owner_group_name, gc.TYPE as composite_type, (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gc.left_factor and gf.name = 'name' and gf.id = ga.field_id) as left_factor_group_name, (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gc.right_factor and gf.name = 'name' and gf.id = ga.field_id) as right_factor_group_name, (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gc.owner and gf.name = 'displayName' and gf.id = ga.field_id) as owner_group_displayname, (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gc.left_factor and gf.name = 'displayName' and gf.id = ga.field_id) as left_factor_group_displayname, (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gc.right_factor and gf.name = 'displayName' and gf.id = ga.field_id) as right_factor_group_displayname, gc.OWNER as owner_group_id, gc.LEFT_FACTOR as left_factor_group_id, gc.RIGHT_FACTOR as right_factor_group_id, gc.ID as composite_id, gc.CREATE_TIME, gc.CREATOR_ID, gc.HIBERNATE_VERSION_NUMBER from grouper_composites gc ;

COMMENT ON VIEW grouper_composites_v IS 'Grouper_composites_v is a view of composite relationships with friendly names.  A composite is a joining of two groups with a group math operator of: union, intersection, or complement.';

COMMENT ON COLUMN grouper_composites_v.OWNER_GROUP_NAME IS 'OWNER_GROUP_NAME: Name of the group which is the result of the composite operation, e.g. school:stem1:allPeople';

COMMENT ON COLUMN grouper_composites_v.COMPOSITE_TYPE IS 'COMPOSITE_TYPE: union (all members), intersection (only members in both), or complement (in first, not in second)';

COMMENT ON COLUMN grouper_composites_v.LEFT_FACTOR_GROUP_NAME IS 'LEFT_FACTOR_GROUP_NAME: Name of group which is the first of two groups in the composite operation, e.g. school:stem1:part1';

COMMENT ON COLUMN grouper_composites_v.RIGHT_FACTOR_GROUP_NAME IS 'RIGHT_FACTOR_GROUP_NAME: Name of group which is the second of two groups in the composite operation, e.g. school:stem1:part2';

COMMENT ON COLUMN grouper_composites_v.OWNER_GROUP_DISPLAYNAME IS 'OWNER_GROUP_DISPLAYNAME: Display name of result group of composite operation, e.g. My school:The stem1:All people';

COMMENT ON COLUMN grouper_composites_v.LEFT_FACTOR_GROUP_DISPLAYNAME IS 'LEFT_FACTOR_GROUP_DISPLAYNAME: Display name of group which is the first of two groups in the composite operation, e.g. My school:The stem1:Part 1';

COMMENT ON COLUMN grouper_composites_v.RIGHT_FACTOR_GROUP_DISPLAYNAME IS 'RIGHT_FACTOR_GROUP_DISPLAYNAME: Display name of group which is the second of two groups in the composite operation, e.g. My school:The stem1:Part 1';

COMMENT ON COLUMN grouper_composites_v.OWNER_GROUP_ID IS 'OWNER_GROUP_ID: UUID of the result group';

COMMENT ON COLUMN grouper_composites_v.LEFT_FACTOR_GROUP_ID IS 'LEFT_FACTOR_GROUP_ID: UUID of the first group of the composite operation';

COMMENT ON COLUMN grouper_composites_v.RIGHT_FACTOR_GROUP_ID IS 'RIGHT_FACTOR_GROUP_ID: UUID of the second group of the composite operation';

COMMENT ON COLUMN grouper_composites_v.COMPOSITE_ID IS 'COMPOSITE_ID: UUID of the composite relationship among the three groups';

COMMENT ON COLUMN grouper_composites_v.CREATE_TIME IS 'CREATE_TIME: number of millis since 1970 that the composite was created';

COMMENT ON COLUMN grouper_composites_v.CREATOR_ID IS 'CREATOR_ID: member id of the subject that created the composite relationship';

COMMENT ON COLUMN grouper_composites_v.HIBERNATE_VERSION_NUMBER IS 'HIBERNATE_VERSION_NUMBER: increments with each update, starts at 0';

CREATE OR REPLACE VIEW grouper_groups_types_v (GROUP_NAME, GROUP_DISPLAYNAME, GROUP_TYPE_NAME, GROUP_ID, GROUP_TYPE_UUID, GROUPER_GROUPS_TYPES_ID, HIBERNATE_VERSION_NUMBER) AS select  (select ga.value from grouper_attributes ga, grouper_fields gf  where ga.group_id = ggt.GROUP_UUID and gf.name = 'name' and ga.field_id = gf.id) as group_name, (select ga.value from grouper_attributes ga, grouper_fields gf  where ga.group_id = ggt.GROUP_UUID and gf.name = 'displayName' and ga.field_id = gf.id) as group_displayname, gt.NAME as group_type_name, ggt.GROUP_UUID as group_id, ggt.TYPE_UUID as group_type_uuid, ggt.ID as grouper_groups_types_id, ggt.HIBERNATE_VERSION_NUMBER from grouper_groups_types ggt, grouper_types gt where ggt.TYPE_UUID = gt.ID ;

COMMENT ON VIEW grouper_groups_types_v IS 'A group can have one or many types associated.  This is a view of those relationships with friendly names';

COMMENT ON COLUMN grouper_groups_types_v.GROUP_NAME IS 'GROUP_NAME: name of group which has the type, e.g. school:stem1:theGroup';

COMMENT ON COLUMN grouper_groups_types_v.GROUP_DISPLAYNAME IS 'GROUP_DISPLAYNAME: display name of the group which has the type, e.g. My school, the stem 1, The group';

COMMENT ON COLUMN grouper_groups_types_v.GROUP_TYPE_NAME IS 'GROUP_TYPE_NAME: friendly name of the type, e.g. grouperLoader';

COMMENT ON COLUMN grouper_groups_types_v.GROUP_ID IS 'GROUP_ID: uuid unique id of the group which has the type';

COMMENT ON COLUMN grouper_groups_types_v.GROUP_TYPE_UUID IS 'GROUP_TYPE_UUID: uuid unique id of the type related to the group';

COMMENT ON COLUMN grouper_groups_types_v.GROUPER_GROUPS_TYPES_ID IS 'GROUPER_GROUPS_TYPES_ID: uuid unique id of the relationship between the group and type';

COMMENT ON COLUMN grouper_groups_types_v.HIBERNATE_VERSION_NUMBER IS 'HIBERNATE_VERSION_NUMBER: increments by one with each update, starts at 0';

CREATE OR REPLACE VIEW grouper_groups_v (EXTENSION, NAME, DISPLAY_EXTENSION, DISPLAY_NAME, DESCRIPTION, PARENT_STEM_NAME, GROUP_ID, PARENT_STEM_ID, MODIFIER_SOURCE, MODIFIER_SUBJECT_ID, CREATOR_SOURCE, CREATOR_SUBJECT_ID, IS_COMPOSITE_OWNER, IS_COMPOSITE_FACTOR, CREATOR_ID, CREATE_TIME, MODIFIER_ID, MODIFY_TIME, HIBERNATE_VERSION_NUMBER) AS select  (select ga.value from grouper_attributes ga, grouper_fields gf where ga.group_id = gg.id and gf.name = 'extension' and gf.id = ga.field_id) as extension, (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gg.id and gf.name = 'name' and gf.id = ga.field_id) as name, (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gg.id and gf.name = 'displayExtension' and gf.id = ga.field_id) as display_extension,     (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gg.id and gf.name = 'displayName' and gf.id = ga.field_id) as display_name, (select ga.value from grouper_attributes ga, grouper_fields gf where ga.group_id = gg.id and gf.name = 'description' and gf.id = ga.field_id) as description, gs.NAME as parent_stem_name, gg.id as group_id, gs.ID as parent_stem_id, (select gm.SUBJECT_SOURCE from grouper_members gm where gm.ID = gg.MODIFIER_ID) as modifier_source, (select gm.SUBJECT_ID from grouper_members gm where gm.ID = gg.MODIFIER_ID) as modifier_subject_id, (select gm.SUBJECT_SOURCE from grouper_members gm where gm.ID = gg.CREATOR_ID) as creator_source, (select gm.SUBJECT_ID from grouper_members gm where gm.ID = gg.CREATOR_ID) as creator_subject_id, (select distinct 'T' from grouper_composites gc where gc.OWNER = gg.ID) as is_composite_owner, (select distinct 'T' from grouper_composites gc where gc.LEFT_FACTOR = gg.ID or gc.right_factor = gg.id) as is_composite_factor, gg.CREATOR_ID, gg.CREATE_TIME, gg.MODIFIER_ID, gg.MODIFY_TIME, gg.HIBERNATE_VERSION_NUMBER   from grouper_groups gg, grouper_stems gs where gg.PARENT_STEM = gs.ID ;

COMMENT ON VIEW grouper_groups_v IS 'Contains one record for each group, with friendly names for some attributes and some more information';

COMMENT ON COLUMN grouper_groups_v.EXTENSION IS 'EXTENSION: part of group name not including path information, e.g. theGroup';

COMMENT ON COLUMN grouper_groups_v.NAME IS 'NAME: name of the group, e.g. school:stem1:theGroup';

COMMENT ON COLUMN grouper_groups_v.DISPLAY_EXTENSION IS 'DISPLAY_EXTENSION: name for display of the group, e.g. My school:The stem 1:The group';

COMMENT ON COLUMN grouper_groups_v.DISPLAY_NAME IS 'DISPLAY_NAME: name for display of the group without any path information, e.g. The group';

COMMENT ON COLUMN grouper_groups_v.DESCRIPTION IS 'DESCRIPTION: contains user entered information about the group e.g. why it exists';

COMMENT ON COLUMN grouper_groups_v.PARENT_STEM_NAME IS 'PARENT_STEM_NAME: name of the stem this group is in, e.g. school:stem1';

COMMENT ON COLUMN grouper_groups_v.GROUP_ID IS 'GROUP_ID: uuid unique id of the group';

COMMENT ON COLUMN grouper_groups_v.PARENT_STEM_ID IS 'PARENT_STEM_ID: uuid unique id of the stem this group is in';

COMMENT ON COLUMN grouper_groups_v.MODIFIER_SOURCE IS 'MODIFIER_SOURCE: source name of the subject who last modified this group, e.g. schoolPersonSource';

COMMENT ON COLUMN grouper_groups_v.MODIFIER_SUBJECT_ID IS 'MODIFIER_SUBJECT_ID: subject id of the subject who last modified this group, e.g. 12345';

COMMENT ON COLUMN grouper_groups_v.CREATOR_SOURCE IS 'CREATOR_SOURCE: source name of the subject who created this group, e.g. schoolPersonSource';

COMMENT ON COLUMN grouper_groups_v.CREATOR_SUBJECT_ID IS 'CREATOR_SUBJECT_ID: subject id of the subject who created this group, e.g. 12345';

COMMENT ON COLUMN grouper_groups_v.IS_COMPOSITE_OWNER IS 'IS_COMPOSITE_OWNER: T if this is a result of a composite operation (union, intersection, complement), or blank if not';

COMMENT ON COLUMN grouper_groups_v.IS_COMPOSITE_FACTOR IS 'IS_COMPOSITE_FACTOR: T if this is a member of a composite operation, e.g. one of the grouper being unioned, intersected, or complemeneted';

COMMENT ON COLUMN grouper_groups_v.CREATOR_ID IS 'CREATOR_ID: member id of the subject who created this group, foreign key to grouper_members';

COMMENT ON COLUMN grouper_groups_v.CREATE_TIME IS 'CREATE_TIME: number of millis since 1970 since this group was created';

COMMENT ON COLUMN grouper_groups_v.MODIFIER_ID IS 'MODIFIER_ID: member id of the subject who last modified this group, foreign key to grouper_members';

COMMENT ON COLUMN grouper_groups_v.MODIFY_TIME IS 'MODIFY_TIME: number of millis since 1970 since this group was last changed';

COMMENT ON COLUMN grouper_groups_v.HIBERNATE_VERSION_NUMBER IS 'HIBERNATE_VERSION_NUMBER: increments by 1 for each update';

CREATE OR REPLACE VIEW grouper_memberships_v (GROUP_NAME, GROUP_DISPLAYNAME, STEM_NAME, STEM_DISPLAYNAME, SUBJECT_ID, SUBJECT_SOURCE, LIST_TYPE, LIST_NAME, MEMBERSHIP_TYPE, COMPOSITE_PARENT_GROUP_NAME, DEPTH, CREATOR_SOURCE, CREATOR_SUBJECT_ID, MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID, STEM_ID, GROUP_ID, GROUP_OR_STEM_ID, CREATE_TIME, CREATOR_ID, FIELD_ID) AS select (select ga.value from grouper_attributes ga, grouper_fields gf  where ga.group_id = gms.owner_id and gf.name = 'name' and ga.field_id = gf.id) as group_name, (select ga.value from grouper_attributes ga, grouper_fields gf  where ga.group_id = gms.owner_id and gf.name = 'displayName' and ga.field_id = gf.id) as group_displayname, (select gs.NAME from grouper_stems gs where gs.ID = gms.owner_id) as stem_name, (select gs.display_NAME from grouper_stems gs where gs.ID = gms.owner_id) as stem_displayname, gm.SUBJECT_ID, gm.subject_source, gf.TYPE as list_type, gf.NAME as list_name, gms.MSHIP_TYPE as membership_type, (select ga.value from grouper_attributes ga, grouper_composites gc, grouper_fields gf where gc.id = gms.VIA_ID and ga.group_id = gc.OWNER and gf.name = 'name' and ga.field_id = gf.id) as composite_parent_group_name, depth,  (select gm.SUBJECT_SOURCE from grouper_members gm where gm.ID = gms.creator_ID) as creator_source, (select gm.SUBJECT_ID from grouper_members gm where gm.ID = gms.creator_ID) as creator_subject_id, gms.id as membership_id,  gms.PARENT_MEMBERSHIP as parent_membership_id, (select gs.id from grouper_stems gs where gs.ID = gms.owner_id) as stem_id, (select gg.id from grouper_groups gg where gg.id = gms.owner_id) as group_id, gms.OWNER_ID as group_or_stem_id, gms.CREATE_TIME, gms.CREATOR_ID, gms.FIELD_ID  from grouper_memberships gms, grouper_members gm, grouper_fields gf  where gms.MEMBER_ID = gm.ID and gms.field_id = gf.id ;

COMMENT ON VIEW grouper_memberships_v IS 'Grouper_memberships_v holds one record for each membership or privilege in the system for members to groups or stems (for privileges).  This is denormalized so there are records for the actual immediate relationships, and the cascaded effective relationships.  This has friendly names.';

COMMENT ON COLUMN grouper_memberships_v.GROUP_NAME IS 'GROUP_NAME: name of the group if this is a group membership, e.g. school:stem1:theGroup';

COMMENT ON COLUMN grouper_memberships_v.GROUP_DISPLAYNAME IS 'GROUP_DISPLAYNAME: display name of the group if this is a group membership, e.g. My school:The stem1:The group';

COMMENT ON COLUMN grouper_memberships_v.STEM_NAME IS 'STEM_NAME: name of the stem if this is a stem privilege, e.g. school:stem1';

COMMENT ON COLUMN grouper_memberships_v.STEM_DISPLAYNAME IS 'STEM_DISPLAYNAME: display name of the stems if this is a stem privilege, e.g. My school:The stem1';

COMMENT ON COLUMN grouper_memberships_v.SUBJECT_ID IS 'SUBJECT_ID: e.g. a school id of a person in the membership e.g. 12345';

COMMENT ON COLUMN grouper_memberships_v.SUBJECT_SOURCE IS 'SUBJECT_SOURCE: source where the subject in the membership is from e.g. mySchoolPeople';

COMMENT ON COLUMN grouper_memberships_v.LIST_TYPE IS 'LIST_TYPE: list: members of a group, access: privilege of a group, naming: privilege of a stem';

COMMENT ON COLUMN grouper_memberships_v.LIST_NAME IS 'LIST_NAME: subset of list type.  which list if a list membership.  which privilege if a privilege.  e.g. members';

COMMENT ON COLUMN grouper_memberships_v.MEMBERSHIP_TYPE IS 'MEMBERSHIP_TYPE: either immediate (direct membership or privilege), of effective (membership due to a composite or a group being a member of another group)';

COMMENT ON COLUMN grouper_memberships_v.COMPOSITE_PARENT_GROUP_NAME IS 'COMPOSITE_PARENT_GROUP_NAME: name of group if this membership relates to a composite relationship, e.g. school:stem:allStudents';

COMMENT ON COLUMN grouper_memberships_v.DEPTH IS 'DEPTH: 0 for composite, if not then it is the 0 indexed count of number of group hops between member and group';

COMMENT ON COLUMN grouper_memberships_v.CREATOR_SOURCE IS 'CREATOR_SOURCE: subject source where the creator of the group is from';

COMMENT ON COLUMN grouper_memberships_v.CREATOR_SUBJECT_ID IS 'CREATOR_SUBJECT_ID: subject id of the creator of the group, e.g. 12345';

COMMENT ON COLUMN grouper_memberships_v.MEMBERSHIP_ID IS 'MEMBERSHIP_ID: uuid unique id of this membership';

COMMENT ON COLUMN grouper_memberships_v.PARENT_MEMBERSHIP_ID IS 'PARENT_MEMBERSHIP_ID: if this is an effective membership, then this is the membership_uuid of the cause of this membership';

COMMENT ON COLUMN grouper_memberships_v.STEM_ID IS 'STEM_ID: if this is a stem privilege, this is the stem uuid unique id';

COMMENT ON COLUMN grouper_memberships_v.GROUP_ID IS 'GROUP_ID: if this is a group list or privilege, this is the group uuid unique id';

COMMENT ON COLUMN grouper_memberships_v.GROUP_OR_STEM_ID IS 'GROUP_OR_STEM_ID: stem_id if stem, group_id if group';

COMMENT ON COLUMN grouper_memberships_v.CREATE_TIME IS 'CREATE_TIME: number of millis since 1970 since this membership was created';

COMMENT ON COLUMN grouper_memberships_v.CREATOR_ID IS 'CREATOR_ID: member_id of the creator, foreign key into grouper_members';

COMMENT ON COLUMN grouper_memberships_v.FIELD_ID IS 'FIELD_ID: uuid unique id of the field.  foreign key to grouper_fields.  This represents the list_type and list_name';

CREATE OR REPLACE VIEW grouper_stems_v (EXTENSION, NAME, DISPLAY_EXTENSION, DISPLAY_NAME, DESCRIPTION, PARENT_STEM_NAME, PARENT_STEM_DISPLAYNAME, CREATOR_SOURCE, CREATOR_SUBJECT_ID, MODIFIER_SOURCE, MODIFIER_SUBJECT_ID, CREATE_TIME, CREATOR_ID, STEM_ID, MODIFIER_ID, MODIFY_TIME, PARENT_STEM, HIBERNATE_VERSION_NUMBER) AS select gs.extension, gs.NAME, gs.DISPLAY_EXTENSION, gs.DISPLAY_NAME, gs.DESCRIPTION, (select gs_parent.NAME from grouper_stems gs_parent where gs_parent.id = gs.PARENT_STEM) as parent_stem_name, (select gs_parent.DISPLAY_NAME from grouper_stems gs_parent where gs_parent.id = gs.PARENT_STEM) as parent_stem_displayname, (select gm.SUBJECT_SOURCE from grouper_members gm where gm.ID = gs.creator_ID) as creator_source, (select gm.SUBJECT_ID from grouper_members gm where gm.ID = gs.creator_ID) as creator_subject_id, (select gm.SUBJECT_SOURCE from grouper_members gm where gm.ID = gs.MODIFIER_ID) as modifier_source, (select gm.SUBJECT_ID from grouper_members gm where gm.ID = gs.MODIFIER_ID) as modifier_subject_id, gs.CREATE_TIME, gs.CREATOR_ID,  gs.ID as stem_id, gs.MODIFIER_ID, gs.MODIFY_TIME, gs.PARENT_STEM, gs.HIBERNATE_VERSION_NUMBER from grouper_stems gs ;

COMMENT ON VIEW grouper_stems_v IS 'GROUPER_STEMS_V: holds one record for each stem (folder) in grouper, with friendly names';

COMMENT ON COLUMN grouper_stems_v.EXTENSION IS 'EXTENSION: name of the stem without the parent stem names, e.g. stem1';

COMMENT ON COLUMN grouper_stems_v.NAME IS 'NAME: name of the stem including parent stem names, e.g. school:stem1';

COMMENT ON COLUMN grouper_stems_v.DISPLAY_EXTENSION IS 'DISPLAY_EXTENSION: display name of the stem without parent stem names, e.g. The stem 1';

COMMENT ON COLUMN grouper_stems_v.DISPLAY_NAME IS 'DISPLAY_NAME: display name of the stem including parent stem names, e.g. My school: The stem 1';

COMMENT ON COLUMN grouper_stems_v.DESCRIPTION IS 'DESCRIPTION: description entered in about the stem, for example including why the stem exists and who has access';

COMMENT ON COLUMN grouper_stems_v.PARENT_STEM_NAME IS 'PARENT_STEM_NAME: name of the stem (folder) that this stem is in.  e.g. school';

COMMENT ON COLUMN grouper_stems_v.PARENT_STEM_DISPLAYNAME IS 'PARENT_STEM_DISPLAYNAME: display name of the stem (folder) that this stem is in.  e.g. My school';

COMMENT ON COLUMN grouper_stems_v.CREATOR_SOURCE IS 'CREATOR_SOURCE: subject source where the subject that created this stem is from, e.g. mySchoolPeople';

COMMENT ON COLUMN grouper_stems_v.CREATOR_SUBJECT_ID IS 'CREATOR_SUBJECT_ID: e.g. the school id of the subject that created this stem, e.g. 12345';

COMMENT ON COLUMN grouper_stems_v.MODIFIER_SOURCE IS 'MODIFIER_SOURCE: subject source where the subject that last modified this stem is from, e.g. mySchoolPeople';

COMMENT ON COLUMN grouper_stems_v.MODIFIER_SUBJECT_ID IS 'MODIFIER_SUBJECT_ID: e.g. the school id of the subject who last modified this stem, e.g. 12345';

COMMENT ON COLUMN grouper_stems_v.CREATE_TIME IS 'CREATE_TIME: number of millis since 1970 that this stem was created';

COMMENT ON COLUMN grouper_stems_v.CREATOR_ID IS 'CREATOR_ID: member id of the subject who created this stem, foreign key to grouper_members';

COMMENT ON COLUMN grouper_stems_v.STEM_ID IS 'STEM_ID: uuid unique id of this stem';

COMMENT ON COLUMN grouper_stems_v.MODIFIER_ID IS 'MODIFIER_ID: member id of the subject who last modified this stem, foreign key to grouper_members';

COMMENT ON COLUMN grouper_stems_v.MODIFY_TIME IS 'MODIFY_TIME: number of millis since 1970 since this stem was last modified';

COMMENT ON COLUMN grouper_stems_v.PARENT_STEM IS 'PARENT_STEM: stem_id uuid unique id of the stem (folder) that this stem is in';

COMMENT ON COLUMN grouper_stems_v.HIBERNATE_VERSION_NUMBER IS 'HIBERNATE_VERSION_NUMBER: increments by one for each update from hibernate';

CREATE OR REPLACE VIEW grouper_rpt_attributes_v (ATTRIBUTE_NAME, GROUP_COUNT, GROUP_TYPE_NAME, FIELD_ID, GROUP_TYPE_ID) AS select gf.NAME as attribute_name,  (select count(*) from grouper_attributes ga where ga.FIELD_ID = gf.id) as group_count,   gt.NAME as group_type_name, gf.ID as field_id, gt.ID as group_type_id from grouper_fields gf, grouper_types gt where gf.TYPE = 'attribute' and gf.GROUPTYPE_UUID = gt.ID ;

COMMENT ON VIEW grouper_rpt_attributes_v IS 'GROUPER_RPT_ATTRIBUTES_V: report on attributes, how many groups use each attribute';

COMMENT ON COLUMN grouper_rpt_attributes_v.ATTRIBUTE_NAME IS 'ATTRIBUTE_NAME: friendly name of the attribute which is actually from grouper_fields';

COMMENT ON COLUMN grouper_rpt_attributes_v.GROUP_COUNT IS 'GROUP_COUNT: number of groups which define this attribute';

COMMENT ON COLUMN grouper_rpt_attributes_v.GROUP_TYPE_NAME IS 'GROUP_TYPE_NAME: group type which owns this attribute';

COMMENT ON COLUMN grouper_rpt_attributes_v.FIELD_ID IS 'FIELD_ID: uuid unique id of this field (attribute), foreign key from grouper_attributes to grouper_fields';

COMMENT ON COLUMN grouper_rpt_attributes_v.GROUP_TYPE_ID IS 'GROUP_TYPE_ID: uuid unique id of the group type.  foreign key from grouper_fields to grouper_types';

CREATE OR REPLACE VIEW grouper_rpt_composites_v (COMPOSITE_TYPE, THE_COUNT) AS select gc.TYPE as composite_type, count(*) as the_count from grouper_composites gc group by gc.type ;

COMMENT ON VIEW grouper_rpt_composites_v IS 'GROUPER_RPT_COMPOSITES_V: report on the three composite types: union, intersection, complement and how many of each exist';

COMMENT ON COLUMN grouper_rpt_composites_v.COMPOSITE_TYPE IS 'COMPOSITE_TYPE: either union: all members from both factors, intersection: only members in both factors, complement: members in first but not second factor';

COMMENT ON COLUMN grouper_rpt_composites_v.THE_COUNT IS 'THE_COUNT: nubmer of composites of this type in the system';

CREATE OR REPLACE VIEW grouper_rpt_group_field_v (GROUP_NAME, GROUP_DISPLAYNAME, FIELD_TYPE, FIELD_NAME, MEMBER_COUNT) AS select ga.value as group_name, ga2.value as group_displayName, gf.type as field_type, gf.name as field_name, count(distinct gms.member_id) as member_count from grouper_memberships gms, grouper_fields gf, grouper_attributes ga, grouper_fields gaf,  grouper_attributes ga2, grouper_fields gaf2 where gms.FIELD_ID = gf.ID and ga.FIELD_ID = gaf.id and gaf.name = 'name' and ga.group_id = gms.OWNER_ID and ga2.group_id = gms.owner_id and ga2.field_id = gaf2.id and gaf2.name = 'displayName' group by ga.value, ga2.value, gf.type, gf.name ;

COMMENT ON VIEW grouper_rpt_group_field_v IS 'GROUPER_RPT_GROUP_FIELD_V: report on how many unique members are in each group based on field (or list) name and type';

COMMENT ON COLUMN grouper_rpt_group_field_v.GROUP_NAME IS 'GROUP_NAME: name of the group where the list and members are, e.g. school:stem1:myGroup';

COMMENT ON COLUMN grouper_rpt_group_field_v.GROUP_DISPLAYNAME IS 'GROUP_DISPLAYNAME: display name of the group where the list and members are, e.g. My school:The stem1:My group';

COMMENT ON COLUMN grouper_rpt_group_field_v.FIELD_TYPE IS 'FIELD_TYPE: membership field type, e.g. list or access';

COMMENT ON COLUMN grouper_rpt_group_field_v.FIELD_NAME IS 'FIELD_NAME: membership field name, e.g. members, admins, readers';

COMMENT ON COLUMN grouper_rpt_group_field_v.MEMBER_COUNT IS 'MEMBER_COUNT: number of unique members in the group/field';

CREATE OR REPLACE VIEW grouper_rpt_groups_v (GROUP_NAME, GROUP_DISPLAYNAME, IMMEDIATE_MEMBERSHIP_COUNT, MEMBERSHIP_COUNT, ATTRIBUTE_COUNT, GROUPS_TYPES_COUNT, ISA_COMPOSITE_FACTOR_COUNT, ISA_MEMBER_COUNT, GROUP_ID) AS select  (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gg.id and gf.name = 'name' and gf.id = ga.field_id) as group_name,     (select ga.value from grouper_attributes ga , grouper_fields gf where ga.group_id = gg.id and gf.name = 'displayName' and gf.id = ga.field_id) as group_displayname, (select count(distinct gms.MEMBER_ID) from grouper_memberships gms where gms.OWNER_ID = gg.id and gms.MSHIP_TYPE = 'immediate') as immediate_membership_count, (select count(distinct gms.MEMBER_ID) from grouper_memberships gms where gms.OWNER_ID = gg.id) as membership_count, (select count(*) from grouper_attributes ga where ga.GROUP_ID = gg.id) as attribute_count, (select count(*) from grouper_groups_types ggt where ggt.GROUP_UUID = gg.id) as groups_types_count, (select count(*) from grouper_composites gc where gc.LEFT_FACTOR = gg.id or gc.RIGHT_FACTOR = gg.id) as isa_composite_factor_count, (select count(distinct gms.OWNER_ID) from grouper_memberships gms, grouper_members gm where gm.SUBJECT_ID = gg.ID and gms.MEMBER_ID = gm.ID ) as isa_member_count, gg.ID as group_id from grouper_groups gg ;

COMMENT ON VIEW grouper_rpt_groups_v IS 'GROUPER_RPT_GROUPS_V: report with a line for each group and some counts of immediate and effective members etc';

COMMENT ON COLUMN grouper_rpt_groups_v.GROUP_NAME IS 'GROUP_NAME: name of group which has the stats, e.g. school:stem1:theGroup';

COMMENT ON COLUMN grouper_rpt_groups_v.GROUP_DISPLAYNAME IS 'GROUP_DISPLAYNAME: display name of the group which has the stats, e.g. My school:The stem1:The group';

COMMENT ON COLUMN grouper_rpt_groups_v.IMMEDIATE_MEMBERSHIP_COUNT IS 'IMMEDIATE_MEMBERSHIP_COUNT: number of unique immediate members, directly assigned to this group';

COMMENT ON COLUMN grouper_rpt_groups_v.MEMBERSHIP_COUNT IS 'MEMBERSHIP_COUNT: total number of unique members, immediate or effective';

COMMENT ON COLUMN grouper_rpt_groups_v.ATTRIBUTE_COUNT IS 'ATTRIBUTE_COUNT: number of attributes defined for this group';

COMMENT ON COLUMN grouper_rpt_groups_v.GROUPS_TYPES_COUNT IS 'GROUPS_TYPES_COUNT: number of group types associated with this group';

COMMENT ON COLUMN grouper_rpt_groups_v.ISA_COMPOSITE_FACTOR_COUNT IS 'ISA_COMPOSITE_FACTOR_COUNT: number of composites this group is a factor of';

COMMENT ON COLUMN grouper_rpt_groups_v.ISA_MEMBER_COUNT IS 'ISA_MEMBER_COUNT: number of groups this group is an immediate or effective member of';

COMMENT ON COLUMN grouper_rpt_groups_v.GROUP_ID IS 'GROUP_ID: uuid unique id of this group';

CREATE OR REPLACE VIEW grouper_rpt_members_v (SUBJECT_ID, SUBJECT_SOURCE, MEMBERSHIP_COUNT, MEMBER_ID) AS select gm.SUBJECT_ID, gm.SUBJECT_SOURCE, (select count(distinct gms.owner_id) from grouper_memberships gms where gms.MEMBER_ID = gm.ID) as membership_count, gm.ID as member_id from grouper_members gm ;

COMMENT ON VIEW grouper_rpt_members_v IS 'GROUPER_RPT_MEMBERS_V: report for each member in grouper_members and some stats like how many groups they are in';

COMMENT ON COLUMN grouper_rpt_members_v.SUBJECT_ID IS 'SUBJECT_ID: e.g. the school person id of the person e.g. 12345';

COMMENT ON COLUMN grouper_rpt_members_v.SUBJECT_SOURCE IS 'SUBJECT_SOURCE: subject source where the subject is from, e.g. schoolAllPeople';

COMMENT ON COLUMN grouper_rpt_members_v.MEMBERSHIP_COUNT IS 'MEMBERSHIP_COUNT: number of distinct groups or stems this member has a membership with';

COMMENT ON COLUMN grouper_rpt_members_v.MEMBER_ID IS 'MEMBER_ID: uuid unique id of the member in grouper_members';

CREATE OR REPLACE VIEW grouper_rpt_stems_v (STEM_NAME, STEM_DISPLAYNAME, GROUP_IMMEDIATE_COUNT, STEM_IMMEDIATE_COUNT, GROUP_COUNT, STEM_COUNT, THIS_STEM_MEMBERSHIP_COUNT, CHILD_GROUP_MEMBERSHIP_COUNT, GROUP_MEMBERSHIP_COUNT, STEM_ID) AS select gs.NAME as stem_name, gs.DISPLAY_NAME as stem_displayname, (select count(*) from grouper_groups gg where gg.PARENT_STEM = gs.ID) as group_immediate_count, (select count(*) from grouper_stems gs2 where gs.id = gs2.PARENT_STEM ) as stem_immediate_count, (select count(*) from grouper_attributes ga, grouper_fields gf where ga.FIELD_ID = gf.ID and gf.NAME = 'name' and ga.value like gs.NAME || '%') as group_count, (select count(*) from grouper_stems gs2 where gs2.name like gs.NAME || '%') as stem_count, (select count(distinct gm.member_id) from grouper_memberships gm where gm.OWNER_ID = gs.id) as this_stem_membership_count,  (select count(distinct gm.member_id) from grouper_memberships gm, grouper_groups gg where gg.parent_stem = gs.id and gm.OWNER_ID = gg.id) as child_group_membership_count,  (select count(distinct gm.member_id) from grouper_memberships gm, grouper_attributes ga, grouper_fields gf where gm.owner_id = ga.group_id and ga.FIELD_ID = gf.ID and gf.NAME = 'name' and ga.value like gs.NAME || '%') as group_membership_count, gs.ID as stem_id from grouper_stems gs ;

COMMENT ON VIEW grouper_rpt_stems_v IS 'GROUPER_RPT_STEMS_V: report with a row for each stem and stats on many groups or members are inside';

COMMENT ON COLUMN grouper_rpt_stems_v.STEM_NAME IS 'STEM_NAME: name of the stem in report, e.g. school:stem1';

COMMENT ON COLUMN grouper_rpt_stems_v.STEM_DISPLAYNAME IS 'STEM_DISPLAYNAME: display name of the stem in report, e.g. My school:The stem 1';

COMMENT ON COLUMN grouper_rpt_stems_v.GROUP_IMMEDIATE_COUNT IS 'GROUP_IMMEDIATE_COUNT: number of groups directly inside this stem';

COMMENT ON COLUMN grouper_rpt_stems_v.STEM_IMMEDIATE_COUNT IS 'STEM_IMMEDIATE_COUNT: number of stems directly inside this stem';

COMMENT ON COLUMN grouper_rpt_stems_v.GROUP_COUNT IS 'GROUP_COUNT: number of groups inside this stem, or in a stem inside this stem etc';

COMMENT ON COLUMN grouper_rpt_stems_v.STEM_COUNT IS 'STEM_COUNT: number of stems inside this stem or in a stem inside this stem etc';

COMMENT ON COLUMN grouper_rpt_stems_v.THIS_STEM_MEMBERSHIP_COUNT IS 'THIS_STEM_MEMBERSHIP_COUNT: number of access memberships related to this stem (e.g. how many people can create groups/stems inside)';

COMMENT ON COLUMN grouper_rpt_stems_v.CHILD_GROUP_MEMBERSHIP_COUNT IS 'CHILD_GROUP_MEMBERSHIP_COUNT: number of memberships in groups immediately in this stem';

COMMENT ON COLUMN grouper_rpt_stems_v.GROUP_MEMBERSHIP_COUNT IS 'GROUP_MEMBERSHIP_COUNT: number of memberships in groups in this stem or in stems in this stem etc';

COMMENT ON COLUMN grouper_rpt_stems_v.STEM_ID IS 'STEM_ID: uuid unique id of this stem';

CREATE OR REPLACE VIEW grouper_rpt_types_v (GROUP_TYPE_NAME, GROUP_COUNT, GROUP_TYPE_ID) AS select gt.NAME as group_type_name, (select count(*) from grouper_groups_types ggt where ggt.TYPE_UUID = gt.ID) as group_count, gt.id as group_type_id from grouper_types gt ;

COMMENT ON VIEW grouper_rpt_types_v IS 'GROUPER_RPT_TYPES_V: report on group types and how many groups have that type';

COMMENT ON COLUMN grouper_rpt_types_v.GROUP_TYPE_NAME IS 'GROUP_TYPE_NAME: friendly name of this group type';

COMMENT ON COLUMN grouper_rpt_types_v.GROUP_COUNT IS 'GROUP_COUNT: number of groups that have this group type';

COMMENT ON COLUMN grouper_rpt_types_v.GROUP_TYPE_ID IS 'GROUP_TYPE_ID: uuid unique id of this group type';


update grouper_ddl set db_version = 1, last_updated = '2009/02/27 10:04:04', 
history = '2009/02/27 10:04:04: upgrade Subject from V0 to V1, 2009/02/24 01:02:06: upgrade Subject from V0 to V1, ' where object_name = 'Subject';
commit;

ALTER TABLE subjectattribute
    ADD CONSTRAINT fk_subjectattr_subjectid FOREIGN KEY (subjectid) REFERENCES subject (subjectid);

COMMENT ON TABLE subject IS 'sample subject table for grouper unit tests';

COMMENT ON COLUMN subject.subjectId IS 'subject id of row';

COMMENT ON COLUMN subject.subjectTypeId IS 'subject type e.g. person';

COMMENT ON COLUMN subject.name IS 'name of this subject';

COMMENT ON TABLE subjectattribute IS 'attribute data for each subject';

COMMENT ON COLUMN subjectattribute.subjectId IS 'subject id of row';

COMMENT ON COLUMN subjectattribute.name IS 'name of attribute';

COMMENT ON COLUMN subjectattribute.value IS 'value of attribute';

COMMENT ON COLUMN subjectattribute.searchValue IS 'search value (e.g. all lower)';

