Skip to content

Commit

Permalink
Added a missing foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Feb 18, 2017
1 parent b1a007e commit 4f78c75
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 17 deletions.
63 changes: 51 additions & 12 deletions db/magnum.sql
@@ -1,8 +1,8 @@
-- MySQL dump 10.15 Distrib 10.0.20-MariaDB, for Linux (x86_64)
-- MySQL dump 10.16 Distrib 10.1.21-MariaDB, for Linux (x86_64)
--
-- Host: mag-sol.com Database: magnum
-- Host: mag-sol.com Database: mag-sol.com
-- ------------------------------------------------------
-- Server version 5.5.41-MariaDB
-- Server version 5.5.52-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Expand Down Expand Up @@ -48,7 +48,7 @@ CREATE TABLE `contract` (
CONSTRAINT `contract_ibfk_2` FOREIGN KEY (`employee`) REFERENCES `employee` (`id`),
CONSTRAINT `contract_ibfk_3` FOREIGN KEY (`product`) REFERENCES `product` (`id`),
CONSTRAINT `contract_ibfk_4` FOREIGN KEY (`site`) REFERENCES `site` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -71,7 +71,7 @@ CREATE TABLE `customer` (
`invoice_address` varchar(255) NOT NULL DEFAULT '',
`note` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -93,7 +93,7 @@ CREATE TABLE `day` (
PRIMARY KEY (`id`),
KEY `week` (`week`),
CONSTRAINT `day_week_fk` FOREIGN KEY (`week`) REFERENCES `week` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5551 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=5976 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -126,12 +126,13 @@ CREATE TABLE `invoice` (
`customer` int(11) NOT NULL DEFAULT '0',
`contract` int(11) DEFAULT NULL,
`cust_ref` varchar(20) DEFAULT NULL,
`cust_ref_desc` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `invoice_contract_fk` (`contract`),
KEY `invoice_customer_fk` (`customer`),
CONSTRAINT `invoice_contract_fk` FOREIGN KEY (`contract`) REFERENCES `contract` (`id`),
CONSTRAINT `invoice_customer_fk` FOREIGN KEY (`customer`) REFERENCES `customer` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=420 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=443 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -154,7 +155,24 @@ CREATE TABLE `invoice_line` (
KEY `week` (`week`),
CONSTRAINT `invoice_line_ibfk_1` FOREIGN KEY (`week`) REFERENCES `week` (`id`),
CONSTRAINT `line_invoice_fk` FOREIGN KEY (`invoice`) REFERENCES `invoice` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1134 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=1204 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `month`
--

DROP TABLE IF EXISTS `month`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `month` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`year` int(11) NOT NULL,
`month` int(11) NOT NULL,
`month_name` varchar(15) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=277 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -189,7 +207,25 @@ CREATE TABLE `site` (
`email` varchar(50) DEFAULT NULL,
`note` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `temptable`
--

DROP TABLE IF EXISTS `temptable`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `temptable` (
`id` int(11) NOT NULL DEFAULT '0',
`invoice` int(11) NOT NULL DEFAULT '0',
`line_no` int(11) NOT NULL DEFAULT '0',
`week` int(11) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`amount` decimal(10,2) NOT NULL DEFAULT '0.00',
`vat` char(10) NOT NULL DEFAULT 'standard'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -206,7 +242,7 @@ CREATE TABLE `vat_rate` (
`type` char(10) NOT NULL,
`rate` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -221,10 +257,13 @@ CREATE TABLE `week` (
`contract` int(11) NOT NULL,
`start` date NOT NULL DEFAULT '0000-00-00',
`invoiced` tinyint(4) DEFAULT NULL,
`month` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `contract` (`contract`),
KEY `month` (`month`),
CONSTRAINT `week_ibfk_2` FOREIGN KEY (`month`) REFERENCES `month` (`id`),
CONSTRAINT `week_ibfk_1` FOREIGN KEY (`contract`) REFERENCES `contract` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1042 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=1117 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

Expand All @@ -236,4 +275,4 @@ CREATE TABLE `week` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2015-07-28 10:51:30
-- Dump completed on 2017-02-18 11:39:40
21 changes: 19 additions & 2 deletions lib/Magnum/Schema/Result/Month.pm
Expand Up @@ -93,9 +93,26 @@ __PACKAGE__->add_columns(

__PACKAGE__->set_primary_key("id");

=head1 RELATIONS
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-18 10:28:49
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VhXq5OAeWFLW1O2kddZESQ
=head2 weeks
Type: has_many
Related object: L<Magnum::Schema::Result::Week>
=cut

__PACKAGE__->has_many(
"weeks",
"Magnum::Schema::Result::Week",
{ "foreign.month" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);


# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-18 11:42:16
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Q6aCFF/7REvcSEgR/zwXRw


# You can replace this text with custom code or comments, and it will be preserved on regeneration
Expand Down
22 changes: 19 additions & 3 deletions lib/Magnum/Schema/Result/Week.pm
Expand Up @@ -65,6 +65,7 @@ __PACKAGE__->table("week");
=head2 month
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
=cut
Expand All @@ -84,7 +85,7 @@ __PACKAGE__->add_columns(
"invoiced",
{ data_type => "tinyint", is_nullable => 1 },
"month",
{ data_type => "integer", is_nullable => 0 },
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
);

=head1 PRIMARY KEY
Expand Down Expand Up @@ -146,9 +147,24 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 month
Type: belongs_to
Related object: L<Magnum::Schema::Result::Month>
=cut

__PACKAGE__->belongs_to(
"month",
"Magnum::Schema::Result::Month",
{ id => "month" },
{ is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" },
);


# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-18 11:17:45
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KTpIye3gDoHn65FkgNVLGQ
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-18 11:42:17
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:h15Nso1A9QRFk9H+6n1NGw

sub is_in_month {
my $self = shift;
Expand Down

0 comments on commit 4f78c75

Please sign in to comment.