File: reverse_cardinality.pl

package info (click to toggle)
libalzabo-perl 0.86-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,116 kB
  • ctags: 767
  • sloc: perl: 14,549; makefile: 46
file content (40 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl -w

use strict;

use Alzabo::Create::Schema;

unless (@ARGV)
{
    print <<'EOF';

This script requires at least one argument, a schema name.  If it is
given multiple arguments it will treat them all as script names
EOF

    exit 0;
}

foreach (@ARGV)
{
    my $s = Alzabo::Create::Schema->load_from_file( name => $_ );
    reverse_cardinality($s);
}

sub reverse_cardinality
{
    my $s = shift;

    foreach my $t ($s->tables)
    {
	foreach my $fk ($t->all_foreign_keys)
	{
	    my @c = $fk->cardinality;

	    $fk->set_cardinality(@c[1,0]);
	}
    }

    $s->save_to_file;
}