Commit ae1e5536 authored by Max Dor's avatar Max Dor 💬

Meh at in-jar-resources

parent 72df9230
......@@ -21,6 +21,98 @@ And quit the prompt with:
\q
```
Go back in into the Database you created using the password provided above:
```
psql -h localhost --user gridepo gridepo
```
and create the initial schema:
```
CREATE TABLE channels
(
sid bigserial NOT NULL,
id text NOT NULL,
network text NOT NULL,
CONSTRAINT c_ids UNIQUE (id, network)
);
CREATE INDEX c_id_idx
ON channels USING hash(id);
CREATE INDEX c_net_idx
ON channels USING hash(network);
CREATE TABLE channel_events
(
lid bigserial NOT NULL,
cSid bigint NOT NULL,
id text NOT NULL,
meta jsonb NOT NULL,
data jsonb,
CONSTRAINT c_ev_gid UNIQUE(id,cSid)
);
CREATE INDEX c_ev_id_idx
ON channel_events USING hash(id);
CREATE INDEX c_ev_cid_idx
ON channel_events USING hash(cSid);
CREATE TABLE channel_states
(
sid bigserial NOT NULL,
cSid bigint NOT NULL
);
CREATE TABLE channel_state_data
(
sSid bigint NOT NULL,
eLid bigint NOT NULL
);
CREATE TABLE channel_event_states
(
eLid bigint NOT NULL,
sSid bigint NOT NULL
);
CREATE TABLE channel_event_stream
(
sid bigserial NOT NULL,
eLid bigint NOT NULL
);
CREATE TABLE channel_extremities
(
cSid bigint NOT NULL,
eLid bigint NOT NULL
);
CREATE TABLE channel_addresses
(
cAlias text NOT NULL,
cId text NOT NULL,
srvId text NOT NULL,
auto boolean NOT NULL,
CONSTRAINT c_adr_alias UNIQUE(cAlias)
);
CREATE TABLE users
(
lid bigserial NOT NULL,
username text NOT NULL,
password text,
CONSTRAINT u_username UNIQUE (username)
);
CREATE INDEX u_lid_idx
ON users USING hash(lid);
CREATE INDEX u_username_idx
ON users USING hash(username);
CREATE TABLE user_access_tokens
(
uLid bigint NOT NULL,
token text NOT NULL,
CONSTRAINT u_token UNIQUE (token)
);
```
And once again, quit with `\q`
In your `gridepo.yaml` config file (if needed, so your install instruction), assuming a local DB:
```yaml
storage:
......
......@@ -32,10 +32,11 @@ storage:
#
# This is where the events, channels and overall protocol messages are stored.
# Database can only be PostgreSQL at this time.
# Database can only be PostgreSQL at this time for persistent storage.
#
# The connection value is a partial JDBC URI that starts after jdbc:postgresql:
# Typical format is: //host/db?user=userForDb&pass=passForDb
#
database:
type: 'postgresql'
connection: ''
......@@ -82,7 +82,7 @@ public class PostgreSQLStore implements Store {
withConnConsumer(conn -> conn.isValid(1000));
log.info("Connected");
try (InputStream is = getClass().getClassLoader().getResourceAsStream("store/postgres/schema/")) {
try (InputStream is = PostgreSQLStore.class.getResourceAsStream("/store/postgres/schema/")) {
List<String> schemaUpdates = IOUtils.readLines(Objects.requireNonNull(is), StandardCharsets.UTF_8);
withConnConsumer(conn -> {
Statement stmt = conn.createStatement();
......@@ -91,8 +91,9 @@ public class PostgreSQLStore implements Store {
long version = getSchemaVersion();
log.info("Schema version: {}", version);
log.info("Schemas to check: {}", schemaUpdates.size());
for (String sql : schemaUpdates) {
log.debug("Found schema update: {}", sql);
log.info("Processing schema update: {}", sql);
String[] els = sql.split("-", 2);
if (els.length < 2) {
log.warn("Skipping invalid schema update name format: {}", sql);
......@@ -100,20 +101,23 @@ public class PostgreSQLStore implements Store {
try {
long elV = Long.parseLong(els[0]);
if (elV > version) {
try (InputStream elIs = getClass().getClassLoader().getResourceAsStream("store/postgres/schema/" + sql)) {
String update = IOUtils.toString(Objects.requireNonNull(elIs), StandardCharsets.UTF_8);
stmt.execute(update);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (stmt.executeUpdate("INSERT INTO schema (version) VALUES (" + elV + ")") != 1) {
throw new RuntimeException("Could not update schema version");
}
log.info("Updated schema to version {}", elV);
if (elV <= version) {
log.info("Skipping {}", sql);
continue;
}
try (InputStream elIs = PostgreSQLStore.class.getResourceAsStream("/store/postgres/schema/" + sql)) {
String update = IOUtils.toString(Objects.requireNonNull(elIs), StandardCharsets.UTF_8);
stmt.execute(update);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (stmt.executeUpdate("INSERT INTO schema (version) VALUES (" + elV + ")") != 1) {
throw new RuntimeException("Could not update schema version");
}
log.info("Updated schema to version {}", elV);
} catch (NumberFormatException e) {
log.warn("Invalid schema update version: {}", els[0]);
}
......
......@@ -3,3 +3,4 @@ org.slf4j.simpleLogger.log.com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
org.slf4j.simpleLogger.log.com.mchange.v2.c3p0.C3P0Registry=warn
org.slf4j.simpleLogger.log.org.xnio=warn
org.slf4j.simpleLogger.log.g=debug
org.slf4j.simpleLogger.log.io.kamax.grid.gridepo=debug
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment