
This is another helper script.
Sometimes you define tables that should be created on OPM package
installation. And it happens during development that you have already
installed a version of your OPM package but another table should be
created. Then you may not deinstall the package just to get the new
table created as you will lose all data of your package on deinstallation.
There exists a script called xml2sql.pl in OTRS_HOME/bin, but that
creates all SQL statements even those that were written for
deinstallation process.
My script extracts only the DatabaseInstall part and you can specify a
single table. And it calls xml2sql to generate the SQL statements for
that specific part.
Example:
<DatabaseInstall Type="post">
<TableCreate Name="table1">
<!-- Column Definition -->
</TableCreate>
<TableCreate Name="table2">
<!-- Column Definition -->
</TableCreate>
</DatabaseInstall>
<DatabaseUninstall Type="pre">
<TableDrop Name="table1"/>
<TableDrop Name="table2"/>
</DatabaseUninstall>
C:\>sopm2xml.pl -file .\yourfile.sopm -table table2 -sql
# ----------------------------------------------------------
# driver: mysql, generated: 2009-03-20 09:46:07
# ----------------------------------------------------------
# ----------------------------------------------------------
# create table table2
# ----------------------------------------------------------
CREATE TABLE table2 (
id BIGINT NOT NULL AUTO_INCREMENT,
name BIGINT NOT NULL,
test VARCHAR (255) NOT NULL,
PRIMARY KEY(id)
);
With -t option you can specify the db type (like the -t option for
xml2sql.pl).
You have to configure the path to xml2sql.pl in the script.
Cheers,
Renée
--
Perl-Magazin: http://perl-magazin.de
Perl-Nachrichten: http://perl-nachrichten.de
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use File::Basename;
use File::Spec;
use File::Temp qw(tempfile);
GetOptions(
'file=s' => \my $file,
'out=s' => \my $outputdir,
'table=s' => \my $table,
'type=s' => \my $type,
'sql' => \my $sql_required,
);
die 'specify .sopm file with -file option' unless $file;
my $filename = basename( $file, '.sopm' );
my $part = "";
my $xml2sql = 'D:\OTRS\bin\xml2sql.pl';
open my $fh, '<', $file or die $!;
while( my $line = <$fh> ){
if( $line =~ /