From be46e2a5a38932e19232ab4e860301ef4bd70b37 Mon Sep 17 00:00:00 2001 From: Jorge Padilla Date: Mon, 18 Sep 2023 09:12:52 -0600 Subject: [PATCH] fix demos --- server/config/demo/demo_repository.go | 6 ++---- server/migrations/33_add_composite_pkey.down.sql | 13 +++++++++++++ server/migrations/33_add_composite_pkey.up.sql | 12 ++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/server/config/demo/demo_repository.go b/server/config/demo/demo_repository.go index fcee382bb4..9156ac67c7 100644 --- a/server/config/demo/demo_repository.go +++ b/server/config/demo/demo_repository.go @@ -51,17 +51,15 @@ func (r *Repository) Create(ctx context.Context, demo Demo) (Demo, error) { return Demo{}, fmt.Errorf("could not get JSON data from opentelemetry store example: %w", err) } - tenantID := sqlutil.TenantID(ctx) - - _, err = tx.ExecContext(ctx, insertQuery, + params := sqlutil.TenantInsert(ctx, demo.ID, demo.Name, demo.Enabled, demo.Type, pokeshopJSONData, openTelemetryStoreJSONData, - tenantID, ) + _, err = tx.ExecContext(ctx, insertQuery, params...) if err != nil { tx.Rollback() diff --git a/server/migrations/33_add_composite_pkey.down.sql b/server/migrations/33_add_composite_pkey.down.sql index 036b726aed..cf8eb08799 100644 --- a/server/migrations/33_add_composite_pkey.down.sql +++ b/server/migrations/33_add_composite_pkey.down.sql @@ -13,6 +13,19 @@ WHERE tenant_id = ''; ALTER TABLE data_stores ALTER COLUMN tenant_id TYPE uuid using tenant_id::uuid; +ALTER TABLE demos +DROP CONSTRAINT demos_pkey, +ADD PRIMARY KEY (id), +ALTER COLUMN tenant_id DROP DEFAULT, +ALTER COLUMN tenant_id DROP NOT NULL; + +UPDATE demos +SET tenant_id = null +WHERE tenant_id = ''; + +ALTER TABLE demos ALTER COLUMN tenant_id TYPE uuid using tenant_id::uuid; + + ALTER TABLE polling_profiles DROP CONSTRAINT polling_profiles_pkey, ADD PRIMARY KEY (id), diff --git a/server/migrations/33_add_composite_pkey.up.sql b/server/migrations/33_add_composite_pkey.up.sql index d81d5686cf..ecebab6d72 100644 --- a/server/migrations/33_add_composite_pkey.up.sql +++ b/server/migrations/33_add_composite_pkey.up.sql @@ -12,6 +12,18 @@ ADD PRIMARY KEY (id, tenant_id), ALTER COLUMN tenant_id SET DEFAULT ''; +ALTER TABLE demos ALTER COLUMN tenant_id TYPE varchar; + +UPDATE demos +SET tenant_id = '' +WHERE tenant_id is null; + +ALTER TABLE demos +DROP CONSTRAINT demos_pkey, +ADD PRIMARY KEY (id, tenant_id), +ALTER COLUMN tenant_id SET DEFAULT ''; + + ALTER TABLE polling_profiles ALTER COLUMN tenant_id TYPE varchar; UPDATE polling_profiles