2 package Debbugs::DB::Result::BinPkgSrcPkg;
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
9 Debbugs::DB::Result::BinPkgSrcPkg - Binary package <-> source package mapping sumpmary table
16 use base 'DBIx::Class::Core';
18 =head1 COMPONENTS LOADED
22 =item * L<DBIx::Class::InflateColumn::DateTime>
24 =item * L<DBIx::Class::TimeStamp>
30 __PACKAGE__->load_components("InflateColumn::DateTime", "TimeStamp");
32 =head1 TABLE: C<bin_pkg_src_pkg>
36 __PACKAGE__->table("bin_pkg_src_pkg");
46 Binary package id (matches bin_pkg)
54 Source package id (matches src_pkg)
58 __PACKAGE__->add_columns(
60 { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
62 { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
65 =head1 UNIQUE CONSTRAINTS
67 =head2 C<bin_pkg_src_pkg_bin_pkg_src_pkg>
79 __PACKAGE__->add_unique_constraint("bin_pkg_src_pkg_bin_pkg_src_pkg", ["bin_pkg", "src_pkg"]);
81 =head2 C<bin_pkg_src_pkg_src_pkg_bin_pkg>
93 __PACKAGE__->add_unique_constraint("bin_pkg_src_pkg_src_pkg_bin_pkg", ["src_pkg", "bin_pkg"]);
101 Related object: L<Debbugs::DB::Result::BinPkg>
105 __PACKAGE__->belongs_to(
107 "Debbugs::DB::Result::BinPkg",
109 { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" },
116 Related object: L<Debbugs::DB::Result::SrcPkg>
120 __PACKAGE__->belongs_to(
122 "Debbugs::DB::Result::SrcPkg",
124 { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" },
128 # Created by DBIx::Class::Schema::Loader v0.07048 @ 2018-04-18 16:55:56
129 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:O/v5RtjJF9SgxXEy76U/xw
131 sub sqlt_deploy_hook {
132 my ($self, $sqlt_table) = @_;
133 $sqlt_table->schema->
134 add_procedure(name => 'bin_ver_to_src_pkg',
136 CREATE OR REPLACE FUNCTION bin_ver_to_src_pkg(bin_ver INT) RETURNS INT
137 AS $src_pkg_from_bin_ver$
141 SELECT sv.src_pkg INTO STRICT src_pkg
142 FROM bin_ver bv JOIN src_ver sv ON bv.src_ver=sv.id
146 $src_pkg_from_bin_ver$ LANGUAGE plpgsql;
149 $sqlt_table->schema->
150 add_procedure(name => 'src_ver_to_src_pkg',
152 CREATE OR REPLACE FUNCTION src_ver_to_src_pkg(src_ver INT) RETURNS INT
153 AS $src_ver_to_src_pkg$
157 SELECT sv.src_pkg INTO STRICT src_pkg
158 FROM src_ver sv WHERE sv.id=src_ver;
161 $src_ver_to_src_pkg$ LANGUAGE plpgsql;
164 $sqlt_table->schema->
165 add_procedure(name => 'update_bin_pkg_src_pkg_bin_ver',
167 CREATE OR REPLACE FUNCTION update_bin_pkg_src_pkg_bin_ver () RETURNS TRIGGER
168 AS $update_bin_pkg_src_pkg_bin_ver$
170 src_ver_rows integer;
172 IF (TG_OP = 'DELETE' OR TG_OP = 'UPDATE' ) THEN
173 -- if there is still a bin_ver with this src_pkg, then do nothing
174 PERFORM * FROM bin_ver bv JOIN src_ver sv ON bv.src_ver = sv.id
175 WHERE sv.id = OLD.src_ver LIMIT 2;
176 GET DIAGNOSTICS src_ver_rows = ROW_COUNT;
177 IF (src_ver_rows <= 1) THEN
178 DELETE FROM bin_pkg_src_pkg
179 WHERE bin_pkg=OLD.bin_pkg AND
180 src_pkg=src_ver_to_src_pkg(OLD.src_ver);
183 IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE') THEN
185 INSERT INTO bin_pkg_src_pkg (bin_pkg,src_pkg)
186 VALUES (NEW.bin_pkg,src_ver_to_src_pkg(NEW.src_ver))
187 ON CONFLICT (bin_pkg,src_pkg) DO NOTHING;
192 $update_bin_pkg_src_pkg_bin_ver$ LANGUAGE plpgsql;