Skip to content
This repository has been archived by the owner on Feb 12, 2020. It is now read-only.

Commit

Permalink
Split creation of foreign keys from creation of indexes and primary k…
Browse files Browse the repository at this point in the history
…eys.

They're not always needed/wanted.
  • Loading branch information
murdos committed Aug 26, 2011
1 parent 27bf3a2 commit d68bba7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions backend/mysql.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -300,9 +300,18 @@ sub backend_mysql_update_index {
} }
close(SQL); close(SQL);


print "Done\n";
return 1;
}

# backend_mysql_update_foreignkey()
# Attemp to pull as much relevant information from CreateFKConstraints.sql as we can.
# @return Always 1.
sub backend_mysql_update_foreignkey {
open(SQL, "replication/CreateFKConstraints.sql"); open(SQL, "replication/CreateFKConstraints.sql");
chomp(my @lines = <SQL>); chomp(my @lines = <SQL>);
my $index_name = "", $table_name = "", $columns = [], $foreign_table_name = "", $foreign_columns = []; my $index_name = "", $table_name = "", $columns = [], $foreign_table_name = "", $foreign_columns = [];

foreach my $line (@lines) { foreach my $line (@lines) {
# skip blank lines and single bracket lines # skip blank lines and single bracket lines
next if($line eq "" || substr($line, 0, 2) eq "--" || substr($line, 0, 1) eq "\\" || next if($line eq "" || substr($line, 0, 2) eq "--" || substr($line, 0, 1) eq "\\" ||
Expand Down
2 changes: 2 additions & 0 deletions backend/postgresql.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ sub backend_postgresql_update_index {
mbz_do_sql($line, 'nodie'); mbz_do_sql($line, 'nodie');
} }
close(SQL); close(SQL);
}


sub backend_postgresql_update_foreignkey {
open(SQL, "replication/CreateFKConstraints.sql"); open(SQL, "replication/CreateFKConstraints.sql");
chomp(my @lines = <SQL>); chomp(my @lines = <SQL>);
my $sql = ""; my $sql = "";
Expand Down
4 changes: 4 additions & 0 deletions init.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
} elsif($action == 5) { } elsif($action == 5) {
print $L{'init_actionindex'}; print $L{'init_actionindex'};
} elsif($action == 6) { } elsif($action == 6) {
print $L{'init_actionfk'};
} elsif($action == 7) {
print $L{'init_actionplugininit'}; print $L{'init_actionplugininit'};
} }
chomp(my $input = <STDIN>); chomp(my $input = <STDIN>);
Expand Down Expand Up @@ -62,5 +64,7 @@
} elsif($action == 5) { } elsif($action == 5) {
mbz_update_index(); mbz_update_index();
} elsif($action == 6) { } elsif($action == 6) {
mbz_update_foreignkey();
} elsif($action == 7) {
mbz_init_plugins(); mbz_init_plugins();
} }
8 changes: 7 additions & 1 deletion languages/English.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"[3] Load raw tables (requires big download ~1GB)\n". "[3] Load raw tables (requires big download ~1GB)\n".
"[4] Load raw tables (don't download, load from 'mbdump/')\n". "[4] Load raw tables (don't download, load from 'mbdump/')\n".
"[5] Apply table indexing\n". "[5] Apply table indexing\n".
"[6] Initialise plugins\n\n". "[6] Apply table foreign keys\n".
"[7] Initialise plugins\n\n".
"Option: "; "Option: ";


# action descriptions # action descriptions
Expand Down Expand Up @@ -74,6 +75,11 @@
"it is faster.... if you cancel, you can safely return by running this again.\n". "it is faster.... if you cancel, you can safely return by running this again.\n".
"Ready to proceed? (y/n): "; "Ready to proceed? (y/n): ";


$L{'init_actionfk'} =
"One of the most time consuming option. This will apply foreign keys to your already loaded\n".
"database. If you cancel, you can safely return by running this again.\n".
"Ready to proceed? (y/n): ";

$L{'init_actionplugininit'} = $L{'init_actionplugininit'} =
"Run this last but before you start the replications. Make sure you edit settings.pl\n". "Run this last but before you start the replications. Make sure you edit settings.pl\n".
"with the active plugins you wish to initialise in \@g_active_plugins.\n\n". "with the active plugins you wish to initialise in \@g_active_plugins.\n\n".
Expand Down
9 changes: 9 additions & 0 deletions src/functions.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -820,6 +820,15 @@ sub mbz_update_index {
return (\&$function_name)->(); return (\&$function_name)->();
} }


# mbz_update_foreignkey()
# This subroutine is just a controller that redirects to the update index for the RDBMS we are
# using.
# @return Passthru from backend_DB_update_index().
sub mbz_update_foreignkey {
# use the subroutine appropriate for the RDBMS
my $function_name = "backend_${g_db_rdbms}_update_foreignkey";
return (\&$function_name)->();
}


# mbz_update_schema() # mbz_update_schema()
# This subroutine is just a controller that redirects to the update schema for the RDBMS we are # This subroutine is just a controller that redirects to the update schema for the RDBMS we are
Expand Down

0 comments on commit d68bba7

Please sign in to comment.