2 package Debbugs::DB::Result::BinVer;
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
9 Debbugs::DB::Result::BinVer - Binary versions
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_ver>
36 __PACKAGE__->table("bin_ver");
45 sequence: 'bin_ver_id_seq'
55 Binary package id (matches bin_pkg)
63 Source version (matchines src_ver)
71 Architecture id (matches arch)
75 data_type: 'debversion'
82 __PACKAGE__->add_columns(
85 data_type => "integer",
86 is_auto_increment => 1,
88 sequence => "bin_ver_id_seq",
91 { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
93 { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
95 { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
97 { data_type => "debversion", is_nullable => 0 },
110 __PACKAGE__->set_primary_key("id");
112 =head1 UNIQUE CONSTRAINTS
114 =head2 C<bin_ver_bin_pkg_id_arch_idx>
128 __PACKAGE__->add_unique_constraint("bin_ver_bin_pkg_id_arch_idx", ["bin_pkg", "arch", "ver"]);
136 Related object: L<Debbugs::DB::Result::Arch>
140 __PACKAGE__->belongs_to(
142 "Debbugs::DB::Result::Arch",
144 { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" },
147 =head2 bin_associations
151 Related object: L<Debbugs::DB::Result::BinAssociation>
155 __PACKAGE__->has_many(
157 "Debbugs::DB::Result::BinAssociation",
158 { "foreign.bin" => "self.id" },
159 { cascade_copy => 0, cascade_delete => 0 },
166 Related object: L<Debbugs::DB::Result::BinPkg>
170 __PACKAGE__->belongs_to(
172 "Debbugs::DB::Result::BinPkg",
174 { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" },
181 Related object: L<Debbugs::DB::Result::SrcVer>
185 __PACKAGE__->belongs_to(
187 "Debbugs::DB::Result::SrcVer",
189 { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" },
193 # Created by DBIx::Class::Schema::Loader v0.07045 @ 2016-11-24 09:08:27
194 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DzTzZbPkilT8WMhXoZv9xw
197 sub sqlt_deploy_hook {
198 my ($self, $sqlt_table) = @_;
199 for my $idx (qw(ver bin_pkg src_ver)) {
200 $sqlt_table->add_index(name => 'bin_ver_'.$idx.'_id_idx',
203 $sqlt_table->add_index(name => 'bin_ver_src_ver_id_arch_idx',
204 fields => [qw(src_ver arch)]
206 $sqlt_table->schema->
207 add_procedure(name => 'bin_ver_to_src_pkg',
209 CREATE OR REPLACE FUNCTION bin_ver_to_src_pkg(bin_ver INT) RETURNS INT
210 AS $src_pkg_from_bin_ver$
214 SELECT sv.src_pkg INTO STRICT src_pkg
215 FROM bin_ver bv JOIN src_ver sv ON bv.src_ver=sv.id
219 $src_pkg_from_bin_ver$ LANGUAGE plpgsql;
222 $sqlt_table->schema->
223 add_procedure(name => 'update_bin_pkg_src_pkg_bin_ver',
225 CREATE OR REPLACE FUNCTION update_bin_pkg_src_pkg_bin_ver () RETURNS TRIGGER
226 AS $update_bin_pkg_src_pkg_bin_ver$
228 src_ver_rows integer;
230 IF (TG_OP = 'DELETE' OR TG_OP = 'UPDATE' ) THEN
231 -- if there is still a bin_ver with this src_pkg, then do nothing
232 PERFORM * FROM bin_ver bv JOIN src_ver sv ON bv.src_ver = sv.id
233 WHERE sv.id = OLD.src_ver LIMIT 2;
234 GET DIAGNOSTICS src_ver_rows = ROW_COUNT;
235 IF (src_ver_rows <= 1) THEN
236 DELETE FROM bin_pkg_src_pkg
237 WHERE bin_pkg=OLD.bin_pkg AND
238 src_pkg=src_ver_to_src_pkg(OLD.src_ver);
241 IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE') THEN
243 INSERT INTO bin_pkg_src_pkg (bin_pkg,src_pkg)
244 VALUES (NEW.bin_pkg,src_ver_to_src_pkg(NEW.src_ver))
245 ON CONFLICT (bin_pkg,src_pkg) DO NOTHING;
250 $update_bin_pkg_src_pkg_bin_ver$ LANGUAGE plpgsql;
253 # $sqlt_table->schema->
254 # add_trigger(name => 'bin_ver_update_bin_pkg_src_pkg',
255 # perform_action_when => 'after',
256 # database_events => [qw(INSERT UPDATE DELETE)],
257 # on_table => 'bin_ver',
259 # FOR EACH ROW EXECUTE PROCEDURE update_bin_pkg_src_pkg_bin_ver();