aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/093_move_to_has_tag_string.rb23
-rw-r--r--db/migrate/094_remove_old_tags_foreign_key.rb17
-rw-r--r--db/schema.rb24
3 files changed, 53 insertions, 11 deletions
diff --git a/db/migrate/093_move_to_has_tag_string.rb b/db/migrate/093_move_to_has_tag_string.rb
new file mode 100644
index 000000000..58f36c224
--- /dev/null
+++ b/db/migrate/093_move_to_has_tag_string.rb
@@ -0,0 +1,23 @@
+class MoveToHasTagString < ActiveRecord::Migration
+ def self.up
+ rename_table :public_body_tags, :has_tag_string_tags
+
+ # we rename existing column:
+ rename_column :has_tag_string_tags, :public_body_id, :model_id
+ # if using has_tag_string afresh in another project, can use this:
+ # add_column :has_tag_string_tags, :model_id, :integer, :null => false
+
+ # the model needs a default value, so build in stages:
+ add_column :has_tag_string_tags, :model, :string
+ HasTagString::HasTagStringTag.update_all "model = 'PublicBody'"
+ change_column :has_tag_string_tags, :model, :string, :null => false
+ # just use this for a fresh project:
+ # add_column :has_tag_string_tags, :model, :string, :null => false
+
+ add_index :has_tag_string_tags, [:model, :model_id]
+ end
+
+ def self.down
+ raise "no reverse migration"
+ end
+end
diff --git a/db/migrate/094_remove_old_tags_foreign_key.rb b/db/migrate/094_remove_old_tags_foreign_key.rb
new file mode 100644
index 000000000..1a87b97c2
--- /dev/null
+++ b/db/migrate/094_remove_old_tags_foreign_key.rb
@@ -0,0 +1,17 @@
+class RemoveOldTagsForeignKey < ActiveRecord::Migration
+ def self.up
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ execute "ALTER TABLE has_tag_string_tags DROP CONSTRAINT fk_public_body_tags_public_body"
+ end
+
+ remove_index :public_body_tags, [:public_body_id, :name, :value]
+ remove_index :public_body_tags, :name
+
+ add_index :has_tag_string_tags, [:model, :model_id, :name, :value]
+ add_index :has_tag_string_tags, :name
+ end
+
+ def self.down
+ raise "no reverse migration"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 0c90be6b1..cf117c4e3 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 92) do
+ActiveRecord::Schema.define(:version => 94) do
create_table "acts_as_xapian_jobs", :force => true do |t|
t.string "model", :null => false
@@ -65,6 +65,18 @@ ActiveRecord::Schema.define(:version => 92) do
add_index "exim_logs", ["exim_log_done_id"], :name => "index_exim_logs_on_exim_log_done_id"
+ create_table "has_tag_string_tags", :force => true do |t|
+ t.integer "model_id", :null => false
+ t.text "name", :null => false
+ t.datetime "created_at", :null => false
+ t.text "value"
+ t.string "model", :null => false
+ end
+
+ add_index "has_tag_string_tags", ["model", "model_id", "name", "value"], :name => "index_has_tag_string_tags_on_model_and_model_id_and_name_and_va"
+ add_index "has_tag_string_tags", ["model", "model_id"], :name => "index_has_tag_string_tags_on_model_and_model_id"
+ add_index "has_tag_string_tags", ["name"], :name => "index_has_tag_string_tags_on_name"
+
create_table "holidays", :force => true do |t|
t.date "day"
t.text "description"
@@ -173,16 +185,6 @@ ActiveRecord::Schema.define(:version => 92) do
add_index "public_bodies", ["first_letter"], :name => "index_public_bodies_on_first_letter"
add_index "public_bodies", ["url_name"], :name => "index_public_bodies_on_url_name", :unique => true
- create_table "public_body_tags", :force => true do |t|
- t.integer "public_body_id", :null => false
- t.text "name", :null => false
- t.datetime "created_at", :null => false
- t.text "value"
- end
-
- add_index "public_body_tags", ["name", "public_body_id", "value"], :name => "index_public_body_tags_on_public_body_id_and_name_and_value", :unique => true
- add_index "public_body_tags", ["name"], :name => "index_public_body_tags_on_name"
-
create_table "public_body_versions", :force => true do |t|
t.integer "public_body_id"
t.integer "version"