Permalink
Browse files

Projects and sponsors tables

  • Loading branch information...
1 parent d19388b commit 5224ac78921a3eb0ae84a5f68c81b76ca8dc2a8d Ray Miller committed Aug 1, 2012
View
57 ddl/templates/versions/9/audit-up.sql
@@ -1 +1,58 @@
ALTER TABLE audit.cassettes ADD COLUMN conditional BOOLEAN;
+
+CREATE TABLE audit.projects (
+audit_op CHAR(1) NOT NULL CHECK (audit_op IN ('D','I','U')),
+audit_user TEXT NOT NULL,
+audit_stamp TIMESTAMP NOT NULL,
+audit_txid INTEGER NOT NULL,
+id integer,
+sponsor_id text,
+allele_request text
+);
+GRANT SELECT ON audit.projects TO "[% ro_role %]";
+GRANT SELECT,INSERT ON audit.projects TO "[% rw_role %]";
+CREATE OR REPLACE FUNCTION public.process_projects_audit()
+RETURNS TRIGGER AS $projects_audit$
+ BEGIN
+ IF (TG_OP = 'DELETE') THEN
+ INSERT INTO audit.projects SELECT 'D', user, now(), txid_current(), OLD.*;
+ ELSIF (TG_OP = 'UPDATE') THEN
+ INSERT INTO audit.projects SELECT 'U', user, now(), txid_current(), NEW.*;
+ ELSIF (TG_OP = 'INSERT') THEN
+ INSERT INTO audit.projects SELECT 'I', user, now(), txid_current(), NEW.*;
+ END IF;
+ RETURN NULL;
+ END;
+$projects_audit$ LANGUAGE plpgsql;
+CREATE TRIGGER projects_audit
+AFTER INSERT OR UPDATE OR DELETE ON public.projects
+ FOR EACH ROW EXECUTE PROCEDURE public.process_projects_audit();
+
+CREATE TABLE audit.sponsors (
+audit_op CHAR(1) NOT NULL CHECK (audit_op IN ('D','I','U')),
+audit_user TEXT NOT NULL,
+audit_stamp TIMESTAMP NOT NULL,
+audit_txid INTEGER NOT NULL,
+id text,
+description text
+);
+GRANT SELECT ON audit.sponsors TO "[% ro_role %]";
+GRANT SELECT,INSERT ON audit.sponsors TO "[% rw_role %]";
+CREATE OR REPLACE FUNCTION public.process_sponsors_audit()
+RETURNS TRIGGER AS $sponsors_audit$
+ BEGIN
+ IF (TG_OP = 'DELETE') THEN
+ INSERT INTO audit.sponsors SELECT 'D', user, now(), txid_current(), OLD.*;
+ ELSIF (TG_OP = 'UPDATE') THEN
+ INSERT INTO audit.sponsors SELECT 'U', user, now(), txid_current(), NEW.*;
+ ELSIF (TG_OP = 'INSERT') THEN
+ INSERT INTO audit.sponsors SELECT 'I', user, now(), txid_current(), NEW.*;
+ END IF;
+ RETURN NULL;
+ END;
+$sponsors_audit$ LANGUAGE plpgsql;
+CREATE TRIGGER sponsors_audit
+AFTER INSERT OR UPDATE OR DELETE ON public.sponsors
+ FOR EACH ROW EXECUTE PROCEDURE public.process_sponsors_audit();
+
+
View
8 ddl/templates/versions/9/fixtures.sql
@@ -29,3 +29,11 @@ WHERE name IN (
'pL1L2_GT1_bsd_frt15_neo_barcode',
'pL1L2_GT2_bsd_frt15_neo_barcode'
);
+
+INSERT INTO sponsors(id,description)
+VALUES ( 'Core', 'Homozygous - Core' ),
+ ( 'Syboss', 'Homozygous - Syboss' ),
+ ( 'Pathogens', 'Homozygous - Pathogens' ),
+ ( 'Cre Knockin', 'EUCOMMTools-Cre Knockin' ),
+ ( 'Cre BAC', 'EUCOMMTools-Cre BAC' ),
+ ( 'Human', 'Homozygous - Human' );
View
16 ddl/templates/versions/9/up.sql
@@ -1 +1,17 @@
ALTER TABLE cassettes ADD COLUMN conditional BOOLEAN NOT NULL DEFAULT FALSE;
+
+CREATE TABLE sponsors (
+ id TEXT PRIMARY KEY,
+ description TEXT NOT NULL DEFAULT ''
+);
+GRANT SELECT ON sponsors TO "[% ro_role %]";
+GRANT SELECT, INSERT, UPDATE, DELETE ON sponsors TO "[% rw_role %]";
+
+CREATE TABLE projects (
+ id SERIAL PRIMARY KEY,
+ sponsor_id TEXT NOT NULL REFERENCES sponsors(id),
+ allele_request TEXT NOT NULL
+);
+GRANT SELECT ON projects TO "[% ro_role %]";
+GRANT SELECT, INSERT, UPDATE, DELETE ON projects TO "[% rw_role %]";
+GRANT USAGE ON projects_id_seq TO "[% rw_role %]";
View
111 lib/LIMS2/Model/Schema/Result/Project.pm
@@ -0,0 +1,111 @@
+use utf8;
+package LIMS2::Model::Schema::Result::Project;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+LIMS2::Model::Schema::Result::Project
+
+=cut
+
+use strict;
+use warnings;
+
+use Moose;
+use MooseX::NonMoose;
+use MooseX::MarkAsMethods autoclean => 1;
+extends 'DBIx::Class::Core';
+
+=head1 COMPONENTS LOADED
+
+=over 4
+
+=item * L<DBIx::Class::InflateColumn::DateTime>
+
+=back
+
+=cut
+
+__PACKAGE__->load_components("InflateColumn::DateTime");
+
+=head1 TABLE: C<projects>
+
+=cut
+
+__PACKAGE__->table("projects");
+
+=head1 ACCESSORS
+
+=head2 id
+
+ data_type: 'integer'
+ is_auto_increment: 1
+ is_nullable: 0
+ sequence: 'projects_id_seq'
+
+=head2 sponsor_id
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 allele_request
+
+ data_type: 'text'
+ is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+ "id",
+ {
+ data_type => "integer",
+ is_auto_increment => 1,
+ is_nullable => 0,
+ sequence => "projects_id_seq",
+ },
+ "sponsor_id",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "allele_request",
+ { data_type => "text", is_nullable => 0 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 RELATIONS
+
+=head2 sponsor
+
+Type: belongs_to
+
+Related object: L<LIMS2::Model::Schema::Result::Sponsor>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "sponsor",
+ "LIMS2::Model::Schema::Result::Sponsor",
+ { id => "sponsor_id" },
+ { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07022 @ 2012-08-01 16:23:40
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TEWL4wmlfym0+CuGo3C9zg
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+__PACKAGE__->meta->make_immutable;
+1;
View
21 lib/LIMS2/Model/Schema/Result/Sponsor.pm
@@ -70,9 +70,26 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("id");
+=head1 RELATIONS
-# Created by DBIx::Class::Schema::Loader v0.07022 @ 2012-07-26 12:05:23
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZZ8Ln3+IXCoF98bZWNKZ9A
+=head2 projects
+
+Type: has_many
+
+Related object: L<LIMS2::Model::Schema::Result::Project>
+
+=cut
+
+__PACKAGE__->has_many(
+ "projects",
+ "LIMS2::Model::Schema::Result::Project",
+ { "foreign.sponsor_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07022 @ 2012-08-01 16:23:40
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xZzQ8o0GCiDIaEDQRz5otw
# You can replace this text with custom code or comments, and it will be preserved on regeneration

0 comments on commit 5224ac7

Please sign in to comment.