From 2f2dfcb224dcc0ddf99261a650b84c2baaf334ba Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Fri, 2 Oct 2015 14:23:30 +0100 Subject: [PATCH] Simple script to add characters. Added P&P characters. --- Literature/lib/Literature/Schema.pm | 13 ++++++++++++ db/literature.dat | 6 +++--- db/literature.sql | 4 ++-- util/load_chars | 32 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100755 util/load_chars diff --git a/Literature/lib/Literature/Schema.pm b/Literature/lib/Literature/Schema.pm index ac1c879..6729271 100644 --- a/Literature/lib/Literature/Schema.pm +++ b/Literature/lib/Literature/Schema.pm @@ -14,6 +14,19 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 20:37:37 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LLfKaZZTfOORlQkSPO9kIg +sub get_schema { + my $class = shift; + + unless ($ENV{LIT_USER} and $ENV{LIT_PASS}) { + die "You must set LIT_USER and LIT_PASS\n"; + } + + return $class->connect( + "dbi:mysql:database=literature", + $ENV{LIT_USER}, $ENV{LIT_PASS}, + { mysql_enable_utf8 => 1 }, + ) || die; +} # You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/db/literature.dat b/db/literature.dat index c9bab94..575979a 100644 --- a/db/literature.dat +++ b/db/literature.dat @@ -60,7 +60,7 @@ UNLOCK TABLES; LOCK TABLES `fictional_character` WRITE; /*!40000 ALTER TABLE `fictional_character` DISABLE KEYS */; -INSERT INTO `fictional_character` VALUES (1,'Elizabeth Bennet'),(2,'FitzWilliam D\'Arcy'); +INSERT INTO `fictional_character` VALUES (1,'Elizabeth Bennet'),(2,'FitzWilliam D\'Arcy'),(3,'Mr Bennet'),(4,'Mrs Bennet'),(5,'Jane Bennet'),(6,'Mary Bennet'),(7,'Catherine Bennet'),(8,'Lydia Bennet'),(9,'Charles Bingley'),(10,'Caroline Bingley'),(11,'George Wickham'),(12,'William Collins'),(13,'Lady Catherine de Bourgh'); /*!40000 ALTER TABLE `fictional_character` ENABLE KEYS */; UNLOCK TABLES; @@ -70,7 +70,7 @@ UNLOCK TABLES; LOCK TABLES `fictional_character_appearance` WRITE; /*!40000 ALTER TABLE `fictional_character_appearance` DISABLE KEYS */; -INSERT INTO `fictional_character_appearance` VALUES (1,22),(2,22); +INSERT INTO `fictional_character_appearance` VALUES (1,22),(2,22),(3,22),(4,22),(5,22),(6,22),(7,22),(8,22),(9,22),(10,22),(11,22),(12,22),(13,22); /*!40000 ALTER TABLE `fictional_character_appearance` ENABLE KEYS */; UNLOCK TABLES; @@ -121,4 +121,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2015-10-02 13:27:31 +-- Dump completed on 2015-10-02 14:22:20 diff --git a/db/literature.sql b/db/literature.sql index 70cdaad..a18ff27 100644 --- a/db/literature.sql +++ b/db/literature.sql @@ -100,7 +100,7 @@ CREATE TABLE `fictional_character` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -198,4 +198,4 @@ CREATE TABLE `work_product` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2015-10-02 13:27:31 +-- Dump completed on 2015-10-02 14:22:20 diff --git a/util/load_chars b/util/load_chars new file mode 100755 index 0000000..9c6b5a6 --- /dev/null +++ b/util/load_chars @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use FindBin '$Bin'; +use lib "$Bin/../Literature/lib"; +use 5.010; + +use Literature::Schema; + +my $sch = Literature::Schema->get_schema; + +my $work_rs = $sch->resultset('Work'); +my $pp = $work_rs->find({ title => 'Pride and Prejudice' }); + +while () { + chomp; + $pp->add_to_fictional_characters({ name => $_ }); +} + +__DATA__ +Mr Bennet +Mrs Bennet +Jane Bennet +Mary Bennet +Catherine Bennet +Lydia Bennet +Charles Bingley +Caroline Bingley +George Wickham +William Collins +Lady Catherine de Bourgh