Browse Source

implemented creation of wiki tables

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/wiki
Stephan Richter 2 months ago
parent
commit
3b8e7ed258
  1. 1
      frontend/src/Components/Menu.svelte
  2. 5
      wiki/build.gradle.kts
  3. 6
      wiki/src/main/java/de/srsoftware/umbrella/wiki/Constants.java
  4. 46
      wiki/src/main/java/de/srsoftware/umbrella/wiki/SqliteDb.java

1
frontend/src/Components/Menu.svelte

@ -58,6 +58,7 @@ onMount(fetchModules); @@ -58,6 +58,7 @@ onMount(fetchModules);
<a href="#" onclick={() => go('/bookmark')}>{t('bookmarks')}</a>
<a href="#" onclick={() => go('/notes')}>{t('notes')}</a>
<a href="#" onclick={() => go('/time')}>{t('timetracking')}</a>
<a href="#" onclick={() => go('/wiki')}>{t('wiki')}</a>
<a href="https://svelte.dev/tutorial/svelte/state" target="_blank">{t('tutorial')}</a>
{#each modules as module,i}
{#if module.name.trim()}<a href={module.url}>{module.name}</a>{/if}

5
wiki/build.gradle.kts

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
description = "Umbrella : Wiki"
dependencies{
implementation(project(":core"))
}

6
wiki/src/main/java/de/srsoftware/umbrella/wiki/Constants.java

@ -5,4 +5,10 @@ public class Constants { @@ -5,4 +5,10 @@ public class Constants {
private Constants(){}
public static final String CONFIG_DATABASE = "umbrella.modules.wiki.database";
public static final String CONTENT = "content";
public static final String PAGE_ID = "page_id";
public static final String PERMISSIONS = "permissions";
public static final String TABLE_PAGES = "pages";
public static final String TABLE_PAGES_USERS = "pages_users";
public static final String VERSION = "version";
}

46
wiki/src/main/java/de/srsoftware/umbrella/wiki/SqliteDb.java

@ -3,6 +3,22 @@ package de.srsoftware.umbrella.wiki; @@ -3,6 +3,22 @@ package de.srsoftware.umbrella.wiki;
import de.srsoftware.umbrella.core.BaseDb;
import java.sql.Connection;
import java.sql.SQLException;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.DESCRIPTION;
import static de.srsoftware.umbrella.core.Constants.DUE_DATE;
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
import static de.srsoftware.umbrella.core.Constants.EST_TIME;
import static de.srsoftware.umbrella.core.Constants.NAME;
import static de.srsoftware.umbrella.core.Constants.NO_INDEX;
import static de.srsoftware.umbrella.core.Constants.SHOW_CLOSED;
import static de.srsoftware.umbrella.core.Constants.START_DATE;
import static de.srsoftware.umbrella.core.Constants.STATUS;
import static de.srsoftware.umbrella.core.model.Status.OPEN;
import static de.srsoftware.umbrella.wiki.Constants.*;
import static java.lang.System.Logger.Level.ERROR;
import static java.text.MessageFormat.format;
public class SqliteDb extends BaseDb implements WikiDb {
private static final System.Logger LOG = System.getLogger("TaskDb");
@ -16,9 +32,35 @@ public class SqliteDb extends BaseDb implements WikiDb { @@ -16,9 +32,35 @@ public class SqliteDb extends BaseDb implements WikiDb {
protected int createTables() {
int currentVersion = createSettingsTable();
switch (currentVersion){
case 0: ; // TODO
case 0:
createPagesTable();
createPagesUsersTable();
}
return setCurrentVersion(3);
return setCurrentVersion(1);
}
private void createPagesUsersTable() {
var sql = "CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) NOT NULL, {2} INT NOT NULL, {3} INT NOT NULL, PRIMARY KEY({1}, {2}))";
try {
var stmt = db.prepareStatement(format(sql, TABLE_PAGES_USERS, PAGE_ID, USER_ID, PERMISSIONS));
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_PAGES, e);
throw new RuntimeException(e);
}
}
private void createPagesTable() {
var sql = "CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) NOT NULL, {2} INT NOT NULL, {3} TEXT NOT NULL, PRIMARY KEY({1},{2}))";
try {
var stmt = db.prepareStatement(format(sql, TABLE_PAGES, ID, VERSION, CONTENT));
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_PAGES, e);
throw new RuntimeException(e);
}
}
}
Loading…
Cancel
Save