head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2001.08.14.18.10.11;	author kmaples;	state Exp;
branches;
next	1.1;

1.1
date	2001.07.10.22.52.15;	author kmaples;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Delete the groups which represent Helm-managed permissions on upgrade.
@
text
@# $Id: IzProfilesGroups.sql,v 1.1 2001/07/10 22:52:15 kmaples Exp $

# Delete the groups which represent Helm-managed permissions:

DELETE FROM groups WHERE name IN (
    'tweakparams', 'editusers', 'creategroups', 'editsubcomponents',
    'editkeywords', 'editissues', 'canconfirm');

# Create new lookup table joining profiles and groups:

CREATE TABLE profiles_x_groups (
    userid   mediumint(9)               NOT NULL,
    groupid  mediumint(9)               NOT NULL,
    canbless tinyint(4)     DEFAULT '0' NOT NULL,
    
    PRIMARY KEY (userid, groupid)
);

# Create new lookup table joining issues and groups:

CREATE TABLE issues_x_groups (
    issue_id   mediumint(9)               NOT NULL,
    groupid    mediumint(9)               NOT NULL,
    
    PRIMARY KEY (issue_id, groupid)
);

# Temporary table for new groups data:

CREATE TABLE new_groups (
  groupid      mediumint(9) DEFAULT '0' NOT NULL auto_increment,
  name         varchar(255) DEFAULT ''  NOT NULL,
  description  text                     NOT NULL,
  isissuegroup tinyint(4)   DEFAULT '0' NOT NULL,
  userregexp   tinytext                 NOT NULL,
  
  PRIMARY KEY (groupid),
  UNIQUE (name)
);

# Extract data from groups table:

INSERT INTO new_groups 
SELECT NULL, name, description, isissuegroup, userregexp 
FROM groups;

# Populate the lookup tables from old groups table:

INSERT INTO profiles_x_groups 
SELECT profiles.userid, new_groups.groupid, 
    profiles.groupset & profiles.blessgroupset & groups.bit != 0    
FROM   profiles, new_groups, groups
WHERE  profiles.groupset & groups.bit != 0 
AND    groups.name = new_groups.name;

INSERT INTO issues_x_groups
SELECT issues.issue_id, new_groups.groupid
FROM   issues, new_groups, groups
WHERE  issues.groupset & groups.bit != 0
AND    groups.name = new_groups.name;

# Switch new table for old table:

DROP TABLE groups;
ALTER TABLE new_groups RENAME AS groups;

# Cleanup unneeded fields:

ALTER TABLE profiles DROP COLUMN groupset;
ALTER TABLE profiles DROP COLUMN blessgroupset;
ALTER TABLE issues   DROP COLUMN groupset; 



@


1.1
log
@IZ work previously projected for 1.1.x release is now targeted for 1.2.x
release.  Moving the upgrade scripts accordingly.
@
text
@d1 7
a7 1
# $Id: IzProfilesGroups.sql,v 1.4 2001/06/28 22:38:31 kmaples Exp $
@

