Michael Hoennig
2022-07-28 306f8d1fa8c70719684db06ded41cc0453fc089b
commit | author | age
b433f9 1 # hsadminNg Development
e0b3d2 2
b433f9 3 ## Setting up the Development Environment
e0b3d2 4
f2d0fb 5 ### PostgreSQL Server
e0b3d2 6
f2d0fb 7 So far the spike contains almost only PostgreSQL Code. 
MH 8 All you need so far, is a PostgreSQL database, for now with full admin rights.
306f8d 9 The easiest way to set it up is using docker.
MH 10
11 (Find the mentioned aliases in `.aliases`.)
e0b3d2 12
f2d0fb 13 Initially, pull an image compatible to current PostgreSQL version of Hostsharing:
d18263 14
f2d0fb 15     docker pull postgres:13.7-bullseye
2fa728 16
306f8d 17 <big>**&#9888;**</big>
MH 18 If we switch the version, please also amend the documentation as well as the aliases file. Thanks! 
19
f2d0fb 20 Create and run a container with the given PostgreSQL version:
e0b3d2 21
f2d0fb 22     docker run --name hsadmin-ng-postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:13.7-bullseye
e0b3d2 23
306f8d 24     # or via alias: 
MH 25     pg-sql-run
26
f2d0fb 27 To check if the PostgreSQL container is running, the following command should list a container with the name "hsadmin-ng-postgres": 
e0b3d2 28
306f8d 29     docker container ls 
e0b3d2 30
f2d0fb 31 Stop the PostgreSQL container:
MH 32     
33     docker stop hsadmin-ng-postgres
306f8d 34     # or via alias: pg-sql-stop
e0b3d2 35
f2d0fb 36 Start the PostgreSQL container again:
e0b3d2 37
f2d0fb 38     docker container start hsadmin-ng-postgres
306f8d 39     # or via alias: pg-sql-start
6efa16 40
f2d0fb 41 Remove the PostgreSQL container:
6efa16 42
f2d0fb 43     docker rm hsadmin-ng-postgres
306f8d 44     
MH 45     # or via alias:
46     pg-sql-remove
47
48 To reset to a clean database, use:
49
50     pg-sql-stop; pg-sql-remove; pg-sql-run
51
52     # or via alias:
53     pg-sql-reset
6efa16 54
f2d0fb 55 After the PostgreSQL container is removed, you need to create it again as shown in "Create and run ..." above.
6efa16 56
e97022 57 Given the container is running, to create a backup in ~/backup, run:
MH 58
306f8d 59     docker exec -i hsadmin-ng-postgres /usr/bin/pg_dump --clean --create -U postgres postgres | gzip -9 > ~/backup/hsadmin-ng-postgres.sql.gz
MH 60
61     # or via alias:
62     pg-sql-backup >~/backup/hsadmin-ng-postgres.sql.gz
e97022 63
MH 64
65 Again, given the container is running, to restore the backup from ~/backup, run:
66
67     gunzip --stdout --keep ~/backup/hsadmin-ng-postgres.sql.gz | docker exec -i hsadmin-ng-postgres psql -U postgres -d postgres
306f8d 68
MH 69     # or via alias:
70     pg-sql-restore <~/backup/hsadmin-ng-postgres.sql.gz
e97022 71
MH 72
f2d0fb 73 ### Markdown with PlantUML plugin
6efa16 74
f2d0fb 75 Can you see the following diagram?
6efa16 76
f2d0fb 77 ```plantuml
MH 78 @startuml
79 me -> you: Can you see this diagram?
80 you -> me: Sorry, I don't :-(
81 me -> you: Install some tooling!
82 @enduml
83 ```
6efa16 84
f2d0fb 85 If not, you need to install some tooling.
6efa16 86
f2d0fb 87 #### for IntelliJ IDEA (or derived products)
6efa16 88
f2d0fb 89 You just need the bundled Markdown plugin enabled and install and activate the PlantUML plugin in its settings:
6efa16 90
f2d0fb 91 jetbrains://idea/settings?name=Languages+%26+Frameworks--Markdown 
6efa16 92
f2d0fb 93 You might also need to install Graphviz on your operating system.
MH 94 For Debian-based Linux systems this might work:
7ba20b 95
f2d0fb 96 ```sh
MH 97 sudo apt install graphviz
98 ```
1284c2 99
MH 100
306f8d 101 #### Ubuntu Linux command line
7ba20b 102
f2d0fb 103 ```sh
MH 104 sudo apt-get install pandoc texlive-latex-base texlive-fonts-recommended texlive-extra-utils texlive-latex-extra pandoc-plantuml-filter
105 ```
7ba20b 106
f2d0fb 107 ```sh
MH 108 pandoc --filter pandoc-plantuml rbac.md -o rbac.pdf
109 ```
7ba20b 110
306f8d 111 #### for other IDEs / operating systems
9a19a6 112
f2d0fb 113 If you have figured out how it works, please add instructions above this section.
306f8d 114
MH 115
116 ## Running the SQL files
117
118 ### For RBAC
119
120 If you run the numbered SQL files from the `sql` folder in the defined order, a working RBAC system is built up in the database including test data and some simple tests.
121
122 To increase the amount of test data, simply increase the number of generated customers in `21-hs-customer.sql`.
123
124 If you already have data, e.g. for customers 0..999 (thus with reference numbers 10000..10999) and want to add another 1000 customers, amend the for loop to 1000...1999 and also uncomment and amend the `CONTINUE WHEN` or `WHERE` conditions in the other test data generators, using the first new customer reference number (in the example that's 11000).
125
126 ### For Historization
127
128 You can explore the historization prototype as follows:
129
130 - start with an empty database
131   (the example tables are currently not compatible with RBAC),
132 - then run `historization.sql,`
133 - finally run `examples.sql`.