From 493d2d394517b9ff99fafeae9537deed4077e783 Mon Sep 17 00:00:00 2001
From: Alessandro Vullo <avullo@ebi.ac.uk>
Date: Wed, 8 May 2013 10:34:30 +0000
Subject: [PATCH] [ENSCORESW-443]. Added test to check presence of foreign key
 constraints

---
 modules/t/schema.t | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/modules/t/schema.t b/modules/t/schema.t
index c00c0bc408..7a9ab62ef3 100644
--- a/modules/t/schema.t
+++ b/modules/t/schema.t
@@ -4,6 +4,7 @@ use warnings;
 use FindBin qw/$Bin/;
 use Test::More;
 use Bio::EnsEMBL::Test::MultiTestDB;
+use Bio::EnsEMBL::Utils::IO qw/slurp/;
 use File::Spec::Functions qw/updir catfile catdir/;
 
 my $db = Bio::EnsEMBL::Test::MultiTestDB->new();
@@ -23,6 +24,15 @@ SKIP: {
   my $new_db_name = $db->create_db_name('schematemp');
   note 'Creating database '.$new_db_name;
   $dba->dbc()->do("create database $new_db_name");
+
+  my $table_string = slurp $sql_file;  
+  my @fks = sort grep /FOREIGN[\s\n]+?KEY[\s\n]+?\(.+?\)[\s\n]+?REFERENCES/i, $table_string;
+  if(@fks) {
+    fail("Definition of foreign keys detected in SQL schema file");
+  } else {
+    pass("SQL schema file does not define foreign keys");
+  }
+
   my %args = ( host => $dbc->host(), port => $dbc->port(), user => $dbc->username(), password => $dbc->password());
   my $cmd_args = join(q{ }, map { "--${_}=$args{$_}" } keys %args);
   my $cmd = "mysql $cmd_args $new_db_name < $sql_file 2>&1";
-- 
GitLab