Skip to content
Browse files

Added database setup script and updated installation instructions

  • Loading branch information...
1 parent 335bc6b commit 0afd3edefd4fff0931081b544adb55fe582395f8 felicitus committed Sep 15, 2010
Showing with 107 additions and 2 deletions.
  1. +6 −2 documentation/QUICK-INSTALL
  2. +101 −0 testing/SetupDatabase.php
View
8 documentation/QUICK-INSTALL
@@ -43,8 +43,12 @@ Install the database and test data
Create the user partdb2, password partdb2 with access to the partdb2 database
in mysql (e.g. with phpmyadmin).
-Then you need to execute the file testing/UserTest.php - this creates the
-schema. If you add new objects (=new tables), you need to add them there also.
+Then execute the file testing/SetupDatabase.php from the command line.
+Command line is important because you need to enter "YES" to confirm
+the operation.
+
+
+If you add new objects (=new tables), you need to add them there also.
I know, it's ugly, but will change soon.
View
101 testing/SetupDatabase.php
@@ -0,0 +1,101 @@
+<?php
+namespace de\RaumZeitLabor\PartDB2\Tests;
+declare(encoding = 'UTF-8');
+
+include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php");
+
+use de\RaumZeitLabor\PartDB2\Auth\User;
+use de\RaumZeitLabor\PartDB2\Footprint\Footprint;
+use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager;
+use de\RaumZeitLabor\PartDB2\PartDB2;
+
+use de\RaumZeitLabor\PartDB2\Category\Category;
+use de\RaumZeitLabor\PartDB2\Category\CategoryManager;
+use de\RaumZeitLabor\PartDB2\Category\CategoryManagerService;
+
+PartDB2::initialize();
+
+
+echo "=)))==========================================\n";
+echo "Actions performed by this script:\n";
+echo "* Drop the old database INCLUDING ALL DATA\n";
+echo "* Creates the schema\n";
+echo "* Creates a test user (username/password test)\n";
+echo "* Add sample footprint data\n";
+echo "=)))==========================================\n";
+echo "\n\n";
+echo "If you are sure you want to do this, type YES and hit return.\n";
+
+$fp = fopen('php://stdin', 'r');
+$data = fgets($fp, 1024);
+
+if ($data !== "YES\n") {
+ echo "Aborting.\n";
+ die();
+}
+
+echo "Performing actions...\n";
+
+$tool = new \Doctrine\ORM\Tools\SchemaTool(PartDB2::getEM());
+$classes = array(
+ PartDB2::getEM()->getClassMetadata('de\RaumZeitLabor\PartDB2\Auth\User'),
+ PartDB2::getEM()->getClassMetadata('de\RaumZeitLabor\PartDB2\Session\Session'),
+ PartDB2::getEM()->getClassMetadata('de\RaumZeitLabor\PartDB2\Footprint\Footprint'),
+ PartDB2::getEM()->getClassMetadata('de\RaumZeitLabor\PartDB2\Category\Category')
+);
+$tool->dropSchema($classes);
+$tool->createSchema($classes);
+
+/* Create initial test user */
+$user = new User();
+$user->setUsername("test");
+$user->setPassword("test");
+
+PartDB2::getEM()->persist($user);
+
+/* Create footprints */
+$footprints = array(
+ array('id'=>1,'name'=>'TO220'),
+ array('id'=>2,'name'=>'TO220-3'),
+ array('id'=>3,'name'=>'TO92-3'),
+ array('id'=>4,'name'=>'RM2,5'),
+ array('id'=>5,'name'=>'RM5'),
+ array('id'=>6,'name'=>'RM7,5'),
+ array('id'=>7,'name'=>'RM10'),
+ array('id'=>8,'name'=>'ohne'),
+ array('id'=>9,'name'=>'TO220-7'),
+ array('id'=>10,'name'=>'TO3-3'),
+ array('id'=>11,'name'=>'TO3-4'),
+ array('id'=>12,'name'=>'DIP8'),
+ array('id'=>13,'name'=>'DIP14'),
+ array('id'=>14,'name'=>'DIP16'),
+ array('id'=>15,'name'=>'DIP18'),
+ array('id'=>16,'name'=>'DIP20'),
+ array('id'=>17,'name'=>'DIP6'),
+ array('id'=>18,'name'=>'TO92-3'),
+ array('id'=>19,'name'=>'TO39'),
+ array('id'=>20,'name'=>'TO18'),
+ array('id'=>21,'name'=>'TO126'),
+ array('id'=>22,'name'=>'TO18'),
+ array('id'=>23,'name'=>'DIP28'),
+ array('id'=>24,'name'=>'SOP28'),
+ array('id'=>25,'name'=>'SOIC20'),
+ array('id'=>26,'name'=>'P-DSO-20'),
+ array('id'=>27,'name'=>'SOIC16'),
+ array('id'=>28,'name'=>'SOIC14'),
+ array('id'=>29,'name'=>'P-SOJ-20')
+);
+
+foreach ($footprints as $sFootprint) {
+ $footprint = new Footprint();
+ $footprint->setFootprint($sFootprint["name"]);
+
+ PartDB2::getEM()->persist($footprint);
+
+}
+
+PartDB2::getEM()->flush();
+
+echo "All done.\n";
+
+?>

0 comments on commit 0afd3ed

Please sign in to comment.
Something went wrong with that request. Please try again.