Skip to content

Commit

Permalink
https://github.com/BjoernKW/Schematic/issues/82
Browse files Browse the repository at this point in the history
  • Loading branch information
BjoernKW committed Sep 23, 2024
1 parent b7c2eba commit 1688f41
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 17 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use **Schematic**, you need to add the following Maven dependency to your pro
<dependency>
<groupId>com.bjoernkw</groupId>
<artifactId>schematic</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
</dependency>
```

Expand All @@ -25,13 +25,25 @@ If you're using Spring Boot 2.7.x and Java 11 you can add this version of **Sche
<dependency>
<groupId>com.bjoernkw</groupId>
<artifactId>schematic</artifactId>
<version>0.2.2.jre11</version>
<version>0.2.3.jre11</version>
</dependency>
```

After that, simply restart your Spring Boot application. **Schematic** will be available under http://localhost:8080/schematic/tables
and show the database tables for the database connection configured for your application.

## Configuration Options

In case you need to customise the root path of your application (the default is `/`) or the path
Schematic will run under (the default is `/schematic`), respectively, you can do so by adding the
following properties to your `application.yml` (or `application.properties`) file:

```
schematic:
path: custom-path-for-schematic
root-path: /MyApplication
```

### Screenshots

![Schematic-screenshot-1.png](documentation/static-resources/Schematic-screenshot-1.png)
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml → compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
version: '3.8'
services:
db:
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
- 5432:5432
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/bjoernkw/schematic/IndexController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.bjoernkw.schematic;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
@RequestMapping("/")
public class IndexController {

@Value("${schematic.path}")
private String path;

@GetMapping
public String redirect() {
return "redirect:/schematic/tables";
public String redirect(RedirectAttributes redirectAttributes) {
redirectAttributes.addAttribute("path", path);

return "redirect:/{path}/tables";
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/bjoernkw/schematic/SchematicProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class SchematicProperties {

private String version = getClass().getPackage().getImplementationVersion();

private String path;

private String rootPath;

public String getName() {
return name;
}
Expand All @@ -26,4 +30,20 @@ public String getVersion() {
public void setVersion(String version) {
this.version = version;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public String getRootPath() {
return rootPath;
}

public void setRootPath(String rootPath) {
this.rootPath = rootPath;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/bjoernkw/schematic/TablesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/schematic/tables")
@RequestMapping("/${schematic.path}/tables")
public class TablesController {

private static final Logger LOGGER = LoggerFactory.getLogger(TablesController.class);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
schematic:
name: @project.name@
version: @project.version@
path: schematic
root-path: /

spring:
datasource:
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/fragments/tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h1 class="modal-title fs-5" id="deleteRowsModalLabel">Truncate table "[[${table
<button type="button"
class="btn btn-warning"
data-bs-dismiss="modal"
hx:delete="@{/schematic/tables/{tableName}/truncate(tableName=${table.tableName})}"
hx:delete="@{/{path}/tables/{tableName}/truncate(tableName=${table.tableName},path=${@schematicProperties.path})}"
th:attr="hx-headers='{&quot;' + ${_csrf?.headerName} + '&quot;: &quot;' + ${_csrf?.token} + '&quot;}'"
hx-target="#tables">Yes</button>
</div>
Expand All @@ -104,7 +104,7 @@ <h1 class="modal-title fs-5" id="dropTableModalLabel">Drop table "[[${table.tabl
<button type="button"
class="btn btn-danger"
data-bs-dismiss="modal"
hx:delete="@{/schematic/tables/{tableName}(tableName=${table.tableName})}"
hx:delete="@{/{path}/tables/{tableName}(tableName=${table.tableName},path=${@schematicProperties.path})}"
th:attr="hx-headers='{&quot;' + ${_csrf?.headerName} + '&quot;: &quot;' + ${_csrf?.token} + '&quot;}'"
hx-target="#tables">Yes</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>
<div id="collapsible_query_database"
class="collapse show">
<div class="col-12 mb-4 p-4 border bg-success bg-opacity-10">
<form hx:get="@{/schematic/tables}"
<form hx:get="@{/{path}/tables(path=${@schematicProperties.path})}"
hx-target="#tables">
<div class="mb-3">
<label for="sqlQuery" class="form-label">SQL query</label>
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/templates/layouts/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta name="theme-color" content="#37b73b">

<link rel="icon" th:href="@{/images/favicon.png}">
<link rel="icon" th:href="@{{rootPath}images/favicon.png(rootPath=${@schematicProperties.rootPath})}">

<link rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}">
<link rel="stylesheet" th:href="@{/webjars/font-awesome/6.5.2/css/all.css}">
<link rel="stylesheet" th:href="@{/css/styles.css}">
<link rel="stylesheet" th:href="@{{rootPath}webjars/bootstrap/css/bootstrap.min.css(rootPath=${@schematicProperties.rootPath})}">
<link rel="stylesheet" th:href="@{{rootPath}webjars/font-awesome/6.5.2/css/all.css(rootPath=${@schematicProperties.rootPath})}">
<link rel="stylesheet" th:href="@{{rootPath}css/styles.css(rootPath=${@schematicProperties.rootPath})}">

<script th:src="@{/webjars/popper.js/umd/popper.min.js}"></script>
<script th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
<script th:src="@{/webjars/htmx.org/dist/htmx.min.js}"></script>
<script th:src="@{{rootPath}webjars/popper.js/umd/popper.min.js(rootPath=${@schematicProperties.rootPath})}"></script>
<script th:src="@{{rootPath}webjars/bootstrap/js/bootstrap.min.js(rootPath=${@schematicProperties.rootPath})}"></script>
<script th:src="@{{rootPath}webjars/htmx.org/dist/htmx.min.js(rootPath=${@schematicProperties.rootPath})}"></script>
</head>
<body>
<div>
Expand Down

0 comments on commit 1688f41

Please sign in to comment.