[rt-devel] schema patch

ivan ivan-rt-devel at 420.am
Wed Sep 27 15:21:46 EDT 2000


As promised (if a bit late... uhh), here's a patch to unify schema
creation from a single Perl data structure.  There's four attachments
here:
- first, a patch to Makefile and bin/testdeps.pl
- second, the new file bin/initdb, and
- third, the new file etc/schema.pm, and
- lastly, the new file etc/insert.mysql

You'll also need the DBIx::DataSource and DBIx::DBSchema modules.  If they
have not yet propogated to your favourite CPAN mirror, you can get them
at: <http://420.am/dbix-datasource> and <http://420.am/dbix-dbschema>
respectively.

The initdb.{mysql,Pg,Oracle} files have become just `initdb', with the
database type passed as a parameter.  The database password is no longer
passed on the the command line and is instead queried from the user. 

The schema.{mysql,Pg,Oracle> files have become `schema.pm'.  The data
inserts there were misplaced in there haven't found a new home yet.
`insert.mysql' has the MySQL inserts for now.

MySQL appears to be working.  Pg is no worse than before.  :)  Oracle
might take some work.

-- 
meow
_ivan
-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /proj/maps/src/rt/Makefile,v
retrieving revision 1.1.2.4
retrieving revision 1.9
diff -u -r1.1.2.4 -r1.9
@@ -180,7 +180,7 @@
 
 
 database:
-       bin/initdb.$(DB_TYPE) '$(DB_HOME)' '$(DB_HOST)' '$(DB_DBA)' '$(DB_DBA_PA
SSWORD)' '$(DB_DATABASE)' '$(DB_RT_USER)' '$(DB_RT_PASS)'
+       bin/initdb '$(DB_TYPE)' '$(DB_HOME)' '$(DB_HOST)' '$(DB_DBA)' '$(DB_DATA
BASE)' '$(DB_RT_USER)'
 
 acls:
        $(PERL) -p -i.orig -e " s'!!DB_TYPE!!'$(DB_TYPE)'g;\
Index: bin/testdeps.pl
===================================================================
RCS file: /proj/maps/src/rt/bin/testdeps.pl,v
retrieving revision 1.1.2.3
retrieving revision 1.4
diff -u -r1.1.2.3 -r1.4
--- bin/testdeps.pl     2000/09/19 01:59:05     1.1.2.3
+++ bin/testdeps.pl     2000/09/27 19:11:57     1.4
@@ -29,6 +29,8 @@
 #                     'Text::Template'      => 0,
 #                     'DBIx::SearchBuilder' => 0,
 #                     'Apache::Session'     => 1.03,
+#                     'DBIx::DataSource'    => 0,
+#                     'DBIx::DBSchema'      => 0,
 #                   },
 
 use strict;
@@ -51,6 +53,8 @@
 Text::Template
 DBIx::SearchBuilder 0.05
 Apache::Session 1.03
+DBIx::DataSource
+DBIx::DBSchema
 );
 use CPAN;

-------------- next part --------------
#!/usr/bin/perl -w

use strict;
use vars qw($PROMPT $SCHEMA_FILE);
use subs qw(_yesno);
use DBI;
use DBIx::DataSource qw( create_database drop_database );
use DBIx::DBSchema;

$PROMPT = 1; #by default, should at least *ask* before nuking databases
$SCHEMA_FILE = "etc/schema.pm"; #hmm

$|=1;

my $schema_href = do "etc/schema.pm" or die $@ || $!;
my $schema = DBIx::DBSchema->pretty_read($schema_href);

my($DB_TYPE, $DB_HOME, $DB_HOST, $DB_DBA, $DB_DATABASE) = @ARGV;
print "Enter the $DB_TYPE password for $DB_DBA: ";
system "stty -echo";
my $DB_DBA_PASSWORD = scalar(<STDIN>); #keep off commandline
system "stty echo";
chomp $DB_DBA_PASSWORD;

print <<END;


Database creation parameters:

DB_TYPE         = $DB_TYPE
DB_HOME         = $DB_HOME
DB_HOST         = $DB_HOST
DB_DBA          = $DB_DBA
DB_DBA_PASSWORD = <hidden>
DB_DATABASE     = $DB_DATABASE
END

if ( $PROMPT ) {
  print <<END;

About to drop $DB_TYPE database $DB_DATABASE.
WARNING: This will erase all data in $DB_DATABASE.
If you have an existing RT 2.x installation, this will destory all your data.
END
  exit unless _yesno;
}

my $dsn = "dbi:$DB_TYPE:dbname=$DB_DATABASE;host=$DB_HOST";

print "\nDropping $DB_TYPE database $DB_DATABASE.\n";
drop_database( $dsn, $DB_DBA, $DB_DBA_PASSWORD )
  or die $DBIx::DataSource::errstr;

print "\nCreating $DB_TYPE database $DB_DATABASE.\n";
create_database( $dsn, $DB_DBA, $DB_DBA_PASSWORD )
  or die $DBIx::DataSource::errstr;

my $dbh = DBI->connect( $dsn, $DB_DBA, $DB_DBA_PASSWORD ) or die $DBI::errstr;
foreach my $statement ( $schema->sql($dsn) ) {
  my $sth = $dbh->prepare($statement) or die $dbh->errstr;
  $sth->execute or die $sth->errstr;
}
$dbh->disconnect;

sub _yesno {
  print "Proceed [y/N]:";
  my $x = scalar(<STDIN>);
  $x =~ /^y/i;
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: schema.pm
Type: application/x-perl
Size: 8182 bytes
Desc: not available
Url : http://pallas.eruditorum.org/pipermail/rt-devel/attachments/20000927/47ac900f/schema.bin
-------------- next part --------------
# $Header: /proj/maps/src/rt/etc/insert.mysql,v 1.1 2000/09/27 19:11:32 ivan Exp $
#
# Request Tracker is Copyright 1996-1999 Jesse Reed Vincent <jesse at fsck.com>
# RT is distributed under the terms of the GNU Public License

# The data shouldn't be here, it's mostly for test purposes.  Eventually,
# the makefile should call up some init scrips that uses an RT api or the (admin)
# cli to add the data.

# {{{ Queues, Tickets, Transactions, Attachments, Links

# {{{ Values for Queues
# Default queue - should eventually be created by the admin-cli through some init script
INSERT INTO Queues VALUES (1, 'general','A General Catch-all queue' ,'rt at localhost', 'rt-comment at localhost', 1, 0, 0, NULL, NULL, NULL, NULL);
# }}}

# {{{ Values for Users
INSERT into Users (id, UserId, RealName, Comments, Creator, Created, LastUpdatedBy, LastUpdated) 
	   VALUES (1, 'RT_System', "The RT System itself", 'Do not delete or modify this user. It is integral to RT\'s internal database structures',1, NULL, 1, NULL );

INSERT into Users (id, UserId, RealName, Comments,CanManipulate, Creator, Created, LastUpdatedBy, LastUpdated) 
	   VALUES (2, 'Nobody', "Noone in particular", 'Do not delete or modify this user. It is integral to RT\'s internal database structures',1,1, NULL, 1, NULL );

INSERT into Users (id, UserId, Gecos, RealName, Password, EmailAddress, Comments,CanManipulate, Creator, Created, LastUpdatedBy, LastUpdated) 
	   VALUES (3, 'root', 'root', "Enoch Root", 'password', 'root at localhost','',1, 1, NULL, 1, NULL );			
# }}}

#Grant everyone all rights until we get things settled
INSERT INTO ACL VALUES (1,0,'Everyone','Superuser','System',0);
# }}}

# {{{ Values for Scrips

# Short about the default available actions for subscriptions; (this should be in some docs)

# Action    - base class for any scrips.
#   SendEmail - standard thing, mails away a template
#     Notify  - sends away a template to the recipient in the Scrips Argument 
#     AutoReply - sends an autoreply 

INSERT INTO Scrips VALUES (1,'Autoreply', 
			  'Sends an automatic response to the requestor when a ticket was created',
			  'Create','AutoReply',1,'',0,NULL,0,NULL);

INSERT INTO Scrips VALUES (2,'NotifyOwnerOnTransaction',
			  'Sends mail to owner when anything happens',
			  'Any','Notify',2,'Owner',0,NULL,0,NULL);

INSERT INTO Scrips VALUES (3, 'NotifyAdminWatchersOnCorrespond',
			  'Sends mail to administrative watchers when email comes in',
			  'Correspond,Create','SendEmail',3,'',0,NULL,0,NULL);

INSERT INTO Scrips VALUES (4, 'NotifyRegularWatchersOnCorrespond', 
			  'Send "official" mail to (external) Cc watchers and (external) requestors whenever correspondence comes in',
			  'Correspond','SendEmail',4,'',0,NULL,0,NULL);

INSERT INTO Scrips VALUES (5, 'NotifyAdminWatchersOnComment',
			   'Send mail to administrative watchers whenever comments come in',
			  'Comment','SendEmail',5,'AdminCc',1,0,1,0);

INSERT INTO Scrips VALUES (6, 'NotifyAllWatchersOnStatus', 
			  'Send mail to watchers whenever a ticket\'s status changes',
			  'Resolve/Stall/Open/Kill','SendEmail',6,'',1,0,1,0);

INSERT INTO Scrips VALUES (7, 'NotifyAllWatchersOnResolve', 
			  'Send mail to watchers whenever a ticket\'s status changes to resolved.', 
			  'Resolve','SendEmailOnResolve',7,'',1,0,1,0);

INSERT INTO Scrips VALUES (8, 'NotifyAdminWatchersOnTransaction',
			  'Sends mail to owner when anything happens',
			  'Any','Notify',2,'AdminCc',1,NULL,1,NULL);

##TODO: Get Notify.pm to support OldOwner + fix a template
#INSERT INTO Scrips VALUES (20, 'NotifyOldOwnerOnSteal',
#			  'Sends mail to the old owner when the ticket is stolen',
#			  'Steal','Notify',10,'OldOwner',1,NULL,1,NULL);

# Short about the default available link actions available;

# Action

#   StallDependent - stalls the dependent upon a DependsOn linking action.
#   StallMember - stalls a member upon a MemberOf linking action.
#   OpenDependent - when a DependsOn is resolved, the dependent should be opened.
#   Spam - upon correspondance to a group ticket, sends to all member requestors.
#   ResolveMembers - when a Group Ticket is resolved, all Members should be resolved.
#   ResolveGroupTicket - resolve the Group Ticket when all Members are resolved.

INSERT INTO Scrips VALUES (9, 'StallDependentOnLink', 
		           'Stalls the dependent when a DependsOn link is made',
			   'Link', 'StallDependent',NULL,NULL,1,NULL,1,NULL);

INSERT INTO Scrips VALUES (14, 'StallMemberOnLink', 
		           'Stalls the member when a MemberOf link is made',
			   'Link', 'StallDependent',NULL,'MemberOf',1,NULL,1,NULL);

INSERT INTO Scrips VALUES (10, 'OpenDependentOnResolve',
		           'Opens the dependent when the DependsOn is resolved',
			   'Resolve', 'OpenDependent',NULL,NULL,1,NULL,1,NULL);

INSERT INTO Scrips VALUES (11, 'ResolveMembers',
		           'Resolves all members when MemberOf is resolved',
			   'Resolve', 'ResolveMembers',NULL,NULL,1,NULL,1,NULL);

INSERT INTO Scrips VALUES (13, 'NotifyWatchersofMembers', 'Sends mail to the watchers of all tickets
			   which are members of this ticket',
			   'Correspond', 'Spam',4,NULL,1,NULL,1,NULL);

INSERT INTO Scrips VALUES (255, 'PlaceHolder', 'Custom Scrips should have higher ID', 'None', 
			  NULL, NULL, NULL, NULL, NULL, NULL, NULL);

# }}}

# Put all scrips at all queues:
insert into ScripScope select NULL, id, 0, NULL, NULL, NULL, NULL, NULL from Scrips;
delete from ScripScope where id=8;

# }}}

# }}}

# {{{ Templates

# {{{ Values for Templates
# Default templates
# Should eventually be created through some init script calling on the CLI admin tools

INSERT INTO Templates VALUES (1,'Default Autoresponse Template', NULL, NULL,
'To: {$Ticket->RequestorsAsString}
Cc: {$Ticket->CcAsString}
Bcc: {$Ticket->AdminCcAsString}
Subject: AutoReply: {$Ticket->Subject}

       Greetings,
        This message has been automatically generated in response to your
message regarding \"{$Ticket->Subject()}\", the content of which appears below.
There is no need to reply to it now. The Support group has received
your message and it has been assigned a ticket ID of [{$rtname} #{$Ticket->id()}].
Please include the string

         [{$rtname} #{$Ticket->id}]
in the subject line of all future correspondence about this
problem. To do so, you may reply to this message.
                        Thank you,
                        The Support Group
                        {$Ticket->QueueObj->CorrespondAddress()}

-------------------------------------------------------------------------
{$Transaction->Message()->First()->Content()}
',
NULL,20000227191248,NULL,00000000000000);

INSERT INTO Templates VALUES (2,'Default transaction template',NULL, NULL,
'Reply-To: {$Ticket->QueueObj->CommentAddress} (Replies will be entered as comments)

{$Transaction->CreatedAsString}: Request {$Ticket->id} was acted upon.
Transaction: {$Transaction->Description}
       Queue: {$Ticket->QueueObj->QueueId}
     Subject: {my $z=$Transaction->Message()->First(); $z ? $z->Subject : "(No subject given)"}
       Owner: {$Ticket->OwnerObj->UserId}
  Requestors: {join(",",@{$Ticket->Requestors->Emails()})}    
      Status: {$Ticket->Status}
 Ticket <URL: {$RT::WebURL}/Ticket/Display.html?id={$Ticket->id} >
-------------------------------------------------------------------------
{$Transaction->Message()->First()->Content() if $Transaction->Message()->First()}',
NULL,20000227191543,NULL,00000000000000);



INSERT INTO Templates VALUES (3,'Default admin correspondence template', NULL, NULL,
'Subject: {$Transaction->Message()->First()->Subject}
Content-Type: text/plain; charset=ISO-8859-1
To: {$Ticket->AdminCcAsString}

{$Transaction->IsInbound() ? "In" : "Out"}bound correspondence:

<URL: {$RT::WebURL}/Ticket/Display.html?id={$Ticket->id} >

{$Transaction->Message()->First()->Content()}',
NULL,20000227191745,NULL,00000000000000);

INSERT INTO Templates VALUES (4,'Default Correspondence template for requestors', NULL, NULL,
'Subject: {my $z=$Transaction->Message()->First(); $z ? $z->Subject : "(No subject given)"}
To: {$Ticket->RequestorsAsString}
Cc: {$Ticket->CcAsString}
Content-Type: text/plain; charset=ISO-8859-1

{$Transaction->Message()->First()->Content()}',
NULL,20000227191745,NULL,00000000000000);





INSERT INTO Templates VALUES (5,'Default Administrative Comment template', NULL, NULL,
'Subject: [Comment] {my $z=$Transaction->Message()->First(); return "(...)" unless $z; my $s=$z->Subject; $s =~ s/\\[Comment\\]//g; $comment =~ s/^Re//i; $s;}
Reply-To: {$Ticket->QueueObj->CommentAddress}
Content-Type: text/plain; charset=ISO-8859-1
To: {$Ticket->AdminCcAsString}

{$RT::WebURL}/Ticket/Display.html?id={$Ticket->id}
This is a comment.  It is not sent to the Requestor(s):

{$Transaction->Message()->First()->Content()}
',
NULL,20000227191745,NULL,00000000000000);


INSERT INTO Templates VALUES (6,'Status Change', NULL, NULL,
'Subject: Status Changed to: {$Transaction->NewValue}
Reply-To: {$Ticket->QueueObj->CorrespondAddress}
Content-Type: text/plain; charset=ISO-8859-1
To: {$Ticket->WatchersAsString}

{$RT::WebURL}/Ticket/Display.html?id={$Ticket->id}

{$Transaction->Message()->First()->Content()}
',
NULL,20000227191745,NULL,00000000000000);

INSERT INTO Templates VALUES (7,'Ticket Resolved', NULL, NULL,
'Subject: Ticket Resolved
Reply-To: {$Ticket->QueueObj->CorrespondAddress}
Content-Type: text/plain; charset=ISO-8859-1
To: {$Ticket->RequestorsAsString}
Cc: {$Ticket->CcAsString}

Your request has been resolved. We hope you\'re happy.
',
NULL,20000227191745,NULL,00000000000000);

# }}}



More information about the Rt-devel mailing list