adding keys for new tables, added migration support too

This commit is contained in:
toyomoyo 2006-08-10 08:20:16 +00:00
parent da4124beab
commit bcf214dfc4
5 changed files with 149 additions and 11 deletions

View File

@ -8,6 +8,54 @@
<FIELD name="tracer" method="NO_CONV" type="text" length="0" />
</FIELDS>
</TABLE>
<TABLE name="role">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_role_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="description" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_role_description(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="context" />
<TABLE name="role_deny_grant" />
<TABLE name="role_assignments">
<FIELDS>
<FIELD name="enrol" method="NO_CONV" type="varchar" length="20" />
</FIELDS>
</TABLE>
<TABLE name="role_capabilities">
<FIELDS>
<FIELD name="capability" method="NO_CONV" type="varchar" length="255" dropindex="roleid-contextid-capability" adduniqueindex ="roleid-contextid-capability(roleid, contextid, capability(255))" />
</FIELDS>
</TABLE>
<TABLE name="capabilities">
<FIELDS>
<FIELD name="name" method="NO_CONV" type="varchar" length="150" dropindex="name" addindex ="name(name(150))" />
<FIELD name="captype" method="NO_CONV" type="varchar" length="50" />
<FIELD name="component" method="NO_CONV" type="varchar" length="100" />
</FIELDS>
</TABLE>
<TABLE name="role_names">
<FIELDS>
<FIELD name="text" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_role_names_text(RECORDID)
</PHP_FUNCTION>
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="blog_tag_instance" />
<TABLE name="post">
<FIELDS>

View File

@ -2002,7 +2002,7 @@ function main_upgrade($oldversion=0) {
}
if ($oldversion < 2006080400) {
execute_sql("CREATE TABLE {$CFG->prefix}role (
execute_sql("CREATE TABLE {$CFG->prefix}role (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
`description` text NOT NULL default '',
@ -2010,7 +2010,7 @@ function main_upgrade($oldversion=0) {
PRIMARY KEY (`id`)
)", true);
execute_sql("CREATE TABLE {$CFG->prefix}context (
execute_sql("CREATE TABLE {$CFG->prefix}context (
`id` int(10) unsigned NOT NULL auto_increment,
`level` int(10) unsigned NOT NULL default '0',
`instanceid` int(10) unsigned NOT NULL default '0',
@ -2064,12 +2064,42 @@ function main_upgrade($oldversion=0) {
`roleid` int(10) unsigned NOT NULL default '0',
`contextid` int(10) unsigned NOT NULL default '0',
`text` text NOT NULL default '',
KEY `roleid` (`roleid`),
KEY `contextid` (`roleid`),
UNIQUE KEY `roleid-contextid` (`roleid`, `contextid`),
PRIMARY KEY (`id`)
)", true);
}
if ($oldversion < 2006081000) {
execute_sql("ALTER TABLE `{$CFG->prefix}role` ADD INDEX `sortorder` (`sortorder`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD INDEX `instanceid` (`instanceid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `level-instanceid` (`level`, `instanceid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `roleid` (`roleid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `contextid` (`contextid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `userid` (`userid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD UNIQUE INDEX `contextid-roleid-userid` (`contextid`, `roleid`, `userid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `sortorder` (`sortorder`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD INDEX `roleid` (`roleid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD INDEX `contextid` (`contextid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD INDEX `modifierid` (`modifierid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD UNIQUE INDEX `roleid-contextid-capability` (`roleid`, `contextid`, `capability`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_deny_grant` ADD INDEX `roleid` (`roleid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_deny_grant` ADD INDEX `unviewableroleid` (`unviewableroleid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_deny_grant` ADD UNIQUE INDEX `roleid-unviewableroleid` (`roleid`, `unviewableroleid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}capabilities` ADD INDEX `name` (`name`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_names` ADD INDEX `roleid` (`roleid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_names` ADD INDEX `contextid` (`contextid`)",true);
execute_sql("ALTER TABLE `{$CFG->prefix}role_names` ADD UNIQUE INDEX `roleid-contextid` (`roleid`, `contextid`)",true);
}
return $result;
}

View File

@ -908,6 +908,7 @@ CREATE TABLE prefix_role (
`name` varchar(255) NOT NULL default '',
`description` text NOT NULL default '',
`sortorder` int(10) unsigned NOT NULL default '0',
KEY `sortorder` (`sortorder`),
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT ='moodle roles';
@ -915,6 +916,8 @@ CREATE TABLE prefix_context (
`id` int(10) unsigned NOT NULL auto_increment,
`level` int(10) unsigned NOT NULL default '0',
`instanceid` int(10) unsigned NOT NULL default '0',
KEY `instanceid` (`instanceid`),
UNIQUE KEY `level-instanceid` (`level`, `instanceid`),
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT ='one of these must be set';
@ -930,6 +933,11 @@ CREATE TABLE prefix_role_assignments (
`modifierid` int(10) unsigned NOT NULL default '0',
`enrol` varchar(20) NOT NULL default '',
`sortorder` int(10) unsigned NOT NULL default '0',
KEY `roleid` (`roleid`),
KEY `contextid` (`contextid`),
KEY `userid` (`userid`),
UNIQUE KEY `contextid-roleid-userid` (`contextid`, `roleid`, `userid`),
KEY `sortorder` (`sortorder`),
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT ='assigning roles to different context';
@ -941,6 +949,10 @@ CREATE TABLE prefix_role_capabilities (
`permission` int(10) unsigned NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
`modifierid` int(10) unsigned NOT NULL default '0',
KEY `roleid` (`roleid`),
KEY `contextid` (`contextid`),
KEY `modifierid` (`modifierid`),
UNIQUE KEY `roleid-contextid-capability` (`roleid`, `contextid`, `capability`),
PRIMARY KEY (`id`)
) TYPE=MYISAM COMMENT ='overriding a capability for a particular role in a particular context';
@ -948,6 +960,9 @@ CREATE TABLE prefix_role_deny_grant (
`id` int(10) unsigned NOT NULL auto_increment,
`roleid` int(10) unsigned NOT NULL default '0',
`unviewableroleid` int(10) unsigned NOT NULL default '0',
KEY `roleid` (`roleid`),
KEY `unviewableroleid` (`unviewableroleid`),
UNIQUE KEY `roleid-unviewableroleid` (`roleid`, `unviewableroleid`),
PRIMARY KEY (`id`)
) TYPE=MYISAM COMMENT ='this defines what role can touch (assign, override) what role';
@ -957,6 +972,7 @@ CREATE TABLE prefix_capabilities (
`captype` varchar(50) NOT NULL default '',
`contextlevel` int(10) unsigned NOT NULL default '0',
`component` varchar(100) NOT NULL default '',
KEY `name` (`name`),
PRIMARY KEY (`id`)
) TYPE=MYISAM COMMENT ='this defines all capabilities';
@ -965,6 +981,9 @@ CREATE TABLE prefix_role_names (
`roleid` int(10) unsigned NOT NULL default '0',
`contextid` int(10) unsigned NOT NULL default '0',
`text` text NOT NULL default '',
KEY `roleid` (`roleid`),
KEY `contextid` (`contextid`),
UNIQUE KEY `roleid-contextid` (`roleid`, `contextid`),
PRIMARY KEY (`id`)
) TYPE=MYISAM COMMENT ='role names in native strings';

View File

@ -1679,6 +1679,28 @@ function main_upgrade($oldversion=0) {
);");
}
if ($oldversion < 2006081000) {
modify_database('',"CREATE INDEX prefix_role_sortorder_idx ON prefix_role (sortorder);");
modify_database('',"CREATE INDEX prefix_context_instanceid_idx ON prefix_context (instanceid);");
modify_database('',"CREATE UNIQUE INDEX prefix_context_levelinstanceid_idx ON prefix_context (level, instanceid);");
modify_database('',"CREATE INDEX prefix_role_assignments_roleid_idx ON prefix_role_assignments (roleid);");
modify_database('',"CREATE INDEX prefix_role_assignments_contextidid_idx ON prefix_role_assignments (contextid);");
modify_database('',"CREATE INDEX prefix_role_assignments_userid_idx ON prefix_role_assignments (userid);");
modify_database('',"CREATE UNIQUE INDEX prefix_role_assignments_contextidroleiduserid_idx ON prefix_role_assignments (contextid, roleid, userid);");
modify_database('',"CREATE INDEX prefix_role_assignments_sortorder_idx ON prefix_role_assignments (sortorder);");
modify_database('',"CREATE INDEX prefix_role_capabilities_roleid_idx ON prefix_role_capabilities (roleid);");
modify_database('',"CREATE INDEX prefix_role_capabilities_contextid_idx ON prefix_role_capabilities (contextid);");
modify_database('',"CREATE INDEX prefix_role_capabilities_modifierid_idx ON prefix_role_capabilities (modifierid);");
modify_database('',"CREATE UNIQUE INDEX prefix_role_capabilities_roleidcontextidcapability_idx ON prefix_role_capabilities (roleid, contextid, capability);");
modify_database('',"CREATE INDEX prefix_role_deny_grant_roleid_idx ON prefix_role_deny_grant (roleid);");
modify_database('',"CREATE INDEX prefix_role_deny_grant_unviewableroleid_idx ON prefix_role_deny_grant (unviewableroleid);");
modify_database('',"CREATE UNIQUE INDEX prefix_role_deny_grant_roleidunviewableroleid_idx ON prefix_role_deny_grant (roleid, unviewableroleid);");
modify_database('',"CREATE INDEX prefix_capabilities_name_idx ON prefix_capabilities (name);");
modify_database('',"CREATE INDEX prefix_role_names_roleid_idx ON prefix_role_names (roleid);");
modify_database('',"CREATE INDEX prefix_role_names_contextid_idx ON prefix_role_names (contextid);");
modify_database('',"CREATE UNIQUE INDEX prefix_role_names_roleidcontextid_idx ON prefix_role_names (roleid, contextid);");
}
return $result;
}

View File

@ -677,12 +677,15 @@ CREATE TABLE prefix_role (
description text NOT NULL default '',
sortorder integer NOT NULL default '0'
);
CREATE INDEX prefix_role_sortorder_idx ON prefix_role (sortorder);
CREATE TABLE prefix_context (
id SERIAL PRIMARY KEY,
level integer NOT NULL default 0,
instanceid integer NOT NULL default 0
);
);
CREATE INDEX prefix_context_instanceid_idx ON prefix_context (instanceid);
CREATE UNIQUE INDEX prefix_context_levelinstanceid_idx ON prefix_context (level, instanceid);
CREATE TABLE prefix_role_assignments (
id SERIAL PRIMARY KEY,
@ -696,8 +699,13 @@ CREATE TABLE prefix_role_assignments (
modifierid integer NOT NULL default 0,
enrol varchar(20) NOT NULL default '',
sortorder integer NOT NULL default '0'
);
);
CREATE INDEX prefix_role_assignments_roleid_idx ON prefix_role_assignments (roleid);
CREATE INDEX prefix_role_assignments_contextidid_idx ON prefix_role_assignments (contextid);
CREATE INDEX prefix_role_assignments_userid_idx ON prefix_role_assignments (userid);
CREATE UNIQUE INDEX prefix_role_assignments_contextidroleiduserid_idx ON prefix_role_assignments (contextid, roleid, userid);
CREATE INDEX prefix_role_assignments_sortorder_idx ON prefix_role_assignments (sortorder);
CREATE TABLE prefix_role_capabilities (
id SERIAL PRIMARY KEY,
contextid integer NOT NULL default 0,
@ -707,28 +715,39 @@ CREATE TABLE prefix_role_capabilities (
timemodified integer NOT NULL default 0,
modifierid integer NOT NULL default 0
);
CREATE INDEX prefix_role_capabilities_roleid_idx ON prefix_role_capabilities (roleid);
CREATE INDEX prefix_role_capabilities_contextid_idx ON prefix_role_capabilities (contextid);
CREATE INDEX prefix_role_capabilities_modifierid_idx ON prefix_role_capabilities (modifierid);
CREATE UNIQUE INDEX prefix_role_capabilities_roleidcontextidcapability_idx ON prefix_role_capabilities (roleid, contextid, capability);
CREATE TABLE prefix_role_deny_grant (
id SERIAL PRIMARY KEY,
roleid integer NOT NULL default '0',
unviewableroleid integer NOT NULL default '0'
);
CREATE INDEX prefix_role_deny_grant_roleid_idx ON prefix_role_deny_grant (roleid);
CREATE INDEX prefix_role_deny_grant_unviewableroleid_idx ON prefix_role_deny_grant (unviewableroleid);
CREATE UNIQUE INDEX prefix_role_deny_grant_roleidunviewableroleid_idx ON prefix_role_deny_grant (roleid, unviewableroleid);
CREATE TABLE prefix_capabilities (
id SERIAL PRIMARY KEY,
name varchar(150) NOT NULL default '',
captype varchar(50) NOT NULL default '',
contextlevel integer NOT NULL default 0,
component varchar(100) NOT NULL default ''
);
);
CREATE INDEX prefix_capabilities_name_idx ON prefix_capabilities (name);
CREATE TABLE prefix_role_names (
id SERIAL PRIMARY KEY,
roleid integer NOT NULL default 0,
contextid integer NOT NULL default 0,
text text NOT NULL default ''
);
CREATE INDEX prefix_role_names_roleid_idx ON prefix_role_names (roleid);
CREATE INDEX prefix_role_names_contextid_idx ON prefix_role_names (contextid);
CREATE UNIQUE INDEX prefix_role_names_roleidcontextid_idx ON prefix_role_names (roleid, contextid);
INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('user', 'view', 'user', 'firstname||\' \'||lastname');
INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('course', 'user report', 'user', 'firstname||\' \'||lastname');
INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('course', 'view', 'course', 'fullname');