Fix typo and use constants #3541

pull/3542/head
Rafa de la Torre 10 years ago
parent 24eb7cdbf8
commit 0e6aa02db6

@ -2,12 +2,13 @@
class SequenceForAutomatedFeatureFlags < Sequel::Migration
START_SEQ_NUMBER = -1000
NAME = 'machine_added_feature_flags_id_seq'
def up
# Create sequence to avoid trouble generating unique ids
# It starts in negative numbers and goes downward in order to be able to identify quickly flags added automatically
Rails::Sequel.connection.run(%Q{
CREATE SEQUENCE machine_added_feature_flags_id_seq INCREMENT BY -1
CREATE SEQUENCE #{NAME} INCREMENT BY -1
START WITH #{START_SEQ_NUMBER}
OWNED BY feature_flags.id;
})
@ -15,7 +16,7 @@ class SequenceForAutomatedFeatureFlags < Sequel::Migration
def down
Rails::Sequel.connection.run(%Q{
DROP SEQUENCE IF EXISTS machine_added_feature_flags_id_seq;
DROP SEQUENCE IF EXISTS #{NAME}
})
end

@ -17,14 +17,14 @@ class FeatureFlagsForNewDashboard < Sequel::Migration
WITH flags_to_add as (
SELECT * FROM (SELECT unnest(array[#{sql_flag_list}]) as name) as flag EXCEPT (SELECT name from feature_flags)
)
SELECT nextval('machine_added_feature_flags_id_seq'), name, FALSE FROM flags_to_add;
SELECT nextval('#{SequenceForAutomatedFeatureFlags::NAME}'), name, FALSE FROM flags_to_add;
})
end
def down
# Delete automatically-added flags
Rails::Sequel.connection.run(%Q{
DELETE FROM feature_flags WHERE id <= #{START_SEQ_NUMBER} AND name IN (#{sql_flag_list});
DELETE FROM feature_flags WHERE id <= #{SequenceForAutomatedFeatureFlags::START_SEQ_NUMBER} AND name IN (#{sql_flag_list});
})
end

Loading…
Cancel
Save