Skip to content

Commit

Permalink
Bootstrap Risingwave zb_catalog (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfallows authored Dec 18, 2024
1 parent b70e965 commit 8b2823a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ protected void invoke(

seedKafkaAndRegistry(config);

processInitSql(config);

processSql(config);

createConfigServerKafkaTopic(config);
Expand Down Expand Up @@ -338,10 +340,33 @@ private void startContainers(
System.out.println("Verified containers are healthy");
}

private void processInitSql(
ZillabaseConfig config)
{
PgsqlHelper pgsql = new PgsqlHelper(config.risingwave, "postgres");

pgsql.connect();

if (pgsql.connected)
{
pgsql.process("<initdb>",
"""
CREATE USER zillabase;
CREATE SCHEMA zb_catalog AUTHORIZATION postgres;
CREATE TABLE zb_catalog.zviews(
name VARCHAR PRIMARY KEY,
sql VARCHAR);
CREATE TABLE zb_catalog.ztables(
name VARCHAR PRIMARY KEY,
sql VARCHAR);
""");
}
}

private void processSql(
ZillabaseConfig config)
{
PgsqlHelper pgsql = new PgsqlHelper(config.risingwave);
PgsqlHelper pgsql = new PgsqlHelper(config.risingwave, "zillabase");

pgsql.connect();

Expand Down Expand Up @@ -2292,7 +2317,6 @@ CreateContainerCmd createContainer(
}
}


private static final class CreateRisingWaveFactory extends CreateContainerFactory
{
CreateRisingWaveFactory(
Expand Down Expand Up @@ -2708,12 +2732,13 @@ private final class PgsqlHelper


PgsqlHelper(
ZillabaseRisingWaveConfig config)
ZillabaseRisingWaveConfig config,
String user)
{
this.config = config;

Properties props = new Properties();
props.setProperty("user", "root");
props.setProperty("user", user);
props.setProperty("preferQueryMode", PreferQueryMode.SIMPLE.value());

this.url = "jdbc:postgresql://localhost:4567/%s".formatted(config.db);
Expand Down Expand Up @@ -2757,11 +2782,11 @@ void process(
String content = readSql(sql);
if (content != null)
{
execute(sql.getFileName().toString(), content);
process(sql.getFileName().toString(), content);
}
}

private void execute(
void process(
String filename,
String content)
{
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<version>3.3.6</version>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-httpclient5</artifactId>
<version>3.3.6</version>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
Expand Down

0 comments on commit 8b2823a

Please sign in to comment.