Skip to content

Commit

Permalink
Merge pull request #602 from RotherOSS/issue-#576-dbi_tables
Browse files Browse the repository at this point in the history
Issue #576 dbi tables
  • Loading branch information
bschmalhofer authored Oct 31, 2020
2 parents 1548798 + e1d135c commit 6146683
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 102 deletions.
10 changes: 7 additions & 3 deletions Kernel/System/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ On databases like Oracle it could happen that too many tables are listed (all be
to the current user), if the user also has permissions for other databases. So this list
should only be used for verification of the presence of expected OTOBO tables.
The table names are lower cased.
=cut

sub ListTables {
Expand All @@ -946,18 +948,19 @@ sub ListTables {
Priority => 'Error',
Message => "Database driver $Self->{'DB::Type'} does not support ListTables.",
);

return;
}

my $Success = $Self->Prepare(
SQL => $SQL,
);

return if !$Success;
return unless $Success;

my @Tables;
while ( my @Row = $Self->FetchrowArray() ) {
push @Tables, lc $Row[0];
while ( my ($Table) = $Self->FetchrowArray() ) {
push @Tables, lc $Table;
}

return @Tables;
Expand Down Expand Up @@ -1021,6 +1024,7 @@ sub SelectAll {
while ( my @Row = $Self->FetchrowArray() ) {
push @Records, \@Row;
}

return \@Records;
}

Expand Down
6 changes: 3 additions & 3 deletions Kernel/System/MigrateFromOTRS/CloneDB/Driver/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ sub SanityChecks {
my $TargetDBObject = $Kernel::OM->Get('Kernel::System::DB');

# get a list of tables on OTRS DB
my @SourceTables = $Self->TablesList( DBObject => $SourceDBObject );
my @SourceTables = $SourceDBObject->ListTables();

# no need to migrate when the source has no tables
return unless @SourceTables;
Expand Down Expand Up @@ -254,10 +254,10 @@ sub DataTransfer {
# the lock will be released at the end of this sub

# get a list of tables on OTRS DB
my @SourceTables = map { lc } $Self->TablesList( DBObject => $SourceDBObject );
my @SourceTables = $SourceDBObject->ListTables();

# get a list of tables on OTOBO DB
my %TargetTableExists = map { $_ => 1 } $TargetDBBackend->TablesList( DBObject => $TargetDBObject );
my %TargetTableExists = map { $_ => 1 } $TargetDBObject->ListTables();

# TODO: put this into Driver/mysql.pm
my ( $SourceSchema, $TargetSchema );
Expand Down
28 changes: 0 additions & 28 deletions Kernel/System/MigrateFromOTRS/CloneDB/Driver/mysql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,6 @@ sub CreateOTRSDBConnection {
return $OTRSDBObject;
}

# List all tables in the OTRS database in alphabetical order.
# The alphabetical ordering is actually undocumented.
sub TablesList {
my $Self = shift;
my %Param = @_;

# check needed stuff
if ( !$Param{DBObject} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need DBObject!",
);

return;
}

$Param{DBObject}->Prepare(
SQL => "SHOW TABLES",
) || return ();

my @Result;
while ( my @Row = $Param{DBObject}->FetchrowArray() ) {
push @Result, $Row[0];
}

return @Result;
}

# List all columns of a table in the order of their position.
sub ColumnsList {
my $Self = shift;
Expand Down
33 changes: 0 additions & 33 deletions Kernel/System/MigrateFromOTRS/CloneDB/Driver/oracle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,40 +97,7 @@ sub CreateOTRSDBConnection {
return $OTRSDBObject;
}

#
# List all tables in the source database in alphabetical order.
#
sub TablesList {
my ( $Self, %Param ) = @_;

# check needed stuff
if ( !$Param{DBObject} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need DBObject!",
);

return;
}

$Param{DBObject}->Prepare(
SQL => "
SELECT table_name
FROM user_tables
ORDER BY table_name ASC",
) || return ();

my @Result;
while ( my @Row = $Param{DBObject}->FetchrowArray() ) {
push @Result, $Row[0];
}

return @Result;
}

#
# List all columns of a table in the order of their position.
#
sub ColumnsList {
my ( $Self, %Param ) = @_;

Expand Down
35 changes: 0 additions & 35 deletions Kernel/System/MigrateFromOTRS/CloneDB/Driver/postgresql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,7 @@ sub CreateOTRSDBConnection {
return $OTRSDBObject;
}

#
# List all tables in the source database in alphabetical order.
#
sub TablesList {
my ( $Self, %Param ) = @_;

# check needed stuff
if ( !$Param{DBObject} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need DBObject!",
);

return;
}

$Param{DBObject}->Prepare(
SQL => "
SELECT table_name
FROM information_schema.tables
WHERE table_name !~ '^pg_+'
AND table_schema != 'information_schema'
ORDER BY table_name ASC",
) || return ();

my @Result;
while ( my @Row = $Param{DBObject}->FetchrowArray() ) {
push @Result, $Row[0];
}

return @Result;
}

#
# List all columns of a table in the order of their position.
#
sub ColumnsList {
my ( $Self, %Param ) = @_;

Expand Down

0 comments on commit 6146683

Please sign in to comment.