execute "ALTER TABLE #{table_name} ADD PRIMARY KEY USING INDEX #{constraint_name}"
end
-
- def create_enumeration(enumeration_name, values)
- execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
- end
-
- def drop_enumeration(enumeration_name)
- execute "DROP TYPE #{enumeration_name}"
- end
-
- def add_enumeration_value(enumeration_name, value)
- execute "ALTER TYPE #{enumeration_name} ADD VALUE '#{value}'"
- end
-
- def rename_enumeration(old_name, new_name)
- old_name = quote_table_name(old_name)
- new_name = quote_table_name(new_name)
-
- execute "ALTER TYPE #{old_name} RENAME TO #{new_name}"
- end
end
end
end
class AddRelations < ActiveRecord::Migration[4.2]
def self.up
# enums work like strings but are more efficient
- create_enumeration :nwr_enum, %w[Node Way Relation]
+ create_enum :nwr_enum, %w[Node Way Relation]
# a relation can have members much like a way can have nodes.
# differences:
end
def self.up
- create_enumeration :gpx_visibility_enum, %w[private public trackable identifiable]
+ create_enum :gpx_visibility_enum, %w[private public trackable identifiable]
add_column :gpx_files, :visibility, :gpx_visibility_enum, :default => "public", :null => false
Trace.where(:public => false).update_all(:visibility => "private")
add_index :gpx_files, [:visible, :visibility], :name => "gpx_files_visible_visibility_idx"
end
def self.up
- create_enumeration :user_role_enum, %w[administrator moderator]
+ create_enum :user_role_enum, %w[administrator moderator]
create_table :user_roles do |t|
t.column :user_id, :bigint, :null => false
end
def self.up
- create_enumeration :user_status_enum, %w[pending active confirmed suspended deleted]
+ create_enum :user_status_enum, %w[pending active confirmed suspended deleted]
add_column :users, :status, :user_status_enum, :null => false, :default => "pending"
class AddMapBugTables < ActiveRecord::Migration[4.2]
def self.up
- create_enumeration :map_bug_status_enum, %w[open closed hidden]
+ create_enum :map_bug_status_enum, %w[open closed hidden]
create_table :map_bugs do |t|
t.integer :latitude, :null => false
class AddMapBugCommentEvent < ActiveRecord::Migration[4.2]
def self.up
- create_enumeration :map_bug_event_enum, %w[opened closed reopened commented hidden]
+ create_enum :map_bug_event_enum, %w[opened closed reopened commented hidden]
add_column :map_bug_comment, :event, :map_bug_event_enum
end
class RenameBugsToNotes < ActiveRecord::Migration[4.2]
def self.up
- rename_enumeration "map_bug_status_enum", "note_status_enum"
- rename_enumeration "map_bug_event_enum", "note_event_enum"
+ rename_enum "map_bug_status_enum", :to => "note_status_enum"
+ rename_enum "map_bug_event_enum", :to => "note_event_enum"
rename_table :map_bugs, :notes
rename_index :notes, "map_bugs_changed_idx", "notes_updated_at_idx"
rename_index :notes, "notes_updated_at_idx", "map_bugs_changed_idx"
rename_table :notes, :map_bugs
- rename_enumeration "note_event_enum", "map_bug_event_enum"
- rename_enumeration "note_status_enum", "map_bug_status_enum"
+ rename_enum "note_event_enum", :to => "map_bug_event_enum"
+ rename_enum "note_status_enum", :to => "map_bug_status_enum"
end
end
class AddTextFormat < ActiveRecord::Migration[4.2]
def up
- create_enumeration :format_enum, %w[html markdown text]
+ create_enum :format_enum, %w[html markdown text]
add_column :users, :description_format, :format_enum, :null => false, :default => "html"
add_column :user_blocks, :reason_format, :format_enum, :null => false, :default => "html"
add_column :diary_entries, :body_format, :format_enum, :null => false, :default => "html"
class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
def up
- create_enumeration :issue_status_enum, %w[open ignored resolved]
+ create_enum :issue_status_enum, %w[open ignored resolved]
create_table :issues do |t|
t.string :reportable_type, :null => false
class AddImporterRole < ActiveRecord::Migration[7.1]
- def up
- add_enumeration_value :user_role_enum, "importer"
- end
-
- def down
- raise ActiveRecord::IrreversibleMigration
+ def change
+ add_enum_value :user_role_enum, "importer"
end
end