Skip to content

Commit

Permalink
Update migration to use ZVIEW and ZTABLE (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrambek authored Dec 18, 2024
1 parent 8b2823a commit 0bf85f8
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class ZillabaseZillaConfig
{
public static final String DEFAULT_ZILLA_TAG = "0.9.105";
public static final String DEFAULT_ZILLA_TAG = "0.9.112";

private static final List<ZillabaseZillaPortConfig> DEFAULT_PORT_LIST = List.of(
new ZillabaseZillaPortConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public final class ZillabaseStartCommand extends ZillabaseDockerCommand
{
private static final int SERVICE_INITIALIZATION_DELAY_MS = 5000;
private static final int MAX_RETRIES = 5;
private static final Pattern TOPIC_PATTERN = Pattern.compile("(^|-|_)(.)");
private static final Pattern TOPIC_PATTERN = Pattern.compile("(\\w+)\\.(\\w+)");
private static final String DEFAULT_KEYCLOAK_ADMIN_CREDENTIAL = "admin";
private static final String ADMIN_REALMS_PATH = "/admin/realms";
private static final String ADMIN_REALMS_CLIENTS_PATH = "/admin/realms/%s/clients";
Expand Down Expand Up @@ -1528,13 +1528,15 @@ private String generateHttpAsyncApiSpecs(
JsonObject channelsJson = jsonValue.asJsonObject().getJsonObject("channels");
for (Map.Entry<String, JsonValue> channelJson : channelsJson.entrySet())
{
String name = channelJson.getKey();
if (name.endsWith("_replies"))
String channelName = channelJson.getKey();
if (channelName.endsWith("_replies"))
{
continue;
}

String label = matcher.reset(name).replaceAll(match -> match.group(2).toUpperCase());
String name = matcher.reset(channelName).replaceFirst(match -> match.group(2));
String label = name.toUpperCase();

if (secure)
{
String scope = label.toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
-- create_tables

CREATE TABLE petstore_pets(
CREATE ZTABLE petstore_pets(
id VARCHAR,
breed VARCHAR,
PRIMARY KEY (id)
);

CREATE TABLE petstore_customers(
CREATE ZTABLE petstore_customers(
name VARCHAR,
status VARCHAR,
PRIMARY KEY (name)
);

CREATE TABLE petstore_verified_customers(
CREATE ZTABLE petstore_verified_customers(
id VARCHAR,
points VARCHAR,
PRIMARY KEY (id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ A Table creates the topic and CRUD APIs to insert and query data.
A Stream creates the topic and CRUD APIs to produce and fetch data.
*/


-- A table to store user data
CREATE TABLE streampay_users(
CREATE ZTABLE streampay_users(
id VARCHAR,
name VARCHAR,
username VARCHAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CREATE STREAM streampay_commands(
zilla_timestamp TIMESTAMP
);

CREATE MATERIALIZED VIEW IF NOT EXISTS streampay_replies AS
CREATE ZVIEW IF NOT EXISTS streampay_replies AS
SELECT '400' AS status, encode(zilla_correlation_id, 'escape') AS correlation_id from streampay_commands where type NOT IN ('SendPayment', 'RequestPayment', 'RejectRequest')
UNION
SELECT '200' AS status, encode(zilla_correlation_id, 'escape') AS correlation_id from streampay_commands where type IN ('SendPayment', 'RequestPayment', 'RejectRequest');
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CREATE VIEW all_user_transactions AS
FROM
user_transactions;

CREATE MATERIALIZED VIEW streampay_balances AS
CREATE ZVIEW streampay_balances AS
SELECT
user_id,
SUM(net_amount) AS balance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- create_activities

CREATE MATERIALIZED VIEW streampay_activities AS
CREATE ZVIEW streampay_activities AS
SELECT
generate_unique_id()::varchar AS id,
'PaymentSent' AS eventName,
Expand Down Expand Up @@ -48,18 +48,3 @@ CREATE MATERIALIZED VIEW streampay_activities AS
LEFT JOIN streampay_users tu ON sc.user_id = tu.id
WHERE
sc.type = 'RequestPayment';
SELECT
generate_unique_id()::varchar AS id,
'PaymentRejected' AS eventName,
encode(sc.zilla_identity, 'escape') AS from_user_id,
fu.username AS from_username,
sc.user_id AS to_user_id,
tu.username AS to_username,
sc.amount,
CAST(extract(epoch FROM sc.zilla_timestamp) AS FLOAT) * 1000 AS timestamp
FROM
streampay_commands sc
LEFT JOIN streampay_users fu ON encode(sc.zilla_identity, 'escape') = fu.id
LEFT JOIN streampay_users tu ON sc.user_id = tu.id
WHERE
sc.type = 'RejectRequest';
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CREATE VIEW status_updates AS
sc.type IN ('SendPayment', 'RejectRequest')
AND (sc.request_id IS NOT NULL AND sc.request_id <> '');

CREATE MATERIALIZED VIEW streampay_payment_requests AS
CREATE ZVIEW streampay_payment_requests AS
SELECT
rp.id,
rp.from_user_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CREATE FUNCTION assess_fraud(varchar, varchar, double precision) RETURNS struct<summary varchar, risk varchar>
LANGUAGE python AS 'assess_fraud';

CREATE MATERIALIZED VIEW streampay_payment_risk_assessment AS
CREATE ZVIEW streampay_payment_risk_assessment AS
SELECT
ar.id,
ar.to_user_id_identity,
Expand Down

0 comments on commit 0bf85f8

Please sign in to comment.