|
package ocpmigrations
import (
"database/sql"
"github.com/RedHatInsights/insights-results-aggregator/migration"
"github.com/RedHatInsights/insights-results-aggregator/types"
)
var mig0014ModifyClusterRuleToggleAlter = migration . Migration {
StepUp : func ( tx * sql . Tx , _ types . DBDriver ) error {
_ , err := tx . Exec ( `
ALTER TABLE cluster_rule_toggle DROP CONSTRAINT cluster_rule_toggle_pkey,
ADD CONSTRAINT cluster_rule_toggle_pkey PRIMARY KEY (cluster_id, rule_id);
ALTER TABLE cluster_rule_toggle ALTER COLUMN user_id DROP NOT NULL;
` )
return err
} ,
StepDown : func ( tx * sql . Tx , _ types . DBDriver ) error {
_ , err := tx . Exec ( `
ALTER TABLE cluster_rule_toggle DROP CONSTRAINT cluster_rule_toggle_pkey,
ADD CONSTRAINT cluster_rule_toggle_pkey PRIMARY KEY (cluster_id, rule_id, user_id);
ALTER TABLE cluster_rule_toggle ALTER COLUMN user_id SET NOT NULL;
` )
return err
} ,
}
var mig0014ModifyClusterRuleToggleGeneral = migration . NewUpdateTableMigration (
clusterRuleToggleTable ,
`
CREATE TABLE cluster_rule_toggle (
cluster_id VARCHAR NOT NULL,
rule_id VARCHAR NOT NULL,
user_id VARCHAR NOT NULL,
disabled SMALLINT NOT NULL,
disabled_at TIMESTAMP NULL,
enabled_at TIMESTAMP NULL,
updated_at TIMESTAMP NOT NULL,
CHECK (disabled >= 0 AND disabled <= 1),
PRIMARY KEY(cluster_id, rule_id, user_id)
);
` ,
nil ,
`
CREATE TABLE cluster_rule_toggle (
cluster_id VARCHAR NOT NULL,
rule_id VARCHAR NOT NULL,
user_id VARCHAR NULL,
disabled SMALLINT NOT NULL,
disabled_at TIMESTAMP NULL,
enabled_at TIMESTAMP NULL,
updated_at TIMESTAMP NOT NULL,
disabled_check SMALLINT CHECK (disabled >= 0 AND disabled <= 1),
PRIMARY KEY(cluster_id, rule_id)
)
` ,
)
var mig0014ModifyClusterRuleToggle = migration . Migration {
StepUp : func ( tx * sql . Tx , driver types . DBDriver ) error {
if driver == types . DBDriverPostgres {
return mig0014ModifyClusterRuleToggleAlter . StepUp ( tx , driver )
}
return mig0014ModifyClusterRuleToggleGeneral . StepUp ( tx , driver )
} ,
StepDown : func ( tx * sql . Tx , driver types . DBDriver ) error {
if driver == types . DBDriverPostgres {
return mig0014ModifyClusterRuleToggleAlter . StepDown ( tx , driver )
}
return mig0014ModifyClusterRuleToggleGeneral . StepDown ( tx , driver )
} ,
}
|