home *** CD-ROM | disk | FTP | other *** search
/ MetaWorlds Beta 17 / MSQMW17.ZIP / DATA.Z / update.sql < prev    next >
Encoding:
Text File  |  1997-02-05  |  17.7 KB  |  443 lines

  1. SET OPTION ON_ERROR = CONTINUE;
  2. ALTER TABLE sv MODIFY version INTEGER;
  3. DROP PROCEDURE "dba".MWDB_Update;
  4.  
  5. SET OPTION ON_ERROR = NOTIFY_CONTINUE;
  6. create procedure "dba".MWDB_Update()
  7. begin
  8.   declare databaseBuild integer;
  9.  
  10.   // Read the current database build number.
  11.   message 'Read Database Build Number';
  12.   select distinct max(version) into databaseBuild from sv;
  13.  
  14.   // Now that we have a more robust checking scheme, rerun the update for
  15.   // build 2 in case it was not done properly.
  16.   if databaseBuild = 2 then
  17.     set databaseBuild = 1;
  18.   end if;
  19.  
  20.   // Proceed with Build Modification
  21.   // Beta 11 and prior
  22.  
  23.   if databaseBuild < 1 then
  24.     Message 'Update to build 1';
  25.     Message '1: Fix HTML type in MimeTypes';
  26.     update mimetypes set description='text/html' where description='text/htm;';
  27.  
  28.     if not exists(select column_name from sys.syscolumn key join sys.systable
  29.                   where sys.syscolumn.column_name = 'ReceiveDate' and
  30.                   sys.systable.table_name = 'messages') then
  31.  
  32.       Message '1: Add ReceiveDate column to messages table';
  33.       alter table messages add
  34.         ReceiveDate date null;
  35.     end if
  36.     ;
  37.  
  38.  
  39.     if not exists(select column_name from sys.syscolumn key join sys.systable
  40.                   where sys.syscolumn.column_name = 'ReceiveTime' and
  41.                   sys.systable.table_name = 'messages') then
  42.       Message '1: Add ReceiveTime column to messages table';
  43.       alter table messages add
  44.         ReceiveTime time null;
  45.     end if
  46.     ;
  47.  
  48.  
  49.     if not exists(select column_name from sys.syscolumn key join sys.systable
  50.                   where sys.syscolumn.column_name = 'LastDeliveryDateTime' and
  51.                   sys.systable.table_name = 'messages') then
  52.       Message '1: Add LastDeliveryDateTime column to messages table';
  53.       alter table messages add
  54.         LastDeliveryDateTime datetime;
  55.     end if
  56.     ;
  57.  
  58.     Message 'Update build number to 1';
  59.     update sv set version=1;
  60.   end if
  61.   ;
  62.  
  63. // Successive version go below as that is how updates will be applied in series.
  64.   // Beta 12
  65.   if databaseBuild < 2 then
  66.  
  67.     message 'Update to build 2';
  68.     message '2: Update new user area to use default template';
  69.     update subsysin set BannerGraphic = 'newuser.gif'
  70.        where instparam='newusr.sht';
  71.     update subsysin set InstParam = 'area.sht'
  72.        where instparam='newusr.sht';
  73.  
  74.     if not exists(select column_name from sys.syscolumn key join sys.systable
  75.                   where sys.syscolumn.column_name = 'id' and
  76.                   sys.systable.table_name = 'cgi_path') then
  77.       message '2: Add ID column to cgi_path table';
  78.       alter table cgi_path add ID integer default autoincrement;
  79.     end if
  80.     ;
  81.     message '2: Assign IDs to existing CGIs';
  82.     update cgi_path set id=1 where cgi='imagemap';
  83.     update cgi_path set id=2 where cgi='whocgi';
  84.     update cgi_path set id=3 where cgi='newuser';
  85.  
  86.     if exists(select table_name from sys.systable
  87.               where table_name = 'systeminformation') then
  88.       message '2: Delete all entries from systeminformation';
  89.       delete from systeminformation;
  90.     end if;
  91.  
  92.  
  93.     if not exists(select column_name from sys.syscolumn key join sys.systable
  94.                   where sys.syscolumn.column_name = 'server' and
  95.                   sys.systable.table_name = 'systeminformation') then
  96.       message '2: Add server column to the systeminformation table';
  97.       alter table systeminformation add server char(81) default '';
  98.       message '2: Make sure all server entries are empty strings.';
  99.     end if
  100.     ;
  101.  
  102.     message '2: Make sure all server entries are empty strings.';
  103.  
  104.  
  105.     message '2: Add server descriptions to systeminformation table';
  106.     update systeminformation set server='httpsapp' where unitid=1;
  107.     update systeminformation set server='httpsapp' where unitid=2;
  108.     update systeminformation set server='email' where unitid=3;
  109.     update systeminformation set server='email' where unitid=4;
  110.     update systeminformation set server='email' where unitid=5;
  111.     alter table systeminformation modify server not null;
  112.  
  113.     if not exists(select column_name from sys.syscolumn key join sys.systable
  114.                   where sys.syscolumn.column_name = 'virtid' and
  115.                   sys.systable.table_name = 'area_dirs') then
  116.       message '2: add virtid column to area_dirs table';
  117.       alter table area_dirs add virtid integer;
  118.     end if
  119.     ;
  120.  
  121.  
  122.     if not exists(select table_name from sys.systable
  123.                   where sys.systable.table_name = 'attachments') then
  124.       message '2: Create attachments table';
  125.       create table attachments(
  126.          attachid integer primary key default autoincrement not null,
  127.          fname long varchar not null default '',
  128.          stored long varchar not null default ''
  129.       );
  130.     end if
  131.     ;
  132.  
  133.     if not exists(select table_name from sys.systable
  134.                   where sys.systable.table_name = 'msgattach') then
  135.       message '2: Create msgattach table';
  136.       create table msgattach(
  137.          msgbase integer not null,
  138.          attachid integer not null,
  139.          msgid integer not null
  140.       )
  141.     end if
  142.     ;
  143.  
  144.     message 'Update build number to 2';
  145.     update sv set version=2;
  146.   end if;
  147.  
  148.   if databaseBuild < 3 then
  149.  
  150.     message 'Update to build 3';
  151.     if exists(select column_name from sys.syscolumn key join sys.systable
  152.               where sys.systable.table_name='cgi_path' and
  153.               sys.syscolumn.column_name = 'id') then
  154.  
  155.       // Check to see if the cgiid column already exists
  156.       if exists(select column_name from sys.syscolumn key join sys.systable
  157.                 where sys.systable.table_name='cgi_path' and
  158.                 sys.syscolumn.column_name='cgiid') then
  159.         alter table cgi_path delete id;
  160.       else
  161.         message '3: Rename id column to cgiid in cgi_path table';
  162.         alter table cgi_path rename id to cgiid;
  163.       end if;
  164.     end if;
  165.  
  166.     if exists(select table_name from sys.systable
  167.               where sys.systable.table_name='cgi_path') then
  168.  
  169.       if not exists(select server from systeminformation
  170.                 where server='email') then
  171.         message '3: Add email entries into systeminformation table';
  172.         Insert into SystemInformation (KeyWord,Value,server) values ('EmailRetry','60','email');
  173.         Insert into SystemInformation (KeyWord,Value,server) values ('EmailNotify','120','email');
  174.         Insert into SystemInformation (KeyWord,Value,server) values ('EmailBounce','1440','email');
  175.       end if;
  176.     end if;
  177.  
  178.     message 'Update build number to 3';
  179.     update sv set version = 3;
  180.   end if;
  181.  
  182.   if dataBaseBuild < 4 then
  183.  
  184.     message 'Begin build 4 update.';
  185.     if exists(select table_name
  186.               from sys.systable where table_name = 'area_dirs') then
  187.       message '4: Drop the area_dirs table.';
  188.       drop table area_dirs;
  189.     end if;
  190.  
  191.     if not exists(select column_name from sys.syscolumn key join sys.systable
  192.               where sys.systable.table_name='subsysin' and
  193.               sys.syscolumn.column_name='directory') then
  194.       message '4: Adding directory column to subsysin table.';
  195.       alter table subsysin add directory long varchar;
  196.       update subsysin set directory = '';
  197.       alter table subsysin modify directory not null default '';
  198.     end if;
  199.  
  200.     if not exists(select action from configuration
  201.                   where action = 'set_master_user') then
  202.  
  203.       message '4: Adding action ssifiles to the configuration table.';
  204.       insert into configuration(action, ssifile) values ('set_master_user','setmasur.sht');
  205.       insert into configuration(action, ssifile) values ('edit_profile_else','editpfel.sht');
  206.       insert into configuration(action, ssifile) values ('new_account_user','nauser.sht');
  207.       insert into configuration(action, ssifile) values ('new_account_user_update','naupdate.sht');
  208.       insert into configuration(action, ssifile) values ('delete_profile','delprofl.sht');
  209.       insert into configuration(action, ssifile) values ('new_profile','newprofl.sht');
  210.       insert into configuration(action, ssifile) values ('edit_profiles','editpros.sht');
  211.       insert into configuration(action, ssifile) values ('remove_profile_sub','remprsub.sht');
  212.       insert into configuration(action, ssifile) values ('add_prof_sub_list_err','adpfsble.sht');
  213.       insert into configuration(action, ssifile) values ('add_prof_sub_list','adpfsublt.sht');
  214.       insert into configuration(action, ssifile) values ('add_prof_sub','addpfsub.sht');
  215.       insert into configuration(action, ssifile) values ('edit_profile_error','edproerr.sht');
  216.       insert into configuration(action, ssifile) values ('virt_area_dirs','virtards.sht');
  217.       insert into configuration(action, ssifile) values ('new_virt_area_dir','nwvtardr.sht');
  218.       insert into configuration(action, ssifile) values ('edit_virt_area_dirs','edvtardr.sht');
  219.       insert into configuration(action, ssifile) values ('edit_virt_area_dirs_else','edvtarde.sht');
  220.  
  221.     end if;
  222.  
  223.     if exists(select column_name from sys.syscolumn key join sys.systable
  224.               where sys.systable.table_name='attachments' and
  225.               sys.syscolumn.column_name='attachid') then
  226.       message '4: Make the attachid (attachments) autoincrement.';
  227.       alter table attachments modify attachid default autoincrement;
  228.     end if;
  229.  
  230.  
  231.     if exists (select descript from subsysin
  232.                where id = 100 and descript like '%config%') then
  233.       message '4: Modify the config area from 100 to -1.';
  234.       update subsysin set id=-1 where id=100;
  235.       update subsysin set descript = 'Configuration Access' where id=-1;
  236.       update sub_prof set instanceid = -1 where instanceid=100;
  237.       update area_sub set instanceid = -1 where instanceid=100;
  238.     end if;
  239.  
  240.     if not exists(select descript from subsysin
  241.                   where descript = 'Modem Server Access') then
  242.       message '4: Add magic areas for PPP/Email/Read access.';
  243.       Insert Into SubSysIn (id,typeid,descript) VALUES (-2, 3, 'Modem Server Access');
  244.       Insert Into SubSysIn (id,typeid,descript) VALUES (-3, 3, 'E-Mail Server Access');
  245.       Insert Into SubSysIn (id,typeid,descript) VALUES (-4, 3, 'Read All Messages');
  246.       Insert Into Area_Sub (AreaId, InstanceId) values (-1, -2);
  247.       Insert Into Area_Sub (AreaId, InstanceId) values (-1, -3);
  248.       Insert Into Area_Sub (AreaId, InstanceId) values (-1, -4);
  249.     end if;
  250.  
  251.     if exists(select table_name from sys.systable
  252.               where table_name = 'cgi_path') then
  253.       if not exists(select cgi from cgi_path where cgi='filebase') then
  254.         message '4: Add CGI_PATH entries for filebase and msgbase.';
  255.         Insert into cgi_path (cgi, location) values ('filebase', '.\');
  256.         Insert into cgi_path (cgi, location) values ('msgbase', '.\');
  257.       end if;
  258.     end if;
  259.  
  260.     if not exists(select column_name from sys.syscolumn key join sys.systable
  261.                   where sys.systable.table_name='messages' and
  262.                   sys.syscolumn.column_name='LastWarning') then
  263.       message '4: Add LastWarning column to the messages table.';
  264.       alter table messages add LastWarning datetime;
  265.     end if;
  266.  
  267.  
  268.     message 'Update build number to 4';
  269.     update sv set version = 4;
  270.     message 'End of build 4 update.';
  271.   end if;
  272.  
  273.   if dataBaseBuild < 5 then
  274.     message '5: Begin build 5 update';
  275.     if not exists(select column_name from sys.syscolumn key join sys.systable
  276.                   where sys.systable.table_name='messages' and
  277.                   sys.syscolumn.column_name='MsgRaw') then
  278.       message '5: Add MsgRaw column to the message table.';
  279.       alter table messages add MsgRaw long binary;
  280.       message '5: Set the MsgRaw column to be empty strings.';
  281.       update messages set MsgRaw = '';
  282.       alter table messages modify MsgRaw NOT NULL DEFAULT '';
  283.     end if;
  284.  
  285.     if exists(select table_name from sys.systable
  286.               where sys.systable.table_name = 'users') then
  287.  
  288.       message '5: Deleting duplicate aliases';
  289.       update users set alias = LEFT(alias,30)+STRING(users.id)
  290.          where users.alias in
  291.          (select alias from users group by alias having count(*) > 1);
  292.  
  293.       message '5: Reloading user table with alias constraint.';
  294.       UNLOAD TABLE users to '.\\_mwdata_.dat';
  295.       drop table users;
  296.       CREATE TABLE Users(
  297.         ID          integer NOT NULL PRIMARY KEY DEFAULT AUTOINCREMENT,
  298.         Alias       char(41) NOT NULL DEFAULT '',
  299.         FName       char(21) NOT NULL DEFAULT '',
  300.         LName       char(21) NOT NULL DEFAULT '',
  301.         Street1     char(81) NOT NULL DEFAULT '',
  302.         Street2     char(81) NOT NULL DEFAULT '',
  303.         City        char(41) NOT NULL DEFAULT '',
  304.         State       char(21) NOT NULL DEFAULT '',
  305.         Zip         char(11) NOT NULL DEFAULT '',
  306.         Country     char(41) NOT NULL DEFAULT '',
  307.         Passwd      char(21) NOT NULL DEFAULT '',
  308.         Account     integer NOT NULL DEFAULT 0,
  309.         vphone      char(21) NOT NULL DEFAULT '',
  310.         dphone      char(21) NOT NULL DEFAULT '',
  311.         email       char(81) NOT NULL DEFAULT '',
  312.         company     char(81) NOT NULL DEFAULT '',
  313.         pcbuser     char(26) NOT NULL DEFAULT '',
  314.         personaldir char(81) not null default '',
  315.         UNIQUE (Alias)
  316.       );
  317.       load table users from '.\\_mwdata_.dat';
  318.       CREATE INDEX UsersIDX on Users (Alias, FName, LName);
  319.     end if;
  320.  
  321.     if not exists (select trigname from sys.systriggers
  322.                    where trigname = 'AttachProfs') then
  323.       message '5: Create AttachProfs trigger';
  324.       create trigger AttachProfs before delete order 1 on "DBA".Users
  325.       referencing old as UserRec
  326.       for each row
  327.       begin
  328.         delete from user_profile where UserRec.ID = user_profile.userid
  329.       end;
  330.     end if;
  331.  
  332.     if not exists (select trigname from sys.systriggers
  333.                    where trigname = 'AttachUsers') then
  334.       message '5: Create AttachUsers trigger';
  335.       create trigger AttachUsers before delete order 1 on "DBA".Accounts
  336.       referencing old as AcctRec
  337.       for each row
  338.       begin
  339.         delete from users where Users.Account = AcctRec.ID
  340.       end;
  341.     end if;
  342.  
  343.     if not exists(select index_name from sys.sysindex
  344.                   where index_name='MSG_MessageID') then
  345.       message '5:Added MSG_MessageID index.';
  346.       CREATE INDEX MSG_MessageID on "DBA".Messages (MsgID);
  347.     end if;
  348.  
  349.     if not exists(select index_name from sys.sysindex
  350.                   where index_name='MSG_MsgB_MsgBID') then  
  351.       message '5:Added MSG_MsgB_MsgBID index.';
  352.       CREATE INDEX MSG_MsgB_MsgBID on "DBA".MsgB_Msg (MbID);
  353.     end if;
  354.  
  355.     if not exists(select index_name from sys.sysindex
  356.                   where index_name='MSG_MsgB_MsgID') then
  357.       message '5:Added MSG_MsgB_MsgID index.';
  358.       CREATE INDEX MSG_MsgB_MsgID on "DBA".MsgB_Msg (MID);
  359.     end if;
  360.  
  361.     if not exists(select index_name from sys.sysindex
  362.                   where index_name='MSG_MessageTO') then
  363.       message '5:Added MSG_MessageTO index.';
  364.       CREATE INDEX MSG_MessageTO on "DBA".Msg_User (UsrId);
  365.     end if;
  366.  
  367.  
  368.     message 'Update buld number to 5';
  369.     update sv set version = 5;
  370.     message 'End of build 5 update.';
  371.   end if;
  372.  
  373.   if dataBaseBuild < 6 then
  374.     message 'Begin build 6 update';
  375.  
  376.     // Remove any trailing .DLL extensions in the QueryScript column of the
  377.     // SubSysTp table.
  378.     message '6: Remove .dll from the subsystp table.';
  379.     update subsystp set queryscript = LEFT(queryscript,LENGTH(queryscript)-4) where RIGHT(queryScript,4) = '.dll';
  380.     update subsystp set typeparam = LEFT(typeparam,PATINDEX('%.dll%',typeparam)-1)+RIGHT(typeparam,LENGTH(typeparam)-(PATINDEX('%.dll%',typeparam)+3)) where typeparam like '%.dll%';
  381.  
  382.     if not exists (select table_name from sys.systable
  383.                    where table_name = 'whosonline') then
  384.  
  385.       message '6: Add the WhosOnline table';
  386.  
  387.         CREATE TABLE WhosOnline (
  388.           ID          integer PRIMARY KEY DEFAULT AUTOINCREMENT NOT NULL,
  389.           UserName    char(81) NOT NULL DEFAULT '',
  390.           ServerName  char(41) NOT NULL DEFAULT '',
  391.           MachineName char(41) NOT NULL DEFAULT '',
  392.           LoggedOn    timestamp NOT NULL DEFAULT '80-01-01 00:00'
  393.         );
  394.     end if;
  395.  
  396.     if not exists(select index_name from sys.sysindex
  397.                   where index_name='MSG_MsgB_MsgBID') then  
  398.       message '5:Added MSG_MsgB_MsgBID index.';
  399.       CREATE INDEX MSG_MsgB_MsgBID on "DBA".MsgB_Msg (MbID);
  400.     end if;
  401.  
  402.     if not exists(select index_name from sys.sysindex
  403.                   where index_name='MSG_MsgB_MsgID') then
  404.       message '5:Added MSG_MsgB_MsgID index.';
  405.       CREATE INDEX MSG_MsgB_MsgID on "DBA".MsgB_Msg (MID);
  406.     end if;
  407.  
  408.     if not exists(select index_name from sys.sysindex
  409.                   where index_name='MSG_MessageTO') then
  410.       message '5:Added MSG_MessageTO index.';
  411.       CREATE INDEX MSG_MessageTO on "DBA".Msg_User (UsrId);
  412.     end if;
  413.  
  414.     message '6: Make message post and read dates real dates.';
  415.     alter table messages modify PostDate date;
  416.     alter table messages modify ReadDate date;
  417.  
  418.     message '6: Erase entries from the server table.';
  419.     delete from servers;
  420.  
  421.     if exists(select table_name from sys.systable
  422.               where table_name = 'cgi_path') then
  423.       if not exists(select cgi from cgi_path where cgi='area') then
  424.         message '6: Add CGI_PATH entry  for area.dll.';
  425.         Insert into cgi_path (cgi, location) values ('area', '.\');
  426.       end if;
  427.     end if;
  428.  
  429.     message '6: Update build number to 6';
  430.     update sv set version = 6;
  431.  
  432.     message 'End build 6 update';
  433.     end if;
  434.  
  435.   MESSAGE 'End of Update';
  436. end;
  437.  
  438. call mwdb_update();
  439. // Necessary to make the procedure execute.
  440. resume all;
  441.  
  442. commit work;
  443.