Skip to content

Commit

Permalink
RHINENG-10439: store environment id for template
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMraka committed May 31, 2024
1 parent 734844e commit e45d036
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
15 changes: 8 additions & 7 deletions base/mqueue/template_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
// adds too many dependencies and some are incompatible
type TemplateResponse struct {
UUID string `json:"uuid" readonly:"true"`
Name string `json:"name"` // Name of the template
OrgID string `json:"org_id"` // Organization ID of the owner
Description *string `json:"description"` // Description of the template
Arch string `json:"arch"` // Architecture of the template
Version string `json:"version"` // Version of the template
Date time.Time `json:"date"` // Latest date to include snapshots for
RepositoryUUIDS []string `json:"repository_uuids"` // Repositories added to the template
Name string `json:"name"` // Name of the template
OrgID string `json:"org_id"` // Organization ID of the owner
Description *string `json:"description"` // Description of the template
Arch string `json:"arch"` // Architecture of the template
Version string `json:"version"` // Version of the template
Date time.Time `json:"date"` // Latest date to include snapshots for
RepositoryUUIDS []string `json:"repository_uuids"` // Repositories added to the template
EnvironmentID string `json:"client_environment_id"` // Environment ID used by subscription-manager & candlepin
}

type TemplateEvent struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE template DROP COLUMN IF EXISTS environment_id;
5 changes: 5 additions & 0 deletions database_admin/migrations/126_template_environment.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE template ADD COLUMN IF NOT EXISTS environment_id TEXT CHECK (NOT empty(environment_id));

UPDATE template set environment_id = REPLACE(uuid::text, '-', '');

ALTER TABLE template ALTER COLUMN environment_id SET NOT NULL;
3 changes: 2 additions & 1 deletion database_admin/schema/create_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations


INSERT INTO schema_migrations
VALUES (125, false);
VALUES (126, false);

-- ---------------------------------------------------------------------------
-- Functions
Expand Down Expand Up @@ -692,6 +692,7 @@ CREATE TABLE IF NOT EXISTS template
creator TEXT CHECK (NOT empty(creator)),
published TIMESTAMP WITH TIME ZONE,
last_edited TIMESTAMP WITH TIME ZONE,
environment_id TEXT NOT NULL CHECK (not empty(environment_id)),
PRIMARY KEY (rh_account_id, id),
UNIQUE(rh_account_id, uuid)
) PARTITION BY HASH (rh_account_id);
Expand Down
10 changes: 5 additions & 5 deletions dev/test_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ INSERT INTO baseline (id, rh_account_id, name, config, description) VALUES
(3, 1, 'baseline_1-3', '{"to_time": "2000-01-01T00:00:00+00:00"}', NULL),
(4, 3, 'baseline_3-4', '{"to_time": "2000-01-01T00:00:00+00:00"}', NULL);

INSERT INTO template (id, rh_account_id, uuid, name, description, config, creator) VALUES
(1, 1, '99900000-0000-0000-0000-000000000001', 'temp1-1', 'desc1', '{"to_time": "2010-09-22T00:00:00+00:00"}', 'user1'),
(2, 1, '99900000-0000-0000-0000-000000000002', 'temp2-1', 'desc2', '{"to_time": "2021-01-01T00:00:00+00:00"}', 'user2'),
(3, 1, '99900000-0000-0000-0000-000000000003', 'temp3-1', NULL, '{"to_time": "2000-01-01T00:00:00+00:00"}', 'user3'),
(4, 3, '99900000-0000-0000-0000-000000000004', 'temp4-3', 'desc4', '{"to_time": "2000-01-01T00:00:00+00:00"}', 'user4');
INSERT INTO template (id, rh_account_id, uuid, environment_id, name, description, config, creator) VALUES
(1, 1, '99900000-0000-0000-0000-000000000001', '99900000000000000000000000000001', 'temp1-1', 'desc1', '{"to_time": "2010-09-22T00:00:00+00:00"}', 'user1'),
(2, 1, '99900000-0000-0000-0000-000000000002', '99900000000000000000000000000002', 'temp2-1', 'desc2', '{"to_time": "2021-01-01T00:00:00+00:00"}', 'user2'),
(3, 1, '99900000-0000-0000-0000-000000000003', '99900000000000000000000000000003', 'temp3-1', NULL, '{"to_time": "2000-01-01T00:00:00+00:00"}', 'user3'),
(4, 3, '99900000-0000-0000-0000-000000000004', '99900000000000000000000000000004', 'temp4-3', 'desc4', '{"to_time": "2000-01-01T00:00:00+00:00"}', 'user4');

INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, reporter_id, vmaas_json, json_checksum, last_evaluation, last_upload, packages_installed, packages_installable, packages_applicable, third_party, baseline_id, baseline_uptodate, template_id) VALUES
(1, '00000000-0000-0000-0000-000000000001','00000000-0000-0000-0000-000000000001', 1, 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-22 12:00:00-04', '2020-09-22 12:00:00-04',0,0,0, true, 1, true, 1),
Expand Down

0 comments on commit e45d036

Please sign in to comment.