1DBIx::Class::Helper::ScUhseemra:C:oLnitnrtiCbouDntBteIedxn:tP:seC(rl3la)sDso:c:uHmeelnpteart:i:oSnchema::LintContents(3)
2
3
4

NAME

6       DBIx::Class::Helper::Schema::LintContents - suite of methods to find
7       violated "constraints"
8

SYNOPSIS

10        package MyApp::Schema;
11
12        use parent 'DBIx::Class::Schema';
13
14        __PACKAGE__->load_components('Helper::Schema::LintContents');
15
16        1;
17
18       And later, somewhere else:
19
20        say "Incorrectly Null Users:";
21        for ($schema->null_check_source_auto('User')->all) {
22           say '* ' . $_->id
23        }
24
25        say "Duplicate Users:";
26        my $duplicates = $schema->dup_check_source_auto('User');
27        for (keys %$duplicates) {
28           say "Constraint: $_";
29           for ($duplicates->{$_}->all) {
30              say '* ' . $_->id
31           }
32        }
33
34        say "Users with invalid FK's:";
35        my $invalid_fks = $schema->fk_check_source_auto('User');
36        for (keys %$invalid_fks) {
37           say "Rel: $_";
38           for ($invalid_fks->{$_}->all) {
39              say '* ' . $_->id
40           }
41        }
42

DESCRIPTION

44       Some people think that constraints make their databases slower.  As
45       silly as that is, I have been in a similar situation!  I'm here to help
46       you, dear developers!  Basically this is a suite of methods that allow
47       you to find violated "constraints."  To be clear, the constraints I
48       mean are the ones you tell DBIx::Class about, real constraints are
49       fairly sure to be followed.
50

METHODS

52   fk_check_source
53        my $busted = $schema->fk_check_source(
54          'User',
55          'Group',
56          { group_id => 'id' },
57        );
58
59       "fk_check_source" takes three arguments, the first is the from source
60       moniker of a relationship.  The second is the to source or source
61       moniker of a relationship.  The final argument is a hash reference
62       representing the columns of the relationship.  The return value is a
63       resultset of the from source that do not have a corresponding to row.
64       To be clear, the example given above would return a resultset of "User"
65       rows that have a "group_id" that points to a "Group" that does not
66       exist.
67
68   fk_check_source_auto
69        my $broken = $schema->fk_check_source_auto('User');
70
71       "fk_check_source_auto" takes a single argument: the source to check.
72       It will check all the foreign key (that is, "belongs_to") relationships
73       for missing...  "foreign" rows.  The return value will be a hashref
74       where the keys are the relationship name and the values are resultsets
75       of the respective violated relationship.
76
77   dup_check_source
78        my $smashed = $schema->fk_check_source( 'Group', ['id'] );
79
80       "dup_check_source" takes two arguments, the first is the source moniker
81       to be checked.  The second is an arrayref of columns that "should be"
82       unique.  The return value is a resultset of the source that duplicate
83       the passed columns.  So with the example above the resultset would
84       return all groups that are "duplicates" of other groups based on "id".
85
86   dup_check_source_auto
87        my $ruined = $schema->dup_check_source_auto('Group');
88
89       "dup_check_source_auto" takes a single argument, which is the name of
90       the resultsource in which to check for duplicates.  It will return a
91       hashref where they keys are the names of the unique constraints to be
92       checked.  The values will be resultsets of the respective duplicate
93       rows.
94
95   null_check_source
96        my $blarg = $schema->null_check_source('Group', ['id']);
97
98       "null_check_source" tales two arguments, the first is the name of the
99       source to check.  The second is an arrayref of columns that should
100       contain no nulls.  The return value is simply a resultset of rows that
101       contain nulls where they shouldn't be.
102
103   null_check_source_auto
104        my $wrecked = $schema->null_check_source_auto('Group');
105
106       "null_check_source_auto" takes a single argument, which is the name of
107       the resultsource in which to check for nulls.  The return value is
108       simply a resultset of rows that contain nulls where they shouldn't be.
109       This method automatically uses the configured columns that have
110       "is_nullable" set to false.
111

AUTHOR

113       Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
114
116       This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
117
118       This is free software; you can redistribute it and/or modify it under
119       the same terms as the Perl 5 programming language system itself.
120
121
122
123perl v5.34.0                      2D0B2I1x-:0:7C-l2a2ss::Helper::Schema::LintContents(3)
Impressum