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 Jun 5, 2024
1 parent fb33f1a commit 50c0a1d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
9 changes: 5 additions & 4 deletions base/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ func (Baseline) TableName() string {
}

type Template struct {
ID int64 `gorm:"primaryKey"`
RhAccountID int `gorm:"primaryKey"`
UUID string
Name string
ID int64 `gorm:"primaryKey"`
RhAccountID int `gorm:"primaryKey"`
UUID string
EnvironmentID string
Name string
// Config pgtype.JSONB // currently unused
Description *string
Creator *string // pointer for compatibility with previous API versions
Expand Down
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
9 changes: 5 additions & 4 deletions listener/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,18 @@ func TemplateUpdate(template mqueue.TemplateResponse) error {
}

row := models.Template{
RhAccountID: accountID,
UUID: template.UUID,
Name: template.Name,
RhAccountID: accountID,
UUID: template.UUID,
EnvironmentID: template.EnvironmentID,
Name: template.Name,
//Config: nil,
Description: template.Description,
Creator: nil,
Published: &template.Date,
}

err = database.OnConflictUpdateMulti(database.DB, []string{"rh_account_id", "uuid"},
"name", "description", "creator", "published").Save(&row).Error
"name", "environment_id", "description", "creator", "published").Save(&row).Error
if err != nil {
return errors.Wrap(err, "creating template from message")
}
Expand Down

0 comments on commit 50c0a1d

Please sign in to comment.