Skip to content

Commit

Permalink
implement database document
Browse files Browse the repository at this point in the history
  • Loading branch information
slu-it committed Sep 3, 2024
1 parent e37542e commit f254000
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,66 @@
package documentation.generators.asciidoc

import documentation.model.Application
import documentation.model.Database
import documentation.model.Database.Table
import documentation.model.Distance.OWNED
import documentation.model.componentName

class DatabasesOverviewGenerator(applications: List<Application>) {

private val ourApplicationsWithDatabases = applications
private val keyEmoji = "\uD83D\uDD11"
private val ourDatabases = applications
.filter { it.distanceFromUs == OWNED }
.filter { it.databases.isNotEmpty() }
.sortedBy { componentName(it.id) }
.flatMap(Application::databases)
.sortedBy(Database::name)

fun asciiDocSource(): String =
buildString {
appendLine(":toc: left")
appendLine(":toclevels: 2")
appendLine(":toclevels: 3")
appendLine()
appendLine("= Databases")
appendLine()
ourApplicationsWithDatabases
.forEach { application ->
ourDatabases
.sortedBy(Database::name)
.forEach { database ->
appendLine("== ${database.name}")
appendLine()
if (database.description != null) {
appendLine(database.description)
appendLine()
}
appendLine("Type: ${database.type}")
appendLine()
database.tables
.sortedBy(Table::name)
.forEach { table ->
appendLine("=== Table: ${table.name}")
appendLine()
if (table.description != null) {
appendLine(table.description)
appendLine()
}
appendLine(".${table.name} columns")
appendLine("[width=100%, cols=\"~,~,~,~,~\"]")
appendLine("|===")
appendLine("|Column |Type |Nullable? |Default Value |Description")
appendLine()
table.columns
.forEach { column ->
if (column.partOfPrimaryKey) {
appendLine("|`$keyEmoji ${column.name}`")
} else {
appendLine("|`${column.name}`")
}
appendLine("|${column.dataType}")
appendLine("|${column.nullable}")
appendLine("|${column.defaultValue ?: ""}")
appendLine("|${column.description ?: ""}")
appendLine()
}
appendLine("|===")
appendLine()
}
}
}
}
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Since such a commit will constitute a relevant change to the `.build` folder, th

== Document Types

=== Databases Overview

This document lists all known databases and their internal structure.

Take a look link:documents/databases.adoc[here].

=== Events Overview

This document lists all known events that are emitted by any of our application's components.
Expand Down
114 changes: 113 additions & 1 deletion documents/databases.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,117 @@
:toc: left
:toclevels: 2
:toclevels: 3

= Databases

== Order Service Database

The database of the Order Service.

Type: PostgreSQL

=== Table: addresses

Stores saved addresses of customers.

.addresses columns
[width=100%, cols="~,~,~,~,~"]
|===
|Column |Type |Nullable? |Default Value |Description

|`🔑 id`
|uuid
|false
|
|The unique ID of this address.

|`customer_id`
|uuid
|false
|
|The unique ID of the customer this address belongs to.

|`name`
|text
|true
|
|The name of the customer used for this address.

|`street`
|text
|true
|
|The name of the street incl. house numbers and other additions.

|`city`
|text
|true
|
|The name of the city.

|`zip_code`
|text
|true
|
|The ZIP code.

|`country`
|character (2)
|true
|
|A ISO 3166-2 country code.

|===

=== Table: orders

Central table of this service. Stores all orders and their state.

.orders columns
[width=100%, cols="~,~,~,~,~"]
|===
|Column |Type |Nullable? |Default Value |Description

|`🔑 id`
|uuid
|false
|
|The unique ID of this address.

|`customer_id`
|uuid
|false
|
|The unique ID of the customer from the central customer management service.

|`ordered_at`
|timestamp with time zone
|false
|
|The exact point in time when this order was submitted by the customer.

|`dispatched_at`
|timestamp with time zone
|true
|
|

|`billing_address_id`
|uuid
|false
|
|ID of the address used for billing. Foreign key from 'addresses' table.

|`shipping_address_id`
|uuid
|false
|
|ID of the address used for shipping. Foreign key from 'addresses' table.

|`status`
|text
|false
|'OPEN'::text
|The status of the order. Can be 'OPEN', 'PROCESSING', 'DISPATCHED', 'DELIVERED', 'CANCELED' or 'FAILED'

|===

0 comments on commit f254000

Please sign in to comment.