done
This commit is contained in:
parent
c43ac6a884
commit
89d3e142a0
175
README.md
175
README.md
|
@ -0,0 +1,175 @@
|
||||||
|
# M141 LB 3 T.B
|
||||||
|
|
||||||
|
# Platform
|
||||||
|
To avoid confusion and potential hickups in the future I've mentioned what system this was done on incase it does not work on other ones.
|
||||||
|
|
||||||
|
- OS : MacOS Sonoma 14.4.1
|
||||||
|
- Shell : ZSH 5.9 Apple Darwin
|
||||||
|
- MariaDB : 11.4.2-MariaDB Homebrew
|
||||||
|
|
||||||
|
Additional installated
|
||||||
|
|
||||||
|
# Note
|
||||||
|
All steps done in folder : work_dir
|
||||||
|
|
||||||
|
# LB3
|
||||||
|
|
||||||
|
## Importing the files
|
||||||
|
Note : Make sure that you have Adminstrative Permissions for the MariaDB server
|
||||||
|
|
||||||
|
### Importing the SQL file
|
||||||
|
|
||||||
|
1. Geting the SQL file that is to be imported
|
||||||
|
```bash
|
||||||
|
curl -O https://gitlab.com/ch-tbz-it/Stud/m141/m141/-/raw/main/LB3-Praxisarbeit/backpacker_ddl_lb3.sql
|
||||||
|
```
|
||||||
|
2. Log into MariaDB
|
||||||
|
```bash
|
||||||
|
mysql #my user is set to be an administrator for mariadb
|
||||||
|
```
|
||||||
|
3. Make new Databse
|
||||||
|
```sql
|
||||||
|
CREATE DATABASE IF NOT EXISTs backpacker_lb3;
|
||||||
|
```
|
||||||
|
4. MariaDB Verlassen
|
||||||
|
```sql
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
5. Datenbank Importieren
|
||||||
|
```bash
|
||||||
|
mysql backpacker_lb3 < backpacker_ddl_lb3.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
### Importing the CSV file
|
||||||
|
|
||||||
|
1. Getting the CSV files to be imported, unzipping it, delete the MacOS metadata folder and the nolonger neeeded zip file then "rename" the folder to csv.
|
||||||
|
```bash
|
||||||
|
curl -O https://gitlab.com/ch-tbz-it/Stud/m141/m141/-/raw/main/LB3-Praxisarbeit/backpacker_lb3.csv.zip; unzip backpacker_lb3.csv.zip; rm -rf __MACOSX; rm backpacker_lb3.csv.zip; mv backpacker_lb3.csv csv
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Get the current working directory and copy it to the clipboard
|
||||||
|
```bash
|
||||||
|
pwd
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Log into MariaDB
|
||||||
|
```bash
|
||||||
|
mysql
|
||||||
|
```
|
||||||
|
4. Change to backpacker database
|
||||||
|
```sql
|
||||||
|
use backpacker_lb3
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Import the CSV files
|
||||||
|
Note : I've already looked at the csv's and the tables existing hence why I've added rules to the default import to avoid any issues from accuring
|
||||||
|
Keep in mind this command has to be run for each table/csv!
|
||||||
|
```sql
|
||||||
|
load data local infile '/Users/crt/Documents/TBZ/M141/m141-lb3/work_dir/csv/backpacker_lb3_table_tbl_positionen.csv' into table tbl_ppositionen fields terminated by ',' enclosed by '"' lines terminated by '\n' ignore 1 rows;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Making changes to the database
|
||||||
|
From now on it us assumed that were already logged in to MariaDB and have selected the correct database
|
||||||
|
|
||||||
|
### Hashing the Password of the users
|
||||||
|
```sql
|
||||||
|
update tbl_benutzer set Password = MD5(Password);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Changing table names
|
||||||
|
```sql
|
||||||
|
rename table tbl_positionen to tbl_position;
|
||||||
|
rename table tbl_personen to tbl_person;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Changing Attributes
|
||||||
|
```sql
|
||||||
|
alter table tbl_buchung change column Buchungs_ID Buchung_ID INT;
|
||||||
|
alter table tbl_buchung change column Personen_FS Person_FS INT;
|
||||||
|
alter table tbl_person change column Personen_ID Person_ID INT;
|
||||||
|
alter table tbl_position change column Positions_ID Position_ID INT;
|
||||||
|
alter table tbl_position change column Buchungs_FS Buchung_FS INT;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding Indexes
|
||||||
|
```sql
|
||||||
|
alter table tbl_buchung add index idx_Person_FS (Person_FS);
|
||||||
|
alter table tbl_buchung add index idx_Land_FS (Land_FS);
|
||||||
|
alter table tbl_position add index idx_Buchung_FS (Buchung_FS);
|
||||||
|
alter table tbl_position add index idx_Benutzer_FS (Benutzer_FS);
|
||||||
|
alter table tbl_position add index idx_Leistung_FS (Leistung_FS);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding Indexing to frequently used Columns
|
||||||
|
```sql
|
||||||
|
alter table tbl_benutzer add index idx_Benutzername (Benutzername);
|
||||||
|
alter table tbl_benutzer add index idx_aktiv (aktiv);
|
||||||
|
alter table tbl_buchung add index idx_Ankunft (Ankunft);
|
||||||
|
alter table tbl_buchung add index idx_Abreise (Abreise);
|
||||||
|
alter table tbl_person add index idx_Name (Name(20));
|
||||||
|
alter table tbl_position add index idx_erfasst (erfasst);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linking foreign keys
|
||||||
|
|
||||||
|
#### For tbl_buchung
|
||||||
|
```sql
|
||||||
|
alter table tbl_buchung add constraint fk_person_buchung foreign key (Person_FS) references tbl_person (Person_ID);
|
||||||
|
alter table tbl_buchung add constraint fk_land_buchung foreign key (Land_FS) references tbl_land (Land_ID);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### For tbl_position
|
||||||
|
```sql
|
||||||
|
alter table tbl_position add constraint fk_buchung_position foreign key (Buchung_FS) references tbl_buchung (Buchung_ID);
|
||||||
|
alter table tbl_position add constraint fk_benutzer_position foreign key (Benutzer_FS) references tbl_benutzer (Benutzer_ID);
|
||||||
|
alter table tbl_position add constraint fk_leistung_position foreign key (Leistung_FS) references tbl_leistung (LeistungID);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Optimizing the Database
|
||||||
|
```sql
|
||||||
|
analyze table tbl_benutzer, tbl_buchung, tbl_land, tbl_leistung, tbl_person, tbl_position;
|
||||||
|
optimize table tbl_benutzer, tbl_buchung, tbl_land, tbl_leistung, tbl_person, tbl_position;
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Making users and managing permissions
|
||||||
|
|
||||||
|
### Create users
|
||||||
|
```sql
|
||||||
|
create user if not exists 'benutzer'@'localhost' identified by 'Example_User_Password123';
|
||||||
|
create user if not exists 'management'@'localhost' identified by 'Example_Mgmt_Password123';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Set "benutzer" Priviliges
|
||||||
|
```sql
|
||||||
|
grant select, update on tbl_person to 'benutzer'@'localhost';
|
||||||
|
grant select, insert, update (Benutzer_ID, Benutzername, Vorname, Name, Benutzergruppe, erfasst, aktiv)
|
||||||
|
on tbl_benutzer to 'benutzer'@'localhost';
|
||||||
|
grant select (deaktiviert) on tbl_benutzer to 'benutzer'@'localhost';
|
||||||
|
grant select, insert, update, delete on tbl_buchung to 'benutzer'@'localhost';
|
||||||
|
grant select, insert, update, delete on tbl_position to 'benutzer'@'localhost';
|
||||||
|
grant select on tbl_land to 'benutzer'@'localhost';
|
||||||
|
grant select on tbl_leistung to 'benutzer'@'localhost';
|
||||||
|
```
|
||||||
|
### Set "management" Priviliges
|
||||||
|
```sql
|
||||||
|
grant select on tbl_position to 'management'@'localhost';
|
||||||
|
grant select on tbl_buchung to 'management'@'localhost';
|
||||||
|
grant select, insert, update, delete on tbl_person to 'management'@'localhost';
|
||||||
|
grant select, insert, update, delete on tbl_benutzer to 'management'@'localhost';
|
||||||
|
grant select, insert, update, delete on tbl_land to 'management'@'localhost';
|
||||||
|
grant select, insert, update, delete on tbl_leistung to 'management'@'localhost';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reload priviliges
|
||||||
|
```sql
|
||||||
|
flush privileges;
|
||||||
|
```
|
||||||
|
|
||||||
|
# Were done! All requirements are fullfilled!
|
||||||
|
A dump of the ddatabase can be found in this directory : t.b.lb3.sql
|
||||||
|
(Done with : mysqldump backpacker_lb3 > t.b.lb3.sql
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,109 @@
|
||||||
|
-- phpMyAdmin SQL Dump
|
||||||
|
-- version 2.9.1.1
|
||||||
|
-- http://www.phpmyadmin.net
|
||||||
|
--
|
||||||
|
-- Host: localhost
|
||||||
|
-- Erstellungszeit: 09. März 2008 um 21:56
|
||||||
|
-- Server Version: 5.0.27
|
||||||
|
-- PHP-Version: 5.2.0
|
||||||
|
--
|
||||||
|
-- Datenbank: `backpacker_lb3`
|
||||||
|
--
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Tabellenstruktur für Tabelle `tbl_benutzer`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tbl_benutzer` (
|
||||||
|
`Benutzer_ID` int(11) NOT NULL auto_increment,
|
||||||
|
`Benutzername` varchar(20) collate latin1_general_ci NOT NULL default '',
|
||||||
|
`Password` text collate latin1_general_ci,
|
||||||
|
`Vorname` varchar(20) collate latin1_general_ci default NULL,
|
||||||
|
`Name` text collate latin1_general_ci,
|
||||||
|
`Benutzergruppe` tinyint(4) default '1',
|
||||||
|
`erfasst` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
||||||
|
`deaktiviert` date default '1000-01-01',
|
||||||
|
`aktiv` tinyint(4) default '1',
|
||||||
|
PRIMARY KEY (`Benutzer_ID`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci COMMENT='Mitarbeiter' AUTO_INCREMENT=28 ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Tabellenstruktur für Tabelle `tbl_buchung`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tbl_buchung` (
|
||||||
|
`Buchungs_ID` int(11) NOT NULL auto_increment,
|
||||||
|
`Personen_FS` int(11) default NULL,
|
||||||
|
`Ankunft` datetime default NULL,
|
||||||
|
`Abreise` datetime default NULL,
|
||||||
|
`Land_FS` int(11) default NULL,
|
||||||
|
PRIMARY KEY (`Buchungs_ID`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci COMMENT='Buchungszeilen' AUTO_INCREMENT=1087 ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Tabellenstruktur für Tabelle `tbl_land`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tbl_land` (
|
||||||
|
`Land_ID` int(11) NOT NULL default '0',
|
||||||
|
`Land` text collate latin1_general_ci NOT NULL
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci COMMENT='enthält die Ländercodes';
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Tabellenstruktur für Tabelle `tbl_leistung`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tbl_leistung` (
|
||||||
|
`LeistungID` int(11) NOT NULL default '0',
|
||||||
|
`Beschreibung` varchar(70) collate latin1_general_ci default NULL,
|
||||||
|
PRIMARY KEY (`LeistungID`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Tabellenstruktur für Tabelle `tbl_personen`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tbl_personen` (
|
||||||
|
`Personen_ID` int(11) NOT NULL auto_increment,
|
||||||
|
`Titel` text collate latin1_general_ci,
|
||||||
|
`Vorname` text collate latin1_general_ci,
|
||||||
|
`Name` text collate latin1_general_ci,
|
||||||
|
`Strasse` text collate latin1_general_ci,
|
||||||
|
`PLZ` text collate latin1_general_ci,
|
||||||
|
`Ort` text collate latin1_general_ci,
|
||||||
|
`Anrede` text collate latin1_general_ci,
|
||||||
|
`Telefon` text collate latin1_general_ci,
|
||||||
|
`erfasst` datetime default NULL,
|
||||||
|
`Sprache` text collate latin1_general_ci,
|
||||||
|
PRIMARY KEY (`Personen_ID`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci COMMENT='enth<EFBFBD>lt alle G<>ste' AUTO_INCREMENT=2042 ;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Tabellenstruktur für Tabelle `tbl_positionen`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tbl_positionen` (
|
||||||
|
`Positions_ID` int(11) NOT NULL auto_increment,
|
||||||
|
`Buchungs_FS` int(11) default NULL,
|
||||||
|
`Konto` int(11) NOT NULL default '0',
|
||||||
|
`Anzahl` int(11) NOT NULL default '0',
|
||||||
|
`Preis` decimal(10,2) NOT NULL default '0.00',
|
||||||
|
`Rabatt` decimal(4,2) NOT NULL default '0.00',
|
||||||
|
`Benutzer_FS` int(11) NOT NULL default '0',
|
||||||
|
`erfasst` datetime NOT NULL default '1000-01-01 00:00:00',
|
||||||
|
`Leistung_Text` text collate latin1_general_ci NOT NULL,
|
||||||
|
`Leistung_FS` INT (11),
|
||||||
|
PRIMARY KEY (`Positions_ID`),
|
||||||
|
FULLTEXT KEY `Leistung_Text` (`Leistung_Text`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci COMMENT='enthält einzelne Buchungspositionen' AUTO_INCREMENT=4055 ;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
"Benutzer_ID","Benutzername","Password","Vorname","Name","Benutzergruppe","erfasst","deaktiviert","aktiv"
|
||||||
|
"1","admin","a""s*d$""",NULL,"Administrator","1","2018-02-18 00:00:00","1000-01-01","1"
|
||||||
|
"2","mueller","P%ui&kio99","Heinz","Müller","1","2001-06-01 00:00:00","1000-01-01","1"
|
||||||
|
"3","emueller","esther89","Esther","Müller","2","2023-12-01 00:00:00","2001-12-01","0"
|
||||||
|
"7","sauber","pink765","Peter","Sauber","2","2019-01-06 00:00:00","1000-01-01","1"
|
||||||
|
"8","niederer","hhh656","Max","Niederer","2","2019-12-15 00:00:00","2001-06-15","0"
|
||||||
|
"11","angst","immer763",NULL,"Angst","2","2004-04-04 14:21:49","1000-01-01","1"
|
||||||
|
"12","reimann","vr653!","Victoria","Reimann","2","2004-03-15 00:00:00","1000-01-01","1"
|
||||||
|
"13","gubler","fritz232$",NULL,"Gubler","1","2004-04-04 14:23:40","1000-01-01","1"
|
||||||
|
"14","burk","P//345OO","Ana","Burkhardt","1","2003-01-01 00:00:00","2004-03-01","0"
|
||||||
|
"25","mueller","mp323!","Peter","Müller","2","2004-04-04 14:12:03","1000-01-01","1"
|
||||||
|
"26","benjang","bj2545::","Benjamin","Angst","1","2004-04-04 14:13:44","1000-01-01","1"
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,86 @@
|
||||||
|
"Land_ID","Land"
|
||||||
|
"1","Schweiz"
|
||||||
|
"99","Liechtenstein"
|
||||||
|
"100","Aegypten"
|
||||||
|
"101","Algerien"
|
||||||
|
"102","Argentinien"
|
||||||
|
"103","Australien/Ozean."
|
||||||
|
"105","Belgien"
|
||||||
|
"106","Brasilien"
|
||||||
|
"107","Bulgarien"
|
||||||
|
"110","Chile"
|
||||||
|
"111","Cypern"
|
||||||
|
"114","Dänemark"
|
||||||
|
"115","Deutschland"
|
||||||
|
"119","England"
|
||||||
|
"122","Finnland"
|
||||||
|
"123","Frankreich"
|
||||||
|
"126","Griechenland"
|
||||||
|
"129","Holland"
|
||||||
|
"130","Honkong"
|
||||||
|
"133","Indien"
|
||||||
|
"134","Iran"
|
||||||
|
"135","Irland"
|
||||||
|
"136","Island"
|
||||||
|
"137","Israel"
|
||||||
|
"138","Italien"
|
||||||
|
"141","Japan"
|
||||||
|
"142","Jugoslawien"
|
||||||
|
"145","Kanada"
|
||||||
|
"146","Kenya"
|
||||||
|
"147","Korea"
|
||||||
|
"150","Libyen"
|
||||||
|
"154","Malaysia"
|
||||||
|
"155","Marokko"
|
||||||
|
"156","Mexiko"
|
||||||
|
"159","Neuseeland"
|
||||||
|
"160","Nordirland"
|
||||||
|
"161","Norwegen"
|
||||||
|
"164","Oesterreich"
|
||||||
|
"167","Pakistan"
|
||||||
|
"168","Peru"
|
||||||
|
"169","Philippinen"
|
||||||
|
"170","Polen"
|
||||||
|
"171","Portugal"
|
||||||
|
"174","Saudi Arabien"
|
||||||
|
"175","Schottland"
|
||||||
|
"178","Spanien"
|
||||||
|
"179","Sri Lanka"
|
||||||
|
"180","Südafrika"
|
||||||
|
"181","Sudan"
|
||||||
|
"182","Syrien"
|
||||||
|
"185","Thailand"
|
||||||
|
"186","Tschechische Republik"
|
||||||
|
"187","Tunesien"
|
||||||
|
"188","Türkei"
|
||||||
|
"191","Ungarn"
|
||||||
|
"192","Uruguay"
|
||||||
|
"193","USA"
|
||||||
|
"194","übriges Afrika"
|
||||||
|
"197","übriges Europa"
|
||||||
|
"198","Schweiz"
|
||||||
|
"199","Militär"
|
||||||
|
"200","Katar"
|
||||||
|
"201","Kolumbien"
|
||||||
|
"202","Luxemburg"
|
||||||
|
"203","Ver.Arab.Emirate"
|
||||||
|
"204","Baltische Staaten"
|
||||||
|
"205","Belarus (Weissrussland)"
|
||||||
|
"206","China (ohne Hongkong)"
|
||||||
|
"207","Indonesion"
|
||||||
|
"209","Kroatien"
|
||||||
|
"210","Liechtenstein"
|
||||||
|
"211","Rumänien"
|
||||||
|
"212","Russische Föderation"
|
||||||
|
"212","Russland"
|
||||||
|
"213","Singapur"
|
||||||
|
"214","Slowakische Republik"
|
||||||
|
"215","Slowenien"
|
||||||
|
"216","Taiwan"
|
||||||
|
"218","Ukraine"
|
||||||
|
"219","übrige Golfstaaten"
|
||||||
|
"220","übriges Mittelamerika, Karibik"
|
||||||
|
"220","übriges Mittelamerika"
|
||||||
|
"221","übriges Süd- und Ostasien"
|
||||||
|
"222","übriges Südamerika"
|
||||||
|
"223","übriges Westasien"
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
"LeistungID","Beschreibung"
|
||||||
|
"1","Zimmerreservation inklusive erste Nacht"
|
||||||
|
"2","Zimmer Folgenacht"
|
||||||
|
"3","Restaurant"
|
||||||
|
"4","Bar"
|
||||||
|
"5","Telefon"
|
||||||
|
"6","Freizeitangebot"
|
||||||
|
"7","Sauna"
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue