Skip to content

Register 'default' domain during auto-setup image startup #6619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ RUN apk add --update --no-cache ca-certificates py3-pip mysql-client
RUN pip3 install cqlsh && cqlsh --version

COPY docker/start.sh /start.sh
COPY docker/domain /etc/cadence/domain

CMD /start.sh

Expand Down
55 changes: 55 additions & 0 deletions docker/domain/cassandra.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- Insert into domains table
INSERT INTO domains (
id,
domain
) VALUES (
123e4567-e89b-12d3-a456-426614174000, -- Replace with your UUID
{
id: 123e4567-e89b-12d3-a456-426614174000, -- Replace with your UUID
name: 'default',
status: 0, -- Registered
description: 'This is an example domain.',
data: {'key1': 'value1', 'key2': 'value2'},
owner_email: '[email protected]'
}
) IF NOT EXISTS;

-- Insert into domains_by_name_v2 table
INSERT INTO domains_by_name_v2 (
domains_partition,
name,
domain,
config,
replication_config,
is_global_domain,
config_version,
failover_version,
failover_notification_version,
notification_version
) VALUES (
0,
'default',
{
id: 123e4567-e89b-12d3-a456-426614174000, -- Replace with your UUID
name: 'default',
status: 0, -- Registered
description: 'This is an example domain.',
data: {'key1': 'value1', 'key2': 'value2'},
owner_email: '[email protected]'
},
{
retention: 7,
emit_metric: True,
history_archival_status: 0, -- Default to disabled
visibility_archival_status: 0 -- Default to disabled
},
{
active_cluster_name: 'cluster0',
clusters: [{cluster_name: 'cluster0'}]
},
True, -- is_global_domain
1, -- config_version
0, -- failover_version
0, -- failover_notification_version
0 -- notification_version
) IF NOT EXISTS;
25 changes: 25 additions & 0 deletions docker/domain/mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Insert into domains table
INSERT INTO domains (
shard_id,
id,
name,
data,
data_encoding,
is_global
) VALUES (
54321, -- Default shard_id
UNHEX(REPLACE(UUID(), '-', '')), -- Generate a 16-byte UUID
'default', -- Domain name
'{"key1":"value1","key2":"value2"}', -- Example data as JSON
'json', -- Encoding type
1 -- Set to 1 for a global domain
) ON DUPLICATE KEY UPDATE
name = VALUES(name);

-- Insert into domain_metadata table
INSERT INTO domain_metadata (
notification_version
) VALUES (
1
) ON DUPLICATE KEY UPDATE
notification_version = VALUES(notification_version);
32 changes: 32 additions & 0 deletions docker/domain/postgres.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Insert into domains table
INSERT INTO domains (
shard_id,
id,
name,
data,
data_encoding,
is_global
) VALUES (
54321, -- Default shard_id
gen_random_uuid(), -- Generate a UUID for the domain ID
'default', -- Domain name
'{"key1":"value1","key2":"value2"}', -- Example JSON data
'json', -- Encoding type
TRUE -- Set to TRUE for a global domain
) ON CONFLICT (shard_id, id) DO UPDATE
SET
name = EXCLUDED.name,
data = EXCLUDED.data,
data_encoding = EXCLUDED.data_encoding,
is_global = EXCLUDED.is_global;

-- Insert into domain_metadata table
INSERT INTO domain_metadata (
id,
notification_version
) VALUES (
1, -- Default ID
1 -- Notification version
) ON CONFLICT (id) DO UPDATE
SET
notification_version = EXCLUDED.notification_version;
6 changes: 6 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ setup_cassandra_schema() {
cadence-cassandra-tool --ep $CASSANDRA_SEEDS create -k $VISIBILITY_KEYSPACE --rf $RF
cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $VISIBILITY_KEYSPACE setup-schema -v 0.0
cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $VISIBILITY_KEYSPACE update-schema -d $VISIBILITY_SCHEMA_DIR
echo "Registering domain for Cassandra..."
cqlsh $CASSANDRA_SEEDS -k $KEYSPACE -f /etc/cadence/domain/cassandra.cql
}

setup_mysql_schema() {
Expand All @@ -46,6 +48,8 @@ setup_mysql_schema() {
cadence-sql-tool --ep $MYSQL_SEEDS -u $MYSQL_USER --pw $MYSQL_PWD $CONNECT_ATTR create --db $VISIBILITY_DBNAME
cadence-sql-tool --ep $MYSQL_SEEDS -u $MYSQL_USER --pw $MYSQL_PWD --db $VISIBILITY_DBNAME $CONNECT_ATTR setup-schema -v 0.0
cadence-sql-tool --ep $MYSQL_SEEDS -u $MYSQL_USER --pw $MYSQL_PWD --db $VISIBILITY_DBNAME $CONNECT_ATTR update-schema -d $VISIBILITY_SCHEMA_DIR
echo "Registering domain for MySQL..."
mysql -h $MYSQL_HOST -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE < /etc/cadence/domain/mysql.sql
}

setup_postgres_schema() {
Expand All @@ -57,6 +61,8 @@ setup_postgres_schema() {
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw "$POSTGRES_PWD" -p $DB_PORT create --db $VISIBILITY_DBNAME
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw "$POSTGRES_PWD" -p $DB_PORT --db $VISIBILITY_DBNAME setup-schema -v 0.0
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw "$POSTGRES_PWD" -p $DB_PORT --db $VISIBILITY_DBNAME update-schema -d $VISIBILITY_SCHEMA_DIR
echo "Registering domain for PostgreSQL..."
PGPASSWORD=$POSTGRES_PASSWORD psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DATABASE -f /etc/cadence/domain/postgres.sql
}


Expand Down